Introduction to Java :Components Part-2

Lists

You will recall that in the SELECT widget in HTML programming, you could select how many choices were visible at any one time using the SIZE attribute. Well, since the Choice widget does not have such an attribute, you need to use a different component if you want that functionality. In the JDK, the List component is used for such circumstances.

Menus and Menu Bars

Menus allow you to organize many related functions in your application in one centralized, easy-to-use interface object. Although Menus come in many forms, the most common menu types are “menu bars.”

Menu bars are particularly common and part of just about every application interface around today. Specifically, most applications will have a menu bar at the top of the screen that allows a user to choose among the major functions.

Scrollbars

Almost without doubt and before you know it, your users will be filling your application with more data than it can possibly display on one screen.

When this occurs, most programmers rely on some form of scrolling control to allow the user to manipulate the currently viewable portion of an interface object. Scrolling is handled in the JDK by the Scrollbar class. Scrollbars take a little more coding than is realistic for this tutorial. However, you can certainly consult the online documentation and any one of the 200 zillion books on Java for more info.

Buttons

Buttons are probably the most common interface control in modern user interfaces. They appear in toolbars, in menus, as the up and down arrows in scrollbars, and in all sorts of other places. In fact, it is hard to imagine any interface without a button somewhere.

The Button class defines a standard push button that uses 3D effects. When the user clicks on the button with the mouse, the button visually depresses and then pops back up when the mouse button is released.

We have already seen plenty of examples of Buttons and Button code so we won’t duplicate it here.

Canvases

Finally, the Canvas class prepares an area upon which you can draw. We will discuss drawing later. So for now, we will just mention this component.