Multiple ActionEvents
Introduction.
Our last programs had only a single component that could cause the program
to execute, even though they could then get values from other sources.
In this example we will have more than one command button to give the user
some options.
This applet will allow the user to change the color of a text field based on which command button they select. This program should be called MultipleChoice.java. |
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class MultipleChoice extends JApplet implements ActionListener {
} // end MultipleChoice class |
This program does the following
The following contains the MultipleChoice.html file. The size affects the appearance significantly. |
<html> <applet code="MultipleChoice.class" width=250 height=100> </applet> </html> |
When this applet is run and you press the button that says Red, you should see the following on your screen. |
You can keep clicking on buttons until you get tired of it. |