Graphical User Interfaces (GUIs) GUI: An application that uses graphical objects to interact with users GUI applications consist of: –Events: A user or.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

Java Software Development Paradigm Lecture # 12. Basics of GUI.
CS18000: Problem Solving and Object-Oriented Programming.
Unit 3 Graphical User Interface (GUI) Dr. Magdi AMER.
Graphic User Interfaces Layout Managers Event Handling.
CMSC 341 Building Java GUIs. 09/26/2007 CMSC 341 GUI 2 Why Java GUI Development? Course is about Data Structures, not GUIs. We are giving you the opportunity.
Graphical User Interfaces CS 2110 Spring Ivan Sutherland: “Sketchpad”,
Corresponds with Chapter 12
Fall 2007CS 225 Graphical User Interfaces Event Handling Appendix C.
Unit 091 Introduction to GUI Programming Introduction to User Interfaces Introduction to GUI Programming GUI Design Issues GUI Programming Issues Java.
Understanding SWING Architecture CS 4170 UI Design Hrvoje Benko Oct. 9, 2001.
Lecture 15 Graphical User Interfaces (GUI’s). Objectives Provide a general set of concepts for GUI’s Layout manager GUI components GUI Design Guidelines.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 14 GUI and Event-Driven Programming.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 14 GUI and Event-Driven Programming.
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Scott Grissom, copyright 2006Ch 11: GUI Slide 1 Graphical User Interfaces (Ch 11) Careful design of a graphical user interface is key to a viable software.
GUI Programming in Java Tim McKenna GUI Programming Concepts l conventional programming: sequence of operations is determined by the program.
PROGRAMMING REVIEW Lab 2 EECS 448 Dr Fengjun Li and Meenakshi Mishra.
GUI Programming in Java
Java Programming Chapter 10 Graphical User Interfaces.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Graphical User Interfaces (GUIs) GUI: An application that uses graphical objects to interact with users GUI applications consist of: –Events: A user or.
Object Oriented Programming Ders 11: Interfaces Mustafa Emre İlal
Introduction to Swing Components Chapter 14.  Part of the Java Foundation Classes (JFC)  Provides a rich set of GUI components  Used to create a Java.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
– Advanced Programming P ROGRAMMING IN Lecture 21 Introduction to Swing.
1 Outline 1 Introduction 2 Overview of Swing Components 3 JLabel 4 Event Handling 5 TextFields 6 How Event Handling Works 7 JButton 8 JCheckBox and JRadioButton.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
MSc Workshop - © S. Kamin, U. ReddyLect 3 - GUI -1 Lecture 3 - Graphical User Interfaces r GUI toolkits in Java API r JFrame r GUI components.
Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary Litvin, and Skylight.
Swing Differences between Swing and AWT Naming Conventions All Swing components begin with a capital J -- JPanel, JButton, JScrollBar, JApplet, etc..
Layout Managers Arranges and lays out the GUI components on a container.
CSCI Swing1 The Abstract Windowing Toolkit Since Java was first released, its user interface facilities have been a significant weakness –The Abstract.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
GUI Basics. What is GUI? A graphical user interface (GUI) is a type of user interface item that allows people to interact with programs in more ways than.
Creating Windows. How can we use Java to create programs that use windows (GUI applications)? How can we use Java to create programs that use windows.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
Lec.10 (Chapter 8 & 9) GUI Jiang (Jen) ZHENG June 27 th, 2005.
Introduction to Java Chapter 9 - Graphical User Interfaces and Applets1 Chapter 9 Graphical User Interfaces and Applets.
Swing. Introduction to Swing What is Swing? “ Swing is a diverse collection of lightweight components that can be used to build sophisticated user interfaces.”
5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise.
Basics of GUI Programming Chapter 11 and Chapter 22.
Ajmer Singh PGT(IP) JAVA IDE Programming - I. Ajmer Singh PGT(IP) GUI (Graphical User Interface) It is an interface that uses a graphic entities along.
Java Programming, Second Edition Chapter Thirteen Understanding Swing Components.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Graphical User Interface (GUI)
Applets. 9/04/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L12: Applets Slide 2 Applets Usually.
Advanced Topics on Graphical User Interfaces CardLayout JTabbedPane JFrame.
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
Java Swing. Graphical User Interfaces (GUIs) GUI: An application that uses graphical objects to interact with users GUI applications consist of: – Events:
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
Introduction to Swing Mr. Crone. What is Swing? a collection of pre-made Java classes used to create a modern graphical user interface.
Introduction to Swing Mr. Crone. What is Swing? a collection of pre-made Java classes used to create a modern graphical user interface.
Chapter 6 Building Java GUIs. MVC Model View Controller The model passes its data to the view for rendering The view determines which events are passed.
Chapter 9: Graphical User Interfaces
Java GUI.
Graphical User Interfaces (GUIs)
Ellen Walker Hiram College
Chap 7. Building Java Graphical User Interfaces
Chapter 13: Advanced GUIs and Graphics
Graphical User Interfaces -- Introduction
Advanced GUIs and Graphics
Graphical User Interface
Presentation transcript:

Graphical User Interfaces (GUIs) GUI: An application that uses graphical objects to interact with users GUI applications consist of: –Events: A user or programmatic action –Listeners: A method that responds to an event –Components: A GUI object –Containers: A collection of components –listener interface: An interface that contains listeners –Adapter class: A class that implements a listener interface with default methods –layout managers: An object that defines how components in a container present to the user –special features: Methods that customize a GUI's look and feel

Java GUI Facilities AWT (Abstract windowing toolkit) –Designed for creating applets –Not powerful enough for application programs –Simple and easy to use, and supported by almost all browsers –Peer model relies on platform-dependent native code (heavyweight) Swing (The creator was a "swing" dancer) –Newer and more sophisticated GUI facility –Swing class names start with the letter 'J'. –Consistent look and feel across operating systems –Does not depend on operating system facilities (lightweight) –Many swing classes extend their AWT counterparts –Most application developers now use Swing, not AWT –Supports a pluggable look and feel (UIManager.setLookAndFeel("javax.swing.plaf.windowsLookAndFeel"); AWT and Swing are each a collection of Java classes for GUI development Java GUI facilities are large and complex. We focus only on a small subset

AWT vs. Swing AWT advantages over Swing 1.Simpler to learn and use 2.Older browsers might not support Swing Swing advantages over AWT 1.Much greater functionality 2.Portability. Consistent look and feel across platforms 3.Vendor support. AWT functionality is frozen 4.Built-in double buffering overlaps processing with I/O

Containers and Components Container –A Java class instantiated to hold groups of components –Examples: JApplet, JFrame, JPanel, JTabbedPanel, JScrollPane Component –A Java class instantiated to create a type of GUI object –Examples: JButton, JCheckBox, JComboBox, JColorChooser, JFileChooser, JLabel, JList, JMenu, JOptionPane, JPasswordField, JRadioButton, JSlider, JTextArea, JTextField, JToggleButton, JTree Java GUI applications principally consist of containers and components

Layout Managers Java Layout Managers –AWT: Flow, Border, Card, Grid, GridBag –Swing: Flow, Border, Card, Grid, GridBag, Box, Overlay Comments –If a GUI doesn't choose a layout, Java uses FlowLayout –Each layout manager has its own idiosyncrasies responds to window resizing differently May or may not respond to a component's preferred size or alignment preferences Objects that controls how a container's components display

Layout Manager Summary AWT managers –Flow: left-to-right, top-to-bottom in order (The default) –Border: Sections for North, South, Center, East, West –Card: Tab like capability, display one card at a time –Grid: two dimensional array of components –GridBag: two dimensional array of components where components can span rows and columns Swing managers –Box: vertical or horizontal list of components –Overlay: components that can overlap each other. See the demo program on the class web-page (by Lewis/Loftus)

Overlay Layout Example OverlayLayout allows a container to display components over the top of each other.

GridBagLayout GridBagLayout defines a grid of cells. Components can span rows and columns and have varied heights and widths.

CardLayout Example CardLayout allows GUIs to display different panels at different times. CardLayout GUIs often use a combo box to control what panel displays JTabbedPane is an alternative to C

GUI Design The goal is to use Java GUI facilities to solve a user's application problem. The first steps for a GUI designer is to: –Fully understand the problem –Design the way the application interact with the user –Create a GUI containment hierarchy GUI applications need to be –Be robust, properly handling all possible errors. For example, make sure to see what happens when the window is resized. –Be intuitive and easy to use –Should have a consistent interface across panels and frames

GUI Look and Feel

GUI Containment Hierarchy North Panel: Two labels, flow layout South Panel: Two Buttons, box layout East Panel: Slider, label, combo box, box layout West Panel: Three box panels with label and text field, panel with two radio buttons, box layout Center Panel: Six check boxes, label, and text field Note: This slide ties to the picture shown on the previous slide Designers likely would create a class for each of the five sections

General Comments It is not hard to create a GUI application, but it can be tedious There is no drag and drop capability to create GUI components like we have in Visual Basic GUIs in java have many single line Statements –To create GUI components –To set GUI properties –To call special methods Good design –Break up GUI applications to a set of panel or component classes. –This makes the code easier to maintain

Steps to create a GUI Application 1.Create a class hierarchy diagram for the application 2.Determine components should be in their own Java class 3.Instantiate the application's JFrame with its title 4.Configure the window close procedure 5.Instantiate the components and set their properties 6.Call the JFrame getContentPane() method to get the default application container. 7.Add the components to the JFrame application container 8.Set the size of the frame 9.Make the frame visible Note: It is possible for a JFrame to have multiple containers (layers)

Steps to Create a Component or Container Class 1.GUI component class signature line –Extend the appropriate component class (extends) –Implement the appropriate listener (implements) 2.Create references to the needed sub-components 3.Instantiate the components in the constructor class or in the applet init() method 4.Define the layout for containers 5.Call methods for setting custom properties 6.Add components to containers 7.Add listeners

Components JButton JButton button = new Jbutton(“Add”); button.setMnemonic(‘A’); button.setToolTipText(“Add a record”); JFrame JFrame frame = new JFrame("A Title"); JTextField JTextField data = new JTextField(“”) String text = data.getText(); JLabel JLabel label = new JLabel(“label to display”); label.setText(“new Text”); JComboBox JComboBox box = new JComboBox(array or object); JRadioButton JRadioButton button= new JRadioButton(“end”, true); JCheckBox JCheckBox box = new JCheckBox((“Bold”, true); Jlist Jlist list = new Jlist(array or object); JScrollPane JScrollPane scroll = new JScrollPane(array or object); JtabbedPane JTabbedPane pane = new JTabbedPane(); pane.addTab(“label”, container);

Listeners: Methods responding to Events Examples MouseListener – respond to user mouse events –Add "implements MouseListener" to the GUI class –Code listener methods (e.g. mouseClicked()) and attach to the GUI object MouseMotionListener – respond to mouse movements –Add "implements MouseMotionListener" to the GUI class –Code listener methods (e.g. mouseMoved()) and attach to the GUI object ActionListener – Recponds once to button selections –Add "implements ActionListener" to the GUI class –Code the "actionPerformed" method and attach to the GUI object ItemListener – Responds multiple times to changes to a component –Add "implements ItemListener" to the GUI class –Code the "itemStateChanged" method –Attach the ItemListener to the GUI object Window Listener – respond to clicks of a frame's X button –Create a class that extends WindowAdapter –Code the WindowListener methods and attach to the frame