Java Reference
In-Depth Information
Technically, a frame is also a component, but we will treat frames differently from
other components because frames form the physical windows that are seen onscreen.
Frames also have a large number of methods not found in other components.
Figure 14.1 illustrates some of Java's more commonly used graphical components,
listed by class name. A more complete pictorial reference of the available graphical
components can be found in Sun's Java Tutorial at http://java.sun.com/docs/books/
tutorial/uiswing/components/index.html.
Frames are represented by objects of the JFrame class. Any complex graphical
program must construct a JFrame object to represent its main graphical window.
Once you've constructed a JFrame object, you can display it on the screen by calling
its setVisible method and passing it the boolean value true . Here's a simple pro-
gram that constructs a frame and places it onscreen:
1 // Shows an empty window frame on the screen.
2
3 import javax.swing.*;
4
5 public class SimpleFrame {
6 public static void main(String[] args) {
7 JFrame frame = new JFrame();
8 frame.setVisible( true );
9 }
10 }
Figure 14.1
Some of Java's graphical components
 
Search WWH ::




Custom Search