Java & J2EE Page 3 - Java's Basic User Interface Components |
We will start with the simplest of UI components: the button. Buttons are used to trigger events in a GUI environment (we have discussed Event Handling in detail in the previous tutorials). They are easy to manage and, most importantly, they are easy to use. The Button class is used to create buttons. When you add components to the container, you don’t specify a set of coordinates that indicates where the components are to be placed. The arrangement of components is handled by a layout manager in effect for the container. The default layout for a container is flow layout. Now let us write a simple code to test our button class. To create a button use, one of the following constructors:
Example 1 The following Java application illustrates addition of button controls to a panel. Example 2 Import java.awt.*;We can use the setLabel( ) method to change the label of the button and the getLabel( ) method to retrieve the caption.
blog comments powered by Disqus |