February 2000
Intermediate to advanced
352 pages
6h 31m
English
Getting started using the Swing classes is pretty simple. Application windows inherit from JFrame, and applets inherit from JApplet. The only difference between Frame and JFrame is that you cannot add components or set the layout directly for JFrame. Instead, you must use the getContentPane method to obtain the container in which you can add components and vary the layout.
getContentPane().setLayout(new BorderLayout());
JButton b = new JButton ("Hi");
getContentPane().add(b); //add a button to the layout
This is sometimes a bit tedious to type each time, so we recommend retrieving the JPanel from the content pane and then adding all the components to that panel.
JPanel jp = getContentPane() //get the ...
Read now
Unlock full access