You are here

Graphical User Interfaces in Java

15 January, 2016 - 09:02
Available under Creative Commons-ShareAlike 4.0 International License. Download for free at http://cnx.org/contents/402b20ad-c01f-45f1-9743-05eadb1f710e@37.6

In Java Graphical User Interface (GUI) programming, we do not build GUI components from scratch. Instead we use GUI components provided to us by the JDK. Java has two types of GUI applications: stand alone GUI applications and applets. We first study how to build stand-alone GUI applications (GUI app for short).

Every GUI app uses what is called a JFrame that comes with the JDK. A JFrame is a window with borders, a title bar, and buttons for closing and maximizing or minimizing itself. It also knows how to resize itself. Every GUI app subclasses JFrame in some way to add more functionality to the window frame. One common task is to tell the system to terminate all "threads" of the GUI app when the user clicks on the exit (close) button of the main GUI window. We encapsulate this task in an abstract frame class called AFrame described below.