Graphic User Interfaces Part 1. Typical GUI Screen from Microsoft Word What GUI “components” can you see? –Menus? Buttons? Labels? What else? –Anything.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

Graphical User Interfaces (Part IV)
Graphic User Interfaces Layout Managers Event Handling.
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.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
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 and Event-Driven Programming Part 2. Event Handling An action involving a GUI object, such as clicking a button, is called an event. The mechanism.
CPSC150 Week 12 Graphical User Interfaces Chapter 11.
GUI Programming in Java Tim McKenna GUI Programming Concepts l conventional programming: sequence of operations is determined by the program.
More on Creating GUIs in Java using Swing David Meredith Aalborg University.
CC1007NI: Further Programming Week 5 Dhruba Sen Module Leader (Islington College)
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 Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 13 Creating User.
3461A Readings from the Swing Tutorial. 3461A Overview  The follow is the Table of Contents from the trail “Creating a GUI with JFC/Swing” in the “The.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
Dale Roberts GUI Programming using Java - Introduction Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
Chapter 9: Visual Programming Basics Object-Oriented Program Development Using Java: A Class-Centered Approach.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
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.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
1 Graphical User Interfaces AWT and Swing packages Frames and Panels Components Nested Panels Images Reading for this Lecture: L&L, 3.9 – 3.11.
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 Programming: Advanced Topics 1 Components and Facilities for Rich Graphical User Interfaces Chapter 7.
Graphical User Interfaces (Part 2) 1. View  view  presents the user with a sensory (visual, audio, haptic) representation of the model state  a user.
CSE1030-HR GUI The Big Picture Building the View Building the Controller Separating the Concerns Going Further.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Programming with Java’s Swing API February 4, 2003 CMPS Advanced Programming Graphical User Interfaces.
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.
IM103 week 11 Part 2 P532 Case Study part 2: the Airport GUI Learning objectives By the end of this lecture you should be able to:  use the JTabbedPane.
CS1054: Lecture 21 - Graphical User Interface. Graphical User Interfaces vs. Text User Interface.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 – Graphical User Interfaces Java Foundations: Introduction to Programming.
Swing Components. Introduction Swing – A set of GUI classes – Part of the Java's standard library –Much better than the previous library: AWT Abstract.
Swing - 2 Session 13. Swing - 2 / 2 of 38 Objectives (1) Discuss trees and tables Discuss progress bars Discuss MVC architecture Describe menus.
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.
Creating User Interfaces Event-Driven Programming.
Basics of GUI Programming Chapter 11 and Chapter 22.
Creating a Window. A basic window in Java is represented by an object of the class Window in the package java.awt.
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.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Chapter 14: Introduction to Swing Components. Objectives Understand Swing components Use the JFrame class Use the JLabel class Use a layout manager Extend.
Computer Science [3] Java Programming II - Laboratory Course Lab 4 -1 : Introduction to Graphical user interface GUI Components Faculty of Engineering.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 15 : Swing III King Fahd University of Petroleum & Minerals College of Computer.
Lecture # 6 Graphical User Interface(GUI). Introduction A graphical user interface (GUI) presents a user- friendly mechanism for interacting with an application.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
1 Lecture 8: User Interface Components with Swing.
View  view  presents the user with a sensory (visual, audio, haptic) representation of the model state  a user interface element (the user interface.
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
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.
Java Programming Fifth Edition Chapter 13 Introduction to Swing Components.
A Quick Java Swing Tutorial
A First Look at GUI Applications
IFS410: Advanced Analysis and Design
Advanced Programming in Java
Advanced GUIs and Graphics
Graphical User Interface
TA: Nouf Al-Harbi NoufNaief.net :::
Presentation transcript:

Graphic User Interfaces Part 1

Typical GUI Screen from Microsoft Word What GUI “components” can you see? –Menus? Buttons? Labels? What else? –Anything that appears on the screen was programmed carefully to be there.. What do you notice about the layout of the screen? –Where are the exit buttons? Where is the empty sheet? What happens when I resize? What things can happen when you use the mouse –Go right around the screen and think carefully? –How do you think this is handled programmatically?

GUIs.. A lot of things to do Components.. –What do I need? Buttons? Menus? Etc –Where should I put them? Layouts? –What should they “do” when I use the mouse? Event handling/ listeners –Java Swing supports all of this

GUI – what makes a Graphic User Interface Windows User interaction –pressing buttons, choosing menu options Event driven programming

GUIs Two sets of components are available for GUIs in Java awt components (abstract windowing toolkit) package is java.awt Swing components package is javax.swing You’ll see both in the Java API documentation…

awt awt Components –original GUI components –tied directly to the local platforms GUI capabilities –local platform determines the “look and feel” –heavyweight components

Swing Swing components –“lightweight components” –not tied by the local capabilities of the platform do not rely on the operating system to render themselves draw themselves using standard features of the Graphics object –can specify same “look and feel” across all platforms –have much richer functionality than awt components

GUI Classes Types of classes –graphics - drawing shapes and lines, selecting fonts, colours etc… –components – buttons, labels, textfields, etc are placed in containers (e.g. in a panel) –layout managers – used to arrange the components in a container –event handling – handling external events, e.g. pushing buttons, mouse moves, uses event handlers, listeners and adapters –image manipulation – incorporate images in a number of formats

Class Hierarchy Object Component Container JComponent JButton JTextComponent JTextField JLabel JPanel Window Dialog JDialog Frame JFrame JWindow

Creating a Window Your window should instantiate or extend one of the main Swing containers –JFrame (top level window with title & border) –JWindow (window – no title or system menu) –JDialog (typically takes input from user)  all basic window functionality is available (resizing, moving...) Add components to the window –buttons, textfields, lists, etc… for normal GUI controls –panels for grouping The positioning of the components in the container is determined by the layout manager (see later)

JFrame Title Bar Content Pane Space for Menu Bar Border

A code example for a simple frame See MyFrame. Java This sets up a “window” or frame, with a label and a text field Things to note A subclass of JFrame Setting up a menu bar.. Add a menu and a menu item Setting up content on the content pane..setContentPane() which accepts a container… What does the createContentPane() return?

Creating a Window public SimpleFrame extends JFrame{…} Set up window –setTitle(String s) [can use super(“title text”) instead] –setSize(int w, int h) [or pack() fits to controls on frame] –setLocation(int x, int y) –setVisible(boolean b) Indicate what to happen when close is clicked setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); –3 possible operations [hide, nothing, dispose] Stop here

Designing the Window JComponent Java classes that represent GUI Controls include –JLabel –Icons –JButton –JTextField and JTextArea –JScrollbar and JSlider –JCheckbox and JRadioButton –JList –and many others…

Adding components JComponents are placed in Containers Most useful/common container is JPanel An instance of the required control is instantiated and added to the JPanel Container pane = new JPanel(); JButton myButton = new JButton(“Save”); pane.add(myButton); Components should grouped in separate containers (JPanels) on another container JPanel buttonPanel = new JPanel(); buttonPanel.add(saveButton); buttonPanel.add(cancelButton); pane.add(buttonPanel)

Adding components* In a JFrame components are added to the content pane –Content pane is a Container setContentPane(createContentPane()); … /* Then have a method to populate the contentPane container with whatever will be in it..*/ private Container createContentPane(){ JPanel pane = new JPanel(); JButton myButton = new JButton(“Save”); pane.add(myButton); … return pane; } setContentPane() Is a method in Jframe class

More GUI things that you can do. There are all sort of visual features that help the user when they are using a GUI to find what they want..e.g. –Tool tips –Borders (e.g. to help highlight a button) –Menus, and their various menu items –Fast keys (mneumics) on key itme –accelerator keys on menu items –Icons on things (e.g. picture on a button) –Fonts..

–Tool tips –Borders (e.g. to help highlight a button) –Menus, and their various menu items –Fast keys (mneumics) on key itme –accelerator keys on menu items –Icons on things (e.g. picture on a button) –Fonts.. * These ALL exist already in the Java API – as classes (and interfaces) - you just have to find them. * Illustrated for reference in following slides – you have to USE them to get familiar.. More GUI things that you can do.

Tooltips A tooltip is a context sensitive text string that is displayed in a popup window when the mouse rests over an object JButton myButton = new JButton(“Save”); myButton.setToolTipText(“Click this to save”); pane.add(myButton);

Borders javax.swing.Border package consists of several classes to draw borders around components b = new JButton ("ColorizedEtched"); b.setBorder (new EtchedBorder (Color.red, Color.green));

Menus There are 3 main classes that create menus –JMenuBar : creates the menu toolbar –JMenu : creates the dropdown menu on the menu bar –JMenuItem : creates the menu item on the menu – use setJMenuBar(JMenuBar menuBar) to set up the menu in the content pane JMenuBar bar = new JMenuBar(); JMenu fileMenu = new JMenu ("File"); bar.add(fileMenu); fileMenu.add (new JMenuItem ("New")); fileMenu.add (new JMenuItem (“Open")); fileMenu.addSeparator(); fileMenu.add (new JMenuItem (“Close”));

Using Menus Different kinds of menu item –Icon(JMenuItem) –Text and Icon (JMenuItem) –Radio Buttons(JRadioButtonMenuItem) Group in ButtonGroup() –Check boxes(JCheckBoxMenuItem) Submenu –add JMenu to a JMenu

Menu Shortcuts Mnemonics – underlines a character on the menu (to help navigate the menu in an alternative way – e.g. accessibility) Use the constructor of the menu item OR Use the setMnemonic method. Use the KeyEvent constant or the actual constant itself –menu.setMnemonic(KeyEvent.VK_N); –menuItem.setMnemonic(‘N’);

Menu Shortcuts Accelerator Keys Used to bypass navigating the menu to directly choose a menu item Use the setAccelerator method Must use a KeyStroke object – which combines a key and a modifier mask –menuItem.setAccelerator (KeyStroke.getKeyStroke( KeyEvent.VK_C, ActionEvent.CTRL_MASK)); Control key “C”

Icons Used to describe fixed size pictures Icons are typically embedded in a JComponent (e.g. JButton or JMenuItem) –not really a “component” as such… used with other components ImageIcon class is an implementation of Icon that creates an Icon from an image (e.g..gif file or URL) Icon myIcon = new ImageIcon(“myPicture.gif”); Using an Icon: JButton myButton = new JButton(“My Button”, myIcon); file.add(new JMenuItem(“menu item”, myIcon); –setHorizontalTextPosition(…) and setVerticalTextPosition positions the text in different area around the icon

Fonts Use Font class to set the font for a component… JLabel fancyLabel = new JLabel("Fancy Big Label"); // Instantiate a Font object to use for the label Font fancyFont = new Font("Serif", Font.ITALIC, 32); // Associate the font with the label fancyLabel.setFont(fancyFont); // Place the Icon in the label fancyLabel.setIcon(tigerIcon); // Align the text to the right of the Icon fancyLabel.setHorizontalAlignment(JLabel.RIGHT); Font name, Style, size

Lab First GUI

Part 1

Part 2

Part 3