Java Reference
In-Depth Information
logButton.addActionListener(this);
frame.add(controlPanel, BorderLayout.NORTH);
frame.add(logList, 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();
else if (ev.getSource() == logButton)
logList.add(generatedField.getText());
}
public void generateNewSentence() {
StringBuffer buf = new StringBuffer();
int baseChar = monkeyChoice.getSelectedItem().equals ("Dumbo")
? 'A' : 'a';
for (int i = 0; i < 60; i++) {
char c = (char) (baseChar + (random.nextInt() & 31));
if (Character.toUpperCase (c) > (baseChar+26)) c = ' ';
buf.append (c);
}
generatedField.setText (buf.toString());
}
public void pauseApp() {
}
public void destroyApp (boolean forced) {
}
}
When you're designing PDA applications, saving the limited screen space is especially important. For
cases in which the screen is too small to hold all the required information, the ScrollPane and
CardLayout classes are provided. The CardLayout class is a layout manager that allows
distribution of components over several cards. The cards are denoted by a String , and only one card
is shown at once. For example, using a Choice component, the user can be allowed to switch between
cards. The ScrollPane can contain an area that is larger than its space on the screen by using
scrollbars for navigation. Both classes are described in more detail in the section " Switching Layouts
Depending on the Screen Resolution Available . "
Dialogs and Menus
 
Search WWH ::




Custom Search