UMass Lowell Computer Science 91.460 Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 16 Java Fundamentals Java2 Graphical User Interfaces.

Slides:



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

CS18000: Problem Solving and Object-Oriented Programming.
Unit 3 Graphical User Interface (GUI) Dr. Magdi AMER.
Graphic User Interfaces Layout Managers Event Handling.
F27SB2 Programming Languages
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Event Handling. In this class we will cover: Basics of event handling The AWT event hierarchy Semantic and low-level events in the AWT.
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.
Graphical User Interfaces (GUIs) GUI: An application that uses graphical objects to interact with users GUI applications consist of: –Events: A user or.
Event Handling n Events: an event is an object that describes a state change in a source. n Event Sources: A source is an object that generates an event.
PROGRAMMING REVIEW Lab 2 EECS 448 Dr Fengjun Li and Meenakshi Mishra.
28-Aug-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming Design Topic : Event Handling – GUI Part II.
Java Programming Chapter 10 Graphical User Interfaces.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Introduction to GUI in Java 1. Graphical User Interface Java is equipped with many powerful,easy to use GUI component such as input and output dialog.
Graphical User Interface CSI 1101 N. El Kadri. Plan - agenda Graphical components Model-View-Controller Observer/Observable.
MIT AITI 2003 Lecture 17. Swing - Part II. The Java Event Model Up until now, we have focused on GUI's to present information (with one exception) Up.
Java GUI CSCE 190 – Java Instructor: Joel Gompert Mon, July 26, 2004.
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.
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.
Copyright © 2002, Systems and Computer Engineering, Carleton University c-Gui3.ppt * Object-Oriented Software Development Part 18-c Building.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 15 Java Fundamentals Java2 Graphical User Interfaces.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Object Oriented Programming Engr. M. Fahad Khan Lecturer, Software Engineering Department University of Engineering & Technology, Taxila.
Pravin Yannawar, DOCS, NMU Jalgaon. Basic Java : Event handling in AWT and Swing 2 Objectives of This Session Explain the Event handling mechanism & demonstrate.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
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.
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.
COSC 3461: Module 2 Control Flow Paradigms: Reacting to the User.
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.
Anonymous Classes An anonymous class is a local class that does not have a name. An anonymous class allows an object to be created using an expression.
Object Oriented Programming.  Interface  Event Handling.
Introduction to Java Chapter 9 - Graphical User Interfaces and Applets1 Chapter 9 Graphical User Interfaces and Applets.
GUI DYNAMICS Lecture 11 CS2110 – Fall GUI Statics and GUI Dynamics  Statics: what’s drawn on the screen  Components buttons, labels, lists, sliders,
Graphical User Interface Components: Part 1 Chapter 11.
Java the UML Way versjon Only to be used in connection with the book "Java the UML Way", by Else Lervik and.
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.
Event-Driven Programming CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Computer Science [3] Java Programming II - Laboratory Course Lab 4 -1 : Introduction to Graphical user interface GUI Components Faculty of Engineering.
Event-Driven Programming F Procedural programming is executed in procedural order. F In event-driven programming, code is executed upon activation of events.
 Figure illustrates a hierarchy containing many event classes from the package java.awt.event.  Used with both AWT and Swing components.  Additional.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Graphical User Interface (GUI)
1 Lecture 8: User Interface Components with Swing.
Jozef Goetz Credits: Copyright  Pearson Education, Inc. All rights reserved. expanded by J. Goetz, 2016.
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.
1 DemoBasic_v3, DemoBasic_v4 JButton JLabel. 2 Registering an ActionListener Register by invoking the following from within constructor DemoBasicFrame.
1 A Quick Java Swing Tutorial. 2 Introduction Swing – A set of GUI classes –Part of the Java's standard library –Much better than the previous library:
© Copyright by Pearson Education, Inc. All Rights Reserved. Appendix I GUI Components and Event Handling Android How to Program, 3/e.
A Quick Java Swing Tutorial
CSC 205 Programming II Lecture 5 AWT - I.
Welcome To java
Aum Amriteshwaryai Namah
Appendix I GUI Components and Event Handling
A Quick Java Swing Tutorial
CSE 114 – Computer Science I Event Programming
PC02 Term 1 Project Basic Messenger. PC02 Term 1 Project Basic Messenger.
Web Design & Development Lecture 12
A Quick Java Swing Tutorial
Presentation transcript:

UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 16 Java Fundamentals Java2 Graphical User Interfaces (GUIs) Mon. 10/16/00

Homework Status 1 Fri, 9/8 Fri, 9/15 Part 1 Mon, 9/18 Part 2 Mon, 9/18 Part 2 2Fri, 9/15 Fri, 9/22 Part 1 & Part 2 3Fri, 9/22 Fri, 9/29Part 1 & Part 2 4Fri, 10/6Fri, 10/13Part 1 & Part 2 5Fri, 10/13Fri, 10/20Part 1 & Part 2 HW# Assigned Due Content

Event Delegation ä EventListeners are programmer-selected classes that are distinct from the widget ä EventListeners are interfaces ä Widgets attach implementations of these listener interfaces ä Such implementations are often done via an anonymous inner class ä These implementations “handle” the event

Example of an Event Listener public class MyFrame extends JFrame { // inside of a constructor, for example… jTextField1 = new JTextField(); jTextField1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) { jTextField1ActionPerformed(evt); jTextField1ActionPerformed(evt); } } ); // end of addActionListener ); // end of addActionListenergetContentPane().add(jTextField1);...}

Example of an Event Listener public class MyFrame extends JFrame {... private void jTextField1ActionPerformed (ActionEvent evt) { String inputString = jTextField1.getText(); String inputString = jTextField1.getText(); myColor = myStringToColor(inputString); myColor = myStringToColor(inputString); updateWidgets(); updateWidgets(); Container c = getContentPane(); Container c = getContentPane(); c.repaint(); c.repaint();}...}

Java Events ä Java aggregates low-level user events to make life easier for the developer ä Depending on the “focus” (“active” widget), e.g.: ä Button selected ä Text entered ä List item selected ä Menu item selected (we won’t discuss Java menus in this course) ä Item dragged (we won’t discuss Java drag and drop in this course)

Some Types of Java Events ä ActionEvent (e.g. for a JButton) ä ListSelectionEvent (e.g. for a JList) ä AdjustmentEvent ä ItemEvent ä ComponentEvent ä ContainerEvent ä FocusEvent ä PaintEvent ä WindowEvent ä Input Event ä KeyEvent ä MouseEvent

Types of Java Event Listeners ä ActionListener ä AdjustmentListener ä ItemListener ä ComponentListener ä ContainerListener ä FocusListener ä WindowListener ä KeyListener ä MouseListener ä MouseMotionListener ä TextListener ä ListSelectionListener

Event Adapters ä Convenience classes that implement event listener interfaces ä Provide “stubs” for methods you don’t want to implement yourself ä You just override the implementation of event handlers of interest ä For example, the WindowListener interface declares windowActivated, windowClosed, windowClosing, windowDeactivated, windowIconified, windowDeiconified, windowOpened methods that the WindowAdapter implements

Example of an Event Adapter public class MyFrame extends JFrame {... // inside of a constructor, for example addWindowListener (new WindowAdapter () { public void windowClosing (WindowEvent evt) { public void windowClosing (WindowEvent evt) { System.exit (0); System.exit (0); } } ); // end of addWindowListener call ); // end of addWindowListener call...}

Processing GUI Events in Java ä Implement an event handler ä Define a class that implements an event-listener interface (i.e., defines the appropriate event handling method(s)) ä Create an instance of the class ä Register the event handler with the widget, e.g.: ä addActionListener() ä addItemListener()

Another Example // define a public class MyFrame that extends JFrame private JButton myButton1; private boolean state1; // instance variables // in the constructor myButton1 = new JButton(“Press Me”); ButtonHandler handler = new ButtonHandler(); myButton1.addActionListener (handler); addWindowListener (new WindowAdapter () { public void windowClosing (WindowEvent evt) {System.exit(0); } public void windowClosing (WindowEvent evt) {System.exit(0); } } ); ); // elsewhere in the class, define method main for class MyFrame public static void main(String args[]) { MyFrame myFrame1 = new MyFrame(); MyFrame myFrame1 = new MyFrame(); myFrame1.show(); myFrame1.show();}

Another Example (2) // elsewhere in the class, define an inner class private class ButtonHandler implements ActionListener { public void actionPerformed(ActionEvent evt) public void actionPerformed(ActionEvent evt) { if (state1) { if (state1) { myButton1.setText("State2”); myButton1.setText("State2”); state1 = false; state1 = false; } else { else { myButton1.setText("State1”); myButton1.setText("State1”); state1 = true; state1 = true; } }

java.awt.Component ä The parent class for almost all user interface widgets ä Includes methods for: ä Adding various event listeners ä Getting/setting location & size ä Handling text (fonts,...) ä Painting a Graphics object ä Processing focus, visibility, colors, cursors,...

javax.swing.JComponent ä Parent class for most Swing components ä Supports different look-and-feels ä Mechanisms for tool tips, mnemonics, internationalization, borders, scrolling,...

java.awt.Frame ä Top-level window (implemented via native window) ä Has a title ä Can have a menubar ä Controls cursors

Some Swing GUI Components ä JLabel ä JTextField ä JButton ä JCheckBox ä JComboBox ä JComponent ä JFrame ä JPanel ä JList ä JScrollPane

javax.swing.JFrame ä Extends Frame ä Platform-neutral window ä Children must be added to the content pane (Container) ä Has default close operation

javax.swing.JPanel ä Panels are sub-containers (containers within containers) ä Used to organize user interface into major sections ä Fairly lightweight

javax.swing.JLabel ä Extends JComponent ä Non-editable text and/or Image ä Generally does not change even under program control ä Often used with a text entry field ä Very important human factors element

javax.swing.JButton ä Extends AbstractButton ä Implements a simple user selection paradigm ä Typically has a title ä Can also have an Icon ä Several types ä Simple push button (command button) ä Select one of many radio button ä Two-state check box

javax.swing.JTextField ä Extends JTextComponent ä Basic one-line text entry ä Can be uneditable, typically editable ä Can set size by number of characters ä Includes text processing mechanisms (font, alignment,...)

javax.swing.JList ä Extends JComponent ä Multiple or sing-select, potentially scrolla ble, list ä Need to embed in a JScrollPane to get scrollbars ä Includes mechanisms to set, clear selected item(s), set number of visible items, modify colors, convert point to list index, modify list data,... ä Different selection modes (single, single contiguous, multiple discrete)

java.awt.Container ä A collection of (holder for) other widgets ä You usually work with one of its subclasses (like JFrame) ä You add() other widgets to a container ä Can have a layout policy ä Set before add widgets ä Only one layout policy at a time ä Has benefits and disadvantages

Layout Policies ä Set with setLayout() method ä FlowLayout (left to right, top to bottom) ä BorderLayout (5 regions) ä GridLayout (arbitrary sized matrix) ä Others (Box, Card, GridBag,...)