Frames , Windows , and PanesIn Java, you must place components such as buttons and text fields in a container. Applications, including applets with a GUI, use at least one container. When a GUI application runs, it typically displays its interface inside a frame. The following list describes three top-level windows that are closely related :
The following hierarchy of the top-level windows shows the relationship between these components: java.lang.Object -java.awt.Component --java.awt.Container ---java.awt.Window ----javax.swing.JWindow ---java.awt.Window ----java.awt.Frame -----javax.swing.JFrame ---java.awt.Window ----java.awt.Dialog -----javax.swing.JDialog You can use these three containers to create your assignment's GUI. Keep in mind that a JWindow is a naked JFrame, and a JDialog is a single-purpose JWindow.
The following code snippet is an example of creating a frame: // Create frame JFrame myFrame = new JFrame("my frame"); // Create a button JComponent button = new JButton(); // Add button to frame's content pane; myFrame.getContentPane().add(button, BorderLayout.NORTH); myFrame.setVisible(true); Panes are related to frames in that they are windows, but they must be added to one of the top-level windows listed previously or to another pane. The following are the intermediate Swing containers:
|