Graphical User Interface

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Graphical User Interfaces
Graphical User Interfaces Java’s AWT and Swing APIs.
Java Software Development Paradigm Lecture # 12. Basics of GUI.
CS18000: Problem Solving and Object-Oriented Programming.
Graphic User Interfaces Layout Managers Event Handling.
F27SB2 Programming Languages
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
Java Swing Recitation – 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University.
Chapter 121 Window Interfaces Using Swing Chapter 12.
CS102--Object Oriented Programming Lecture 19: – The Swing Package (II) Copyright © 2008 Xiaoyan Li.
Creating a GUI with Swing. Introduction Very useful link: Swing – is a part of JFC (Java Foundation.
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 CMSC 132: Object-Oriented Programming II Nelson Padua-Perez William Pugh Department of Computer Science University of Maryland, College Park.
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.
Unit 11 Object-oriented programming: Graphical user interface Jin Sa.
GUI and event-driven programming An introduction.
GUI Basics: Introduction. Creating GUI Objects // Create a button with text OK JButton jbtOK = new JButton("OK"); // Create a label with text "Enter your.
Java Programming Chapter 10 Graphical User Interfaces.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Graphical User Interface CSI 1101 N. El Kadri. Plan - agenda Graphical components Model-View-Controller Observer/Observable.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
10/24/20151 Java GUI Programming. 10/24/20152 What is a GUI? Java has standard packages for creating custom Graphical User Interfaces Some of the fundamental.
 2002 Prentice Hall, Inc. All rights reserved Introduction Graphical User Interface (GUI) –Gives program distinctive “look” and “feel” –Provides.
– 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.
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.
Timer class and inner classes. Processing timer events Timer is part of javax.swing helps manage activity over time Use it to set up a timer to generate.
Object Oriented programming Instructor: Dr. Essam H. Houssein.
Layout Managers Arranges and lays out the GUI components on a container.
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.
Java Programming Applets. Topics Write an HTML document to host an applet Understand simple applets Use Labels with simple AWT applets Write a simple.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
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.
Introduction to Java Chapter 9 - Graphical User Interfaces and Applets1 Chapter 9 Graphical User Interfaces and Applets.
Review_6 AWT, Swing, ActionListener, and Graphics.
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.
1 Layout Managers Layout managers –Provided for arranging GUI components –Provide basic layout capabilities –Processes layout details –Programmer can concentrate.
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.
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
Getting Started with GUI Programming Chapter 10 CSCI 1302.
Java Programming Fifth Edition Chapter 13 Introduction to Swing Components.
GUIs & Event-Driven Programming Chapter 11 Review.
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 7 Event-Driven Programming and Basic GUI Objects.
A Quick Java Swing Tutorial
Introduction Many Java application use a graphical user interface or GUI (pronounced “gooey”). A GUI is a graphical window or windows that provide interaction.
Graphical User Interfaces
Christopher Budo, Davis Nygren, spencer franks, Luke miller
A First Look at GUI Applications
Java GUI.
Graphical User Interface (pronounced "gooey")
Lecture 27 Creating Custom GUIs
Ellen Walker Hiram College
Chapter 13: Advanced GUIs and Graphics
Timer class and inner classes
GUI building with the AWT
Presentation transcript:

Graphical User Interface IST 311 / MIS 307

Graphical User Interface GUI programming based on model known as event-driven programming Means the program reacts to events based on user’s interactions with GUI

Graphical User Interface There are 2 distinct libraries of GUI components in Java2 Abstract Windowing Toolkit (AWT) Original Java GUI classes Java Foundation Classes (JFC) Includes the Swing component set Released with Java 2 and extend capabilities of AWT classes Generally don’t mix counterparts in the same program

Graphical User Interface Look and Feel The style and appearance of GUI components AWT classes are tied to the local platform’s GUI features Running on Windows, components will adopt Windows style, running on Mac, adopt that operating system style AWT classes may not behave the same on different operating systems

Graphical User Interface Look and Feel Swing GUI components, developer has the option to decide between a “standard” look and feel vs. platform’s GUI style Swing classes support new functionality Image inside a button Behave the same on different operating systems Swing widgets add an initial J to the names of their corresponding AWT counterparts. java.awt.Button vs. javax.swing.JButton

Basic GUI Some way to provide help to the user Some way to allow input of information Some way to allow output of information Some way to control the interaction between the user and the device

Basic GUI Java applications use JFrame as the top-level window A frame is a GUI window with a title bar and rudimentary functionalty JFrame is a subclass of Container To display JFrame, must give it a size and make it visible Must be able to exit the application when the user closes the frame

Basic GUI JFrame since Java 5 allows you to place components into the content pane with add method add(okButton);

Basic GUI Swing components to handle input, output, control, and help JLabel: a display for a short string of text, an image, or both; good for a prompt to user; not for input JTextField: allows input / output of a single line of text getText( ) and setText( ) methods

Basic GUI JTextArea: multi-line text area used for either input or output Does not contain scrollbars by default Can make it un-editable to prevent user typing JButton: control for the interface; implement an ActionListener to handle the user’s action event

Java Event Model Anything that happens while the computer is running is an event Keystroke, mouse click, insert a disk, etc. When a Java program is running, events passed up through the operating system to program Events that belong to the program must be handled by the program

Java Event Model When something happens within GUI component, an event object is generated and passed to the event listener A event listener is any object that implements a listener interface A GUI component, such as a button, is called the event source

import java.awt.event.*; Java Event Model Must write a method to handle the event JButton this is named actionPerformed ActionListener is defined in: import java.awt.event.*;

Basic GUI How to arrange the interface?

Basic GUI Layout Manager Determine how components are positioned on frames and panels Panel is an invisible container Several layout managers in Java: FlowLayout BorderLayout GridLayout By default, Java uses: BorderLayout for frames FlowLayout for panels

Basic GUI FlowLayout Manager Places components onto a frame as you add them, left to right, top to bottom Components retain their normal size on the frame

Basic GUI BorderLayout Manager Divide the JFrame into 5 areas: north, south, east, west, and center Components placed on a frame expand to fill the space available When one or more border areas are unused, the other areas will extend to fill the unused area Except Center; center is left blank

Basic GUI

Basic GUI BorderLayout Manager One limitation of BorderLayout is that only one component may be added to each area To add several components to an area, you must first add them to a JPanel and then add the panel to the area JPanel inputPanel = new JPanel( ); inputPanel.add(prompt); inputPanel.add(input); getContentPane( ).add(inputPanel, “North”);

Basic GUI GridLayout Manager Create a two-dimensional grid with rows and columns setLayout(new GridLayout(4, 3, 1, 1)); Where: 4 represents rows 3 represents columns 1, 1 represent spacing between rows and columns; the higher the number, the larger the spacing

Basic GUI GridLayout Manager Components added will expand to fill the available space

Basic GUI Import declarations import javax.swing.* import java.awt.* For GUI components like JButton, JLabel import java.awt.* For JFrame container For layout managers import java.awt.event.* For ActionListener interface For ActionEvent class

Public Methods for Swing Components JButton setEnabled(true or false) JTextField JTextField (int) JTextField (String) getText( ): String setEnabled (true or false) JTextArea JTextArea (row, col) append (String) setText (String)

Color and Font

Color and Font Every component has 2 colors: foreground and background JButton’s label is drawn in foreground color on the button’s background color

Color and Font Color is represented by mixing red, green, and blue as a value from 0 to 255 Color.black : (0, 0, 0) Color.blue : (0, 0, 255) Color.green : (0, 255, 0) Color.red : (255, 0, 0) Color.pink : (255, 175, 175) Color.orange : (255, 200, 0) Color.magenta : (255, 0, 255)

Color and Font JLabel logoLabel = new JLabel(“ “, SwingConstants.CENTER); logoLabel.setForeground(Color.blue); logoLabel.setFont(new Font(“TimesRoman”, Font.ITALIC,36)); logoLabel.setText(“Penn State Marina”);