System.exit(0);
}
});
// Display an image button to show the camo selection dialog.
camo = new ImageButton();
camo.setLabel("Choose...");
camo.setPreferredSize(84, 72);
camo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
dialog.setVisible(true);
}
});
camo.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent event) {
if (KeyEvent.VK_ENTER == event.getKeyCode()) {
dialog.setVisible(true);
}
}
});
frame.add(camo);
// Construct a dialog.
dialog = new Dialog(frame, "Choose a pattern", true);
dialog.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dialog.setVisible(false);
}
});
// Create a main panel for the dialog.
Panel main = new Panel();
main.setLayout(new BorderLayout());
dialog.add(main);
// Create a list as the center of the dialog.
list = new List(5);
list.add("data/images/camo/Wood1.jpg");
list.add("data/images/camo/Wood2.jpg");
list.add("data/images/camo/Urban.jpg");
list.add("data/images/camo/Winter.jpg");
list.select(0);
list.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent event) {
imgButton.setImage(Toolkit.getDefaultToolkit()
.getImage(
(String) event.getItemSelectable()
.getSelectedObjects()[0]));
}
});
list.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent event) {
if (KeyEvent.VK_ENTER == event.getKeyCode()
|| KeyEvent.VK_SPACE == event.getKeyCode()) {
Dimension size = imgButton.getPreferredSize();
camo.setBackground(imgButton.getBackground());
camo.setLabel(imgButton.getLabel());
camo.setImage(imgButton.getImage().getScaledInstance(
size.width, size.height, Image.SCALE_FAST));
dialog.setVisible(false);
}
}
});
main.add(list, BorderLayout.CENTER);
// Create a panel for the buttons.
Panel panel = new Panel();
panel.setLayout(new GridLayout(0, 1));
dialog.add(panel, BorderLayout.EAST);
// Create a "camo" button on the panel.
imgButton = new ImageButton();
imgButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
Dimension size = imgButton.getPreferredSize();
camo.setBackground(imgButton.getBackground());
camo.setLabel(imgButton.getLabel());