The javax.swing.JFrame class is used to create
a "window". This window has a few characteristics of its own (title bar, etc),
but most of the controls are placed in one of two subareas:
content pane or menu bar.
You can create a frame like this:
JFrame w = new JFrame("your title"); // OK, but it's better to use subclassing as below.
Subclass JFrame, build in constructor. Another better way is to define a class, eg MyWindow that extends JFrame, put the code which builds the GUI in the class's constructor, and create an instance of the window from the main program. See example below.
There are two common ways to use a JFrame's content pane. Both are commonly used. In both cases, the easiest style is to assign the working version of the content pane to
getContentPane() method returns a Container
object, which interestingly is actually a Jpanel. No problem with this
approach.
setContentPane(...).
JFrame w; // This is the natural Java "window". Container c; // This will typically be a JPanel (subclass of Container). WindowListener listen; // String title; boolean b; JMenuBar mBar;
| Using the content pane. See Content Panes | ||
c = | w.getContentPane(); |
Returns window's content pane. Use either get or set, but not both. |