|
Version 7 of the Clay Shell program is like the sixth version except that the center Button object is replaced by a TextArea object.
|
java -jar ".../Clay7.jar" -w 400 -h 200


|
package clay7;
import java.awt.*;
import java.awt.event.*;
public class Main {
<<<Just like in the previous version!>>>
}
class ClayFrame extends Frame implements ActionListener {
public ClayFrame(String title, Color color, Dimension size) {
<<<Just like in the previous version!>>>
}
private Color backgroundColor;
private Color hilightColor;
private Color lolightColor;
private Button nb;
private Button sb;
private Button eb;
private Button wb;
private Button theButton; // selection
private TextArea ta;
private void establishColors() {
<<<Just like in the previous version!>>>
}
private void addComponents() {
// establish the layout manager
setLayout(new BorderLayout());
// create five buttons
nb = new Button("North");
sb = new Button("South");
eb = new Button("East");
wb = new Button("West");
// create a text area
ta = new TextArea();
// set backgrounds of buttons to white
nb.setBackground(lolightColor);
sb.setBackground(lolightColor);
eb.setBackground(lolightColor);
wb.setBackground(lolightColor);
ta.setBackground(Color.white);
// add action listeners
nb.addActionListener(this);
sb.addActionListener(this);
eb.addActionListener(this);
wb.addActionListener(this);
// add the buttons to the frame
add(nb,BorderLayout.NORTH);
add(sb,BorderLayout.SOUTH);
add(ta,BorderLayout.CENTER);
add(eb,BorderLayout.EAST);
add(wb,BorderLayout.WEST);
}
public void actionPerformed(ActionEvent event) {
Object source = event.getSource();
if ( source instanceof Button ) {
theButton = (Button)source;
String theLabel = theButton.getLabel();
ta.append(theLabel + "\n");
// color the buttons
nb.setBackground(lolightColor);
sb.setBackground(lolightColor);
wb.setBackground(lolightColor);
eb.setBackground(lolightColor);
theButton.setBackground(hilightColor);
}
}
class CloseWindow extends WindowAdapter {
<<<Just like in the previous version!>>>
}
}
|