1 / 14

Graphical User Interface (pronounced "gooey")

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. Creating a GUI. A GUI must begin with a top-level container, such as a frame, for holding a content frame

corina
Download Presentation

Graphical User Interface (pronounced "gooey")

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. Creating a 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

  3. frame panel label A Swing GUI

  4. JFrame • 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()

  5. JPanel • Part of the java.swing package • The JPanel class is used to create a content frame for a GUI • JPanel methods include:add() remove()

  6. JLabel • 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()

  7. JButton • 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()

  8. 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

  9. Layouts • 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

  10. JTextField • 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()

  11. 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()

  12. JComboBox • 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()

  13. Colors • 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

  14. Images • 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

More Related