A component is an object with a graphical representation that can be displayed on the screen and that can interact with the user. The
To create a
Button() // Constructs a Button with no label. Button(String label) // Constructs a Button with the specified label.
When a user presses on a
Checkboxes ave two states, on and off. The state of the button is returned as the Object argument, when a
Is a group of checkboxes, where only one of the items in the group can be selected at any one time.
Like a radio button, where we make a selection, however it requires less space and allows us to add items to the menu dynamically using the
Allow us to add a text description to a point on the applet or application.
Are areas where the user can enter text. They are useful for displaying and receiving text messages. We can make this textfield read-only or editable. We can use the
TextField text1 = new TextField(); // no properties TextField text2 = new TextField("Some text"); // a textfield with a // predefined String TextField text3 = new TextField(40); // a textfield with a // predefined size TextField text4 = new TextField("Some text", 50); // combination of the two
To show these components in action we can write a short piece of code that displays these components, but they do not have any events behind them - they work visually but do not have any true program function. Figure 6.8, “A Component Application” shows an example application that details all the previous components.
You can see this application running in Figure 6.9.