Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

12. Getting GUI: A Very Graphic Story > It all starts with a window

It all starts with a window

A JFrame is the object that represents a window on the screen. It’s where you put all the interface things like buttons, checkboxes, text fields, and so on. It can have an honest-to-goodness menu bar with menu items. And it has all the little windowing icons for whatever platform you’re on, for minimizing, maximizing, and closing the window.

“If I see one more command-line app, you’re fired.”

image with no caption

The JFrame looks different depending on the platform you’re on. This is a JFrame on Mac OS X:

image with no caption

a JFrame with a menu bar and two ‘widgets’ (a button and a radio button)

Put widgets in the window

Once you have a JFrame, you can put things (‘widgets’) in it by adding them to the JFrame. There are a ton of Swing components you can add; look for them in the javax.swing package. The most common include JButton, JRadioButton, JCheckBox, JLabel, JList, JScrollPane, JSlider, JTextArea, JTextField, and JTable. Most are really simple to use, but some (like JTable) can be a bit more complicated.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial