1 Graphical User Interface (GUI) Applications Abstract Windowing Toolkit (AWT) Events Handling Applets.

Slides:



Advertisements
Similar presentations
Event handling and listeners What is an event? user actions and context event sources and listeners Why should my programs be event- driven? User interaction.
Advertisements

Fondamenti di Java Introduzione alla costruzione di GUI (graphic user interface)
1 Event Listeners Some Events and Their Associated Event Listeners Act that Results in the EventListener Type User clicks a button, presses Enter while.
User Interfaces II GUI – Awt, Swing, Web
Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Unit 121 A layout manager is an object that determines the manner in which components are arranged in a container. Each layout manager implements one of.
Java Graphical User Interface (GUI) using Visual Editor in eclipse CSI 1390 – Java Programming Instructor: Saeid Nourian University.
Graphical User Interfaces
Web Design & Development Lecture 19. Java Graphics 2.
Programming in Java; Instructor:John Punin Graphics and Graphical User Interfaces1 Programming in Java Graphics and Graphical User Interfaces.
Mari Göransson - KaU - Datavetenskap - DAVD11 1 Java Event Handling --
Graphical User Interfaces Java’s AWT and Swing APIs.
Graphical User Interfaces (Part IV)
CS18000: Problem Solving and Object-Oriented Programming.
Graphic User Interfaces Layout Managers Event Handling.
F27SB2 Programming Languages
TCU CoSc Programming with Java Handling Events.
Introduction to Java Classes, events, GUI’s. Understand: How to use TextPad How to define a class or object How to create a GUI interface How event-driven.
Jan Event Handling -1.1 Yangjun Chen Dept. Business Computing University of Winnipeg.
Java Swing Recitation – 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University.
Gui Interfaces a la Swing Up to speed with Swing by Steven Gutz is a good source It don’t mean a thing if it ain’t got that swing Duke Ellington.
1 lecture 12Lecture 13 Event Handling (cont.) Overview  Handling Window Events.  Event Adapters Revisited.  Introduction to Components and Containers.
10.1 AWT The AWT classes Users today expect a Graphical User Interface (GUI) Improves application usability Difficult to implement cross-platform.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
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 Interface CSI 1101 N. El Kadri. Plan - agenda Graphical components Model-View-Controller Observer/Observable.
Java GUI CSCE 190 – Java Instructor: Joel Gompert Mon, July 26, 2004.
Dale Roberts GUI Programming using Java - Event Handling Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
Graphical User Interface Components: Part 1 Chapter 11.
 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.
1 Unit 5 GUI Aum Amriteshwaryai Namah. 2 Overview Shall learn how to reuse the graphics classes provided by Java for constructing Graphical User Interface.
GUI Clients 1 Enterprise Applications CE00465-M Clients with Graphical User Interfaces.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
Copyright © 2002, Systems and Computer Engineering, Carleton University c-Gui3.ppt * Object-Oriented Software Development Part 18-c Building.
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.
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.
UID – Event Handling and Listeners Boriana Koleva
Event Handling. 2 GUIs are event driven –Generate events when user interacts with GUI e.g., moving mouse, pressing button, typing in text field, etc.
The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a.
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.
Object Oriented Programming.  Interface  Event Handling.
Agenda Introduction. Event Model. Creating GUI Application. Event Examples.
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.
Event Handling CS 21a: Introduction to Computing I First Semester,
TENTH LECTURE Event and listener. Events and Listeners An event can be defined as a type of signal to the program that something has happened. The event.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
Java Swing and Events Chris North cs3724: HCI. Presentations nadine edwards, steve terhar Vote: UI Hall of Fame/Shame?
Event Driven (Asynchronous) Programming. Event handling in Unity Subclass a class that contains event handling methods, and then override those methods.
AWT Vs SWING. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many applications Uses.
GUI Programming in Java Hao Jiang Boston College April, 2009.
A Quick Java Swing Tutorial
GUI Programming using Java - Event Handling
CSC 205 Programming II Lecture 5 AWT - I.
Welcome To java
Aum Amriteshwaryai Namah
Lecture 09 Applets.
Ellen Walker Hiram College
AWT.
Introduction to Computing Using Java
GUI building with the AWT
Programming Graphical User Interface (GUI)
GUI building with the AWT
Graphical User Interface
Presentation transcript:

1 Graphical User Interface (GUI) Applications Abstract Windowing Toolkit (AWT) Events Handling Applets

2 Introduction Java began as a language to be integrated with browsers. But it as evolved as a powerful language for developing stand-alone graphical applications and also server-side applications. Today, Java has large and powerful libraries to deal with 2D and 3D graphics and imaging, as well as the ability to build complex client-side interactive systems. Our focus: Simple GUI apps and Applets and Graphics. More on graphics in your 3 rd year subject on Interactive Computing.

3 AWT - Abstract Windowing Toolkit Single Windowing Interface on Multiple Platforms Supports functions common to all window systems Uses Underlying Native Window system AWT provides GUI widgets Event Handling Containers for widgets Layout managers Graphic operations

4 AWT - Abstract Window Toolkit Portable GUI - preserves native look and feel Standard GUI Components (buttons…) Containers - Panels, Frames, Dialogs Graphics class for custom drawing Layouts responsible for actual positioning of components: BorderLayout, GridLayout, FlowLayout, Null layout

5 Adding Components via Layouts

6 Building Graphical User Interfaces import java.awt.*; Assemble the GUI use GUI components, basic components (e.g., Button, TextField) containers (Frame, Panel) set the positioning of the components use Layout Managers Attach events

7 A sample GUI program import java.awt.*; public class MyGui { public static void main(String args[] ) { Frame f = new Frame ("My Frame"); Button b = new Button("OK"); TextField tf = new TextField("Programming in Java", 20); f.setLayout(new FlowLayout()); f.add(b); f.add(tf); f.setSize(300, 300); f.setVisible(true); }

8 output Output

9 Events Each GUI component (e.g., a Button) that wishes to respond to an event type (e.g., click), must register an event handler, called a Listener. The listener is an object of a "Listener" interface. A Listener class can be created by subclassing (through "implements") one of Listener interfaces (all listener inrefaces are in the java.awt.event package = > must import java.awt.event.*; ) The registration of the listener is done by a call to a method such as addActionListener( ). Each GUI component class has one or more such add…() methods, where applicable.

10 Events b.addActionListener ( ); method to add a listenerlistener object Button f.addWindowListener ( ); Frame

11 Listener Interfaces in java.awt.event.* [1] ActionListener [2] ItemListener [3] MouseMotionListener [4] MouseListener [5] KeyListener [6] FocusListener [7] AdjustmentListener [8] ComponentListener [9] WindowListener [10] ContainerListener [11] TextListener

12 Listener Interfaces Each listener interface has methods that need to be implemented for handling different kinds of events. For example 1, the ActionListener interface has a method actionPerformed() button component is operated. For example2, the MouseMotionListener interface has two methods: 1) mouseDragged(MouseEvent) - Invoked when a mouse button is pressed on a component and then dragged. 2) mouseMoved(MouseEvent) - Invoked when the mouse button has been moved on a component (with no buttons down).

13 Implementing the ActionListener Interface and attaching an event handler to a button import java.awt.*; import java.awt.event.*; public class MyGui1 { public static void main(String args[] ) { Frame f = new Frame ("My Frame"); MyGuiAction ga = new MyGuiAction(f); } class MyGuiAction implements ActionListener { static int count = 0; Button b; TextField tf; MyGuiAction(Frame f) { b = new Button("OK"); b.addActionListener(this); tf = new TextField("Hello Java", 20); f.setLayout(new FlowLayout()); f.add(b); f.add(tf); f.setSize(300, 300); f.setVisible(true); } public void actionPerformed( ActionEvent e) { if(e.getSource() == b) { count++; System.out.println("Button is Pressed"); tf.setText("Hello Java Click "+count); }

14 Output and Clicks on OK Button Exec started 1 st click on OK button2 nd click on OK button

15 BorderLayout Example import java.awt.*; public class MyGui2 { public static void main(String args[] ) { Frame f = new Frame ("My Frame"); f.setLayout(new BorderLayout()); // Add text field to top f.add("North",new TextField()); // Create the panel with buttons at the bottom... Panel p = new Panel(); // FlowLayout p.add(new Button("OK")); p.add(new Button("Cancel")); f.add("South",p); f.add("Center", new TextField("Center region")); f.setSize(300, 300); f.setVisible(true); }

16 Output