Java Reference
In-Depth Information
Button exitButton = new Button ("exit");
Button generateButton = new Button ("generate");
Random random = new Random();
public GhostWriter() {
Panel buttonPanel = new Panel();
buttonPanel.add(exitButton);
buttonPanel.add(generateButton);
exitButton.addActionListener(this);
generateButton.addActionListener(this);
frame.add(list, BorderLayout.CENTER);
frame.add(buttonPanel, BorderLayout.SOUTH);
frame.pack();
frame.addWindowListener(new WindowAdapter() {
public void windowClosing (WindowEvent ev) {
notifyDestroyed();
}
} );
}
public void startApp() {
frame.show();
}
public void actionPerformed (ActionEvent ev) {
if (ev.getSource() == exitButton)
notifyDestroyed();
else if (ev.getSource() == generateButton)
generateNewSentence();
}
public void generateNewSentence() {
StringBuffer buf = new StringBuffer();
for (int i = 0; i < 60; i++) {
char c = (char) (((int) 'a') + (random.nextInt() & 31));
if (c > 'z') c = ' ';
buf.append (c);
}
list.add(buf.toString());
}
public void pauseApp() {
}
public void destroyApp (boolean forced) {
}
}
Another common layout is, as we mentioned earlier, a list of labels and corresponding fields, such as
the input mask of an address book. Suppose that we want to log only the good sentences typed by the
simulated monkeys because of the limited memory of a PDA. Additionally, we have two monkeys to
choose from. In order to display these options, we would like to show a label "generated," a
Search WWH ::




Custom Search