MidtermModule.Week1&2 Introduction to Graphical User Interface
Graphical user interface or GUI in Java is essential to develop attractive, informative and useful programs or applications to be utilized by the companies, institutions, establishments and industries to make their transactions faster and convenient. In this lesson, you will be guided, taught and introduced the concept of object oriented programming language or graphical user interface concepts to increase your knowledge so that you will be starting to love Java programming.
At the end of this lesson, the student should be able to: Understand the concepts of Graphical User Interface of Java Programming Differentiate message box into input box. Learn the different components of Graphical User Interface Apply the syntax of frames and functions of Graphical User Interface Design a program using the concept of Graphical User Interface.
It is pronounced as “ gooey ”. It is called graphical because it uses graphical elements such as windows, buttons, and menus. It is called User Interface because it is the part of a program that interfaces with the user. GUI obtains information from the user and gives it to the program for processing. Window is a portion of the user’s screen that serves as a smaller screen within the screen. Event is an object that represents some action such clicking a mouse button, dragging the mouse, pressing a key on the keyboard, clicking the close window button on a window, or any other action that is expected to elicit a response. There are current three sets of Java APIs for graphics programming: AWT ( A bstract W indowing T oolkit), Swing and JavaFX . AWT API was introduced in JDK 1.0. Most of the AWT components have become obsolete and should be replaced by newer Swing components. Swing API, a much more comprehensive set of graphics libraries that enhances the AWT, was introduced as part of Java Foundation Classes (JFC) after the release of JDK 1.1. JFC consists of Swing, Java2D, Accessibility, Internationalization, and Pluggable Look-and-Feel Support APIs. JFC has been integrated into core Java since JDK 1.2. The latest JavaFX , which was integrated into JDK 8, is meant to replace Swing
A Simple GUI The easiest way to create GUI for your program is to use a message dialog box and an input dialog box. A message dialog box is used to display a message on the screen, and an input dialog box prompts the user to enter information that is returned to you program for processing. A dialog window is an independent subwindow meant to carry temporary notice apart from the main Swing Application Window. Most Dialogs present an error message or warning to a user, but dialogs can present images, directory trees or about anything compatible with the main Swing Application that managed them. For convenience, several Swing component classes can directly instantiate and display dialogs . To create simple, standard dialogs, you use the JOptionPane class.
Dialog Boxes JOptionPane.showMessageDialog allows us to display simple dialog boxes. The first parameter “ null ” displays the dialog box in the middle of the screen, the second parameter defines the text that we want to be displayed inside the box, the third parameter defines the text that we want to be displayed as header, and the fourth parameter allows us to choose a particular icon. JOptionPane’s icon support lets you easily specify which icon the dialog displays. You can use a custom icon, no icon at all, or any one of four standard JOptionPane icons (question, information, warning, and error).
CONSTANTS DESCRIPTION JOption.Pane.PLAIN MESSAGE Used to display a general-purpose message JOption.Pane.ERROR _ MESSAGE Used to display an error message JOption.Pane.INFORMATION_ MESSAGE Used to display a information message JOption.Pane.WARNING _ MESSAGE Used to display a warning message JOption.Pane.QUESTION_ MESSAGE Used to question the user regarding a user response to your program