// CS7 - // This version of OnOff lets the user pick a phrase from a combo // box and then display it in JLabel. import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class OnOffDeluxe extends JApplet { public void init() { // available messages String [] items = { "Applause", "Laughter", "Awwwww", "Show over" }; // get access to the applet's top-level container Container pane = getContentPane(); // create components final JLabel message = new JLabel(""); final JComboBox choices = new JComboBox(items); final JButton flipButton = new JButton("Change Message"); // use a two row layout pane.setLayout(new GridLayout(3,1)); // 3 rows, 1 column pane.add(message); pane.add(flipButton); pane.add(choices); // add the listener flipButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { message.setText((String)choices.getSelectedItem()); } }); } // end init() } // end of class