Presentation is loading. Please wait.

Presentation is loading. Please wait.

Graphical User Interface (pronounced "gooey")

Similar presentations


Presentation on theme: "Graphical User Interface (pronounced "gooey")"— Presentation transcript:

1 Graphical User Interface (pronounced "gooey")
7/19/2018 7:40 PM Chapter 11 GUI Graphical User Interface (pronounced "gooey") Typically used with applications written for Windows or OSX Event-driven, responding to events such as a mouse click Refer to page 275 in the text. © 2007 Lawrenceville Press

2 Chapter 11 Creating a Swing GUI
7/19/2018 7:40 PM Chapter 11 Creating a Swing GUI A GUI must begin with a top-level container, such as a frame, for holding a content frame A content frame, such as a panel, holds and displays components and gets added to a container Components include labels Refer to page 275 in the text. © 2007 Lawrenceville Press

3 frame panel label Chapter 11 A Swing GUI
7/19/2018 7:40 PM Chapter 11 A Swing GUI frame panel label Note: This slide contains animations. Press the space bar or click the mouse button to display each animation. This slide contains four (4) animations. Refer to pages 275 through 277 in the text. A frame is a container, which is a window with a border, title, and buttons for minimizing, maximizing, and closing the frame. <press space bar> A panel is a content frame, which can hold and display components. <press space bar> A label is a component that displays text. Components must be placed in a content frame to be displayed in a container. <press space bar> © 2007 Lawrenceville Press

4 Chapter 11 The JFrame Class
7/19/2018 7:40 PM Chapter 11 The JFrame Class Part of the java.swing package The JFrame class is used to create a frame for a GUI JFrame methods include: setDefaultLookAndFeelDecorated() setDefaultCloseOperation() getContentPane() setContentPane() pack() setVisible() Refer to page 276 in the text. © 2007 Lawrenceville Press

5 Chapter 11 The JPanel Class
7/19/2018 7:40 PM Chapter 11 The JPanel Class Part of the java.swing package The JPanel class is used to create a content frame for a GUI JPanel methods include: add() remove() Refer to page 276 in the text. © 2007 Lawrenceville Press

6 Chapter 11 The JLabel Class
7/19/2018 7:40 PM Chapter 11 The JLabel Class Part of the java.swing package The JLabel class is used to create an object for displaying text JLabel constructors and methods include: JLabel() setText() Refer to page 277 in the text. © 2007 Lawrenceville Press

7 Chapter 11 The JButton Class
7/19/2018 7:40 PM Chapter 11 The JButton Class Part of the java.swing package The JButton class is used to create an object that can be clicked by the user. Provides a means of communication between the user and the interface. Requires a listener object to determine when the user has clicked the button JButton constructors and methods include: JLabel() setActionCommand() getActionCommand() addActionListener() Refer to page 278 in the text. © 2007 Lawrenceville Press

8 Chapter 11 Handling Events
7/19/2018 7:40 PM Chapter 11 Handling Events A listener object responds to an event by executing an event handler named actionPerformed() The actionPerformed() method has a parameter for the action command string, which is passed by the event The component requiring a listener must set the action command and add an action listener The class containing a listener must implement the ActionListener interface Refer to pages 279 and 280 in the text. © 2007 Lawrenceville Press

9 Chapter 11 Component Layout
7/19/2018 7:40 PM Chapter 11 Component Layout FlowLayout manager places components one next to the other in a row BoxLayout manager places components one after the other in a column GridLayout manager places components into a grid of rows and columns Borders and alignment can be changed to control layout within a layout manager Refer to pages 281 and 284 in the text. © 2007 Lawrenceville Press

10 Chapter 11 The JTextField Class
7/19/2018 7:40 PM Chapter 11 The JTextField Class Part of the java.swing package The JTextField class is used to create an object where users can enter data JTextField constructors and methods include: JTextField() getText() addActionListener() Refer to page 285 in the text. © 2007 Lawrenceville Press

11 Chapter 11 Processing Numeric Data
7/19/2018 7:40 PM Chapter 11 Processing Numeric Data Data typed into a text field is a string Class methods in the Double and Integer classes can be used to convert string data to numeric data and the reverse Double class methods include: parseDouble() toString() Integer class methods include: parseInteger() toString() Refer to pages 285 and 286 in the text. © 2007 Lawrenceville Press

12 Chapter 11 The JComboBox Class
7/19/2018 7:40 PM Chapter 11 The JComboBox Class Part of the java.swing package The JComboBox class is used to create an object where users select a choice from a list of choices JComboBox constructors and methods include: JComboBox() setSelectedIndex() getSelectedItem() setEditable() addActionListener() Refer to page 288 in the text. © 2007 Lawrenceville Press

13 7/19/2018 7:40 PM Chapter 11 Adding Color Swing Components have methods for changing their colors: setBackground() setForeground() The methods for changing color require a parameter from the Color class How the color changes varies between components Refer to page 291 in the text. © 2007 Lawrenceville Press

14 Chapter 11 Adding Images to Applications
7/19/2018 7:40 PM Chapter 11 Adding Images to Applications Many Swing components support images GIF and JPG image formats work best The JLabel and JButton classes include the setIcon() method for adding an image to a component The JLabel and JButton constructors may also specify an image Refer to pages 292 and 293 in the text. © 2007 Lawrenceville Press

15 Chapter 11 Nested Classes
7/19/2018 7:40 PM Chapter 11 Nested Classes A class within a class is called a nested class Nested classes are members of the class they are within The class containing the nested class is called the outer class Refer to page 295 in the text. © 2007 Lawrenceville Press

16 outer class nested class Chapter 11 A Nested Class
7/19/2018 7:40 PM Chapter 11 A Nested Class outer class public class MyApp { outer class data members outer class constructors and methods class MyListener implements ActionListener { public void actionPerformed(ActionEvent event) { } } } nested class Note: This slide contains animations. Press the space bar or click the mouse button to display each animation. This slide contains two (2) animations. Refer to page 295 in the text. A class that contains a class member is called an outer class. <press space bar> A class member within a class is called the nested class. <press space bar> © 2007 Lawrenceville Press


Download ppt "Graphical User Interface (pronounced "gooey")"

Similar presentations


Ads by Google