// CS7 - // This is a simple applet that changes its button text. // The user can enter the new button text in a text field. import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class OnOff2 extends JApplet { public void init() { // get access to the applet's top-level container Container pane = getContentPane(); // create components final JButton flipButton = new JButton("Enter whatever you want."); final JTextField newTextField = new JTextField(); // use a two row layout pane.setLayout(new GridLayout(2,1)); // 2 rows, 1 column pane.add(newTextField); pane.add(flipButton); // add the listener flipButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { flipButton.setText(newTextField.getText()); } }); } // end init() } // end of class