Unformatted text preview:

Chapter 14 GUI Components: Part 1PowerPoint PresentationSlide 3Slide 414.1 IntroductionSlide 614.1 Introduction (cont.)Slide 8Slide 914.2 Java’s Nimbus Look-and-Feel14.2 Java’s Nimbus Look-and-Feel (cont.)Slide 12Slide 1314.3 Simple GUI-Based Input/Output with JOptionPaneSlide 15Slide 1614.3 Simple GUI-Based Input/Output with JOptionPane (cont.)Slide 18Slide 19Slide 20Slide 21Slide 22Slide 2314.4 Overview of Swing ComponentsSlide 2514.4 Overview of Swing Components (cont.)Slide 27Slide 28Slide 29Slide 30Slide 31Slide 3214.5 Displaying Text and Images in a WindowSlide 34Slide 35Slide 36Slide 37Slide 3814.5 Displaying Text and Images in a Window (cont.)Slide 40Slide 41Slide 42Slide 43Slide 44Slide 45Slide 46Slide 47Slide 48Slide 49Slide 50Slide 5114.6 Text Fields and an Introduction to Event Handling with Nested Classes14.6 Text Fields and an Introduction to Event Handling with Nested Classes (cont.)Slide 54Slide 55Slide 56Slide 57Slide 58Slide 59Slide 60Slide 61Slide 62Slide 63Slide 64Slide 65Slide 66Slide 67Slide 68Slide 69Slide 70Slide 71Java How to Program, 9/e© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.A graphical user interface (GUI) presents a user-friendly mechanism for interacting with an application. ◦Pronounced “GOO-ee”◦Gives an application a distinctive “look” and “feel.” ◦Consistent, intuitive user-interface components give users a sense of familiarity ◦Learn new applications more quickly and use them more productively. © Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.Built from GUI components. ◦Sometimes called controls or widgets—short for window gadgets. User interacts via the mouse, the keyboard or another form of input, such as voice recognition. IDEs ◦Provide GUI design tools to specify a component’s exact size and location in a visual manner by using the mouse. ◦Generates the GUI code for you. ◦Greatly simplifies creating GUIs, but each IDE has different capabilities and generates different code. © Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.Example of a GUI: SwingSet3 application (Fig. 14.1)http://download.java.net/javadesktop/swingset3/SwingSet3.jnlptitle bar at top contains the window’s title. menu bar contains menus (File and View). In the top-right region of the window is a set of buttons◦Typically, users press buttons to perform tasks. In the GUI Components area of the window is a combo box; ◦User can click the down arrow at the right side of the box to select from a list of items. © Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.Java SE 6 update 10 New, elegant, cross-platform look-and-feel known as Nimbus. We’ve configured our systems to use Nimbus as the default look-and-feel. © Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.Three ways to use Nimbus: Set it as the default for all Java applications that run on your computer.Set it as the look-and-feel when you launch an application by passing a command-line argument to the java command.Set it as the look-and-feel programatically in your application (Section/25.6).© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.To set Nimbus as the default for all Java applications: ◦Create a text file named swing.properties in the lib folder of both your JDK installation folder and your JRE installation folder. ◦Place the following line of code in the file:swing.defaultlaf=com.sun.java.swing.plaf.nimbus.NimbusLookAndFeelFor more information on locating these installation folders visit◦http://bit.ly/JavaInstallationInstructionsIn addition to the standalone JRE, there is a JRE nested in your JDK’s installation folder. If you are using an IDE that depends on the JDK (e.g., NetBeans), you may also need to place the swing.properties file in the nested jre folder’s lib folder.© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.To select Nimbus on an application-by-application basis:◦Place the following command-line argument after the java command and before the application’s name when you run the application:-Dswing.defaultlaf=com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.Most applications use windows or dialog boxes (also called dialogs) to interact with the user. JOptionPane (package javax.swing) provides prebuilt dialog boxes for input and output◦Displayed via static JOptionPane methods. Figure 14.2 uses two input dialogs to obtain integers from the user and a message dialog to display the sum of the integers the user enters. © Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.JOptionPane static method showInputDialog displays an input dialog, using the method’s String argument as a prompt.◦The user types characters in the text field, then clicks OK or presses the Enter key to submit the String to the program. ◦Clicking OK dismisses (hides) the dialog. ◦Can input only Strings. Typical of most GUI components. ◦If the user clicks Cancel, returns null. ◦JOptionPane dialog are dialog—the user cannot interact with the rest of the application while dialog is displayed.© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.Converting Strings to int Values◦ Integer class’s static method parseInt converts its String argument to an int value.Message Dialogs◦JOptionPane static method showMessageDialog displays a message dialog. ◦The first argument helps determine where to position the dialog. If null, the dialog box is displayed at the center of your screen. ◦The second argument is the message to display.◦The third argument is the String that should appear in the title bar at the top of the dialog. ◦The fourth argument is the type of message dialog to display. © Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.Message Dialogs◦A JOption-Pane.PLAIN_MESSAGE dialog does not display an icon to the left of the message. JOptionPane online documentation: ◦http://download.oracle.com/javase/6/docs/api/javax/swing/JOptionPane.html© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.Swing GUI components located in package javax.swing. Abstract Window Toolkit (AWT) in package java.awt is another set of GUI components in Java.◦When a Java


View Full Document

DREXEL SE 102 - GUI Components

Documents in this Course
Load more
Download GUI Components
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view GUI Components and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view GUI Components 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?