Chapter 14. A Very Graphic Story: Getting Gui

image

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 and lambdas. 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 (crude) animation.

It all starts with a window

image

She’s asked a couple of really good questions. In a few pages we’ll address these questions with an extra-special “No Dumb Questions.”

A JFrame is the object that represents a window on the screen. It’s where you put all the interface things like buttons, check boxes, text fields, and so on. It can have an honest-to-goodness ...

Get Head First Java, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.