Chapter 14. A Very Graphic Story: Getting Gui
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
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 menu bar with menu items. ...
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.
Read now
Unlock full access