Skip to Content
Head First Java, 2nd Edition
book

Head First Java, 2nd Edition

by Kathy Sierra, Bert Bates
February 2005
Beginner
720 pages
19h 12m
English
O'Reilly Media, Inc.
Content preview from Head First Java, 2nd Edition

Chapter 12. Getting GUI: A Very Graphic Story

image with no caption

Face it, you need to make GUIs. If you’re building applications that other people are going to use, you need a graphical interface. If you’re building programs for yourself, you want a graphical interface. Even if you believe that the rest of your natural life will be spent writing server-side code, where the client user interface is a web page, sooner or later you’ll need to write tools, and you’ll want a graphical interface. Sure, command-line apps are retro, but not in a good way. They’re weak, inflexible, and unfriendly. We’ll spend two chapters working on GUIs, and learn key Java language features along the way including Event Handling and Inner Classes. In this chapter, we’ll put a button on the screen, and make it do something when you click it. We’ll paint on the screen, we’ll display a jpeg image, and we’ll even do some animation.

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.”

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

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Head First Java, 3rd Edition

Head First Java, 3rd Edition

Kathy Sierra, Bert Bates, Trisha Gee
Learning Java, 6th Edition

Learning Java, 6th Edition

Marc Loy, Patrick Niemeyer, Daniel Leuck
Java in a Nutshell, 7th Edition

Java in a Nutshell, 7th Edition

Benjamin J. Evans, David Flanagan
Learning Java, 4th Edition

Learning Java, 4th Edition

Patrick Niemeyer, Daniel Leuck

Publisher Resources

ISBN: 0596009208Supplemental ContentErrata Page