Making a button is simple: just call the button builder and specify the label you want to appear on the button (if you don't want the tag, you can use the default builder, but that rarely happens). You can refer to a later program to create a handle to the button so that you can reference it later.
A button is a component that, like its own small window, is redrawn when it is updated. This means that we do not have to explicitly depict a button or any other kind of control; just incorporate them into the form, and later work on them will be the responsibility of their own. So in order to place a button into a form, you need to overload the Init () method instead of overloading paint ():
: Button1.java
//putting buttons on a applet
import java.awt.*;
Import java.applet.*;
public class Button1 extends Applet {
button
B1 = New button ("button 1"),
b2 = New button ("button 2");
public void init () {
Add (B1);
Add (b2);
}
///:~
However, this is not enough to create a button (or any other control). You must also call the Applet Add () method to place the button in the form of the program slice. This may seem a lot simpler than it really is, because calls to add () actually decide where to place the control on the form. The controls on the layout of the form are immediately mentioned.