In a single statement, declare and initialize an array that contains the followi
ID: 3831154 • Letter: I
Question
In a single statement, declare and initialize an array that contains the following strings: "midnight blue". "brick red", "burnt sienna", "periwinkle", "forest green". g. The Fear This game's ZombieInvasion interface is defined as follows: Public interface ZombieInvasion {public void zombieAleart (Change Event e);} Write a skeleton definition for a class MyListener containing the minimum code necessary to implement the ZombieInvasion interface. You may omit the import statements. h. What combination of Containers and Layout Managers would you use to create a GUI as shown below?Explanation / Answer
1)
package arrayexample;
class ArrayExample{
public static void main(String args[]){
String a[]={"mid night blue","brick red","burnt sienna","perwinkle","forest green"};//declaration, instantiation and initialization
//printing array
for(int i=0;i<a.length;i++)//length is the property of array
System.out.println(a[i]);
}}
2)
package zombieinvasionexample;
import javax.swing.event.ChangeEvent;
interface ZombieInvasion{
public void zombieAlert(ChangeEvent e);
}
public class MyListerner implements ZombieInvasion{
private static ChangeEvent ChangeEvent;
public void zombieAlert(ChangeEvent ce){
System.out.println("change event");
}
public static void main(String[] args) {
ZombieInvasion obj = new MyListerner();
obj.zombieAlert(ChangeEvent);
}
}
3)
Using GridLayout and Border Layout managers we can get the GUI like this.
Here I am just giving the idea on how to create them.
import java.awt.*;
import java.applet.*;
import java.util.*;
/*
<applet code="BorderLayoutDemo" width=400 height=200>
</applet>
*/
public class BorderLayoutDemo extends Applet {
public void init() {
setLayout(new BorderLayout());
add(new Button("This is across the top."),
BorderLayout.NORTH);
add(new Label("The footer message might go here."),
BorderLayout.SOUTH);
add(new Button("Right"), BorderLayout.EAST);
add(new Button("Left"), BorderLayout.WEST);
String msg = "The reasonable man adapts " +
"himself to the world; " +
"the unreasonable one persists in " +
"trying to adapt the world to himself. " +
"Therefore all progress depends " +
"on the unreasonable man. " +
" - George Bernard Shaw ";
add(new TextArea(msg), BorderLayout.CENTER);
}
}