In this example, we'll define and instantiate a button object, and then we'll use the action event handler (this is an inherited method from Applet, so we merely have to overload it) | |
Note, if you try this applet out, remember to
change the applet name to "AppletWithButton.class" in the .htm file with the code
parameter - |
import java.applet.*;
import java.awt.*;
public class AppletWithButton extends Applet
{
private Button button1 = new Button("Click Here!");
// helper contains the text on button1 -
// in this case, the String "Click Here"
public boolean action(Event e, Object helper)
{
// TODO: Add your own implementation.
// GENERATED BY J++: return super.action(e, helper);
Test to see if the event that occurred
corresponds to button1 | |
Add the button1 object to the display when the
applet is initialized using the init method. Note, when no layout manager
is specified, the default Flow layout manager is used ... it places
controls on the display one after another going right, then down when necessary. | |
We overload the keyDown event - we'll
test what key was pressed, and change the background of the applet's display accordingly |

![]()
Created &
Maintained by DrB - Comments welcome.
Last edited on Friday, July 30, 2004