Marcin Luckner Warsaw University of Technology Faculty of Mathematics and Information Science

Similar documents
GUI Software Architecture

(listener)... MouseListener, ActionLister. (adapter)... MouseAdapter, ActionAdapter. java.awt AWT Abstract Window Toolkit GUI

Sri Vidya College of Engineering & Technology

2010 가을학기부산대학교정보컴퓨터공학부 OVERVIEW OF GUI PROGRAMMING

Java: Graphical User Interfaces (GUI)

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User

Introduction to the JAVA UI classes Advanced HCI IAT351

12/22/11. Copyright by Pearson Education, Inc. All Rights Reserved.

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

10/16/2008. CSG 170 Round 5. Prof. Timothy Bickmore. User Analysis Task Analysis (6) Problem Scenarios (3)

Graphics programming. COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson)

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

Event Driven Programming

PIC 20A GUI with swing

Advanced Java Programming. Swing. Introduction to Swing. Swing libraries. Eran Werner, Tel-Aviv University Summer, 2005

SD Module-1 Advanced JAVA

CompSci 125 Lecture 17. GUI: Graphics, Check Boxes, Radio Buttons

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

SD Module-1 Advanced JAVA. Assignment No. 4

CS11 Java. Fall Lecture 3

GUI Event Handlers (Part I)

Packages: Putting Classes Together

CSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing

Chapter 6: Graphical User Interfaces

Java & Graphical User Interface II. Wang Yang wyang AT njnet.edu.cn

Method Of Key Event Key Listener must implement three methods, keypressed(), keyreleased() & keytyped(). 1) keypressed() : will run whenever a key is

CS11 Java. Fall Lecture 4

Swing. By Iqtidar Ali

Basicsof. JavaGUI and SWING

11/7/12. Discussion of Roulette Assignment. Objectives. Compiler s Names of Classes. GUI Review. Window Events

Graphical User Interfaces. Comp 152

Java Graphical User Interfaces AWT (Abstract Window Toolkit) & Swing

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011

Advanced Java Programming (17625) Event Handling. 20 Marks

Starting Out with Java: From Control Structures Through Objects Sixth Edition

Virtualians.ning.pk. 2 - Java program code is compiled into form called 1. Machine code 2. native Code 3. Byte Code (From Lectuer # 2) 4.

CS 251 Intermediate Programming GUIs: Event Listeners

Graphical User Interfaces in Java - SWING

All the Swing components start with J. The hierarchy diagram is shown below. JComponent is the base class.

3 Combining Widgets to create Graphical User Interfaces

Java. GUI building with the AWT

Unit 7: Event driven programming

(Incomplete) History of GUIs

GUI Event Handling 11. GUI Event Handling. Objectives. What is an Event? Hierarchical Model (JDK1.0) Delegation Model (JDK1.1)

Programming Mobile Devices J2SE GUI

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!

The AWT Event Model 9

GUI Basics. Object Orientated Programming in Java. Benjamin Kenwright

Graphical User Interfaces (GUIs)

UI Software Organization

Java Swing. based on slides by: Walter Milner. Java Swing Walter Milner 2005: Slide 1

Graphical User Interfaces 2

Summary. Section 14.1 Introduction. Section 14.2 Java s New Nimbus Look-and-Feel. 618 Chapter 14 GUI Components: Part 1

Java Event Handling -- 1

UNIT-3 : MULTI THREADED PROGRAMMING, EVENT HANDLING. A Multithreaded program contains two or more parts that can run concurrently.

Chapter 8. Java continued. CS Hugh Anderson s notes. Page number: 264 ALERT. MCQ test next week. This time. This place.

Graphic User Interfaces. - GUI concepts - Swing - AWT

Java continued. Chapter 8 ALERT ALERT. Last week. MCQ test next week. This time. This place. Closed book. Assignment #2 is for groups of 3

Lecture 5: Java Graphics

KF5008 Program Design & Development. Lecture 1 Usability GUI Design and Implementation

Dr. Hikmat A. M. AbdelJaber

Java GUI Design: the Basics

Window Interfaces Using Swing Objects

Handout 14 Graphical User Interface (GUI) with Swing, Event Handling

CS 251 Intermediate Programming GUIs: Components and Layout

Computer Programming Java AWT Lab 18

Programming Languages and Techniques (CIS120)

Jonathan Aldrich Charlie Garrod

Programming graphics

Come & Join Us at VUSTUDENTS.net

Graphical User Interfaces 2

CSE 331. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

I/O Framework and Case Study. CS151 Chris Pollett Nov. 2, 2005.

Chapter 12 GUI Basics

Graphical User Interfaces 2

Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling

Example Programs. COSC 3461 User Interfaces. GUI Program Organization. Outline. DemoHelloWorld.java DemoHelloWorld2.java DemoSwing.

Lab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in

Systems Programming Graphical User Interfaces

Graphical User Interface (GUI)

Using Several Components

GUI Program Organization. Sequential vs. Event-driven Programming. Sequential Programming. Outline

Layout. Dynamic layout, Swing and general layout strategies

Building Graphical User Interfaces. GUI Principles

Week Chapter Assignment SD Technology Standards. 1,2, Review Knowledge Check JP3.1. Program 5.1. Program 5.1. Program 5.2. Program 5.2. Program 5.

public void mouseexited (MouseEvent e) setminute(getminute()+increment); 11.2 public void mouseclicked (MouseEvent e) int x = e.getx(), y = e.gety();

Swing UI. Powered by Pentalog. by Vlad Costel Ungureanu for Learn Stuff

GUI Design. Overview of Part 1 of the Course. Overview of Java GUI Programming

CHAPTER 2. Java Overview

Window Interfaces Using Swing Objects

GUI in Java TalentHome Solutions

Widgets. Overview. Widget. Widgets Widget toolkits Lightweight vs. heavyweight widgets Swing Widget Demo

CONTENTS. Chapter 1 Getting Started with Java SE 6 1. Chapter 2 Exploring Variables, Data Types, Operators and Arrays 13

14.2 Java s New Nimbus Look-and-Feel 551 Sample GUI: The SwingSet3 Demo Application As an example of a GUI, consider Fig. 14.1, which shows the SwingS

Welcome to CIS 068! 1. GUIs: JAVA Swing 2. (Streams and Files we ll not cover this in this semester, just a review) CIS 068

China Jiliang University Java. Programming in Java. Java Swing Programming. Java Web Applications, Helmut Dispert

CSE 331. Event- driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

CHAPTER 1: A GENERAL INTRODUCTION TO PROGRAMMING 1

Module 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Transcription:

Marcin Luckner Warsaw University of Technology Faculty of Mathematics and Information Science mluckner@mini.pw.edu.pl http://www.mini.pw.edu.pl/~lucknerm

} Abstract Window Toolkit Delegates creation and behavior to the native GUI toolkit Portable, but on a lowest common denominator Extended by Swing Swing it is built on top of the AWT architecture mluckner@mini.pw.edu.pl 11/30/16 2

} Swing is part of the Java Foundation Classes (JFC) } All components are created and managed by Java } May be slower than AWT } Has a rich and convenient set of user interface elements } less prone to platform-specific bugs } gives a consistent user experience across platforms 3

} We will focus on Swing, but } The Eclipse integrated development environment uses a graphics toolkit called SWT } Oracle developed an alternate technology, called JavaFX, that may at some point become a replacement for Swing. 4

} Most Swing component classes start with a J JFrame JButton } They cam be easy mistaken with AWT components: Frame Button } Mixing AWT and Swing should be ommited However, it should works with Java 1.6 version 2 and later 5

} Create the frame. JFrame frame = new JFrame("FrameDemo"); } Allow the user to close the frame frame.setdefaultcloseoperation(jframe.ex IT_ON_CLOSE); } Create components and put them in the frame. frame.getcontentpane().add(emptylabel) } Size the frame. frame.pack(); } Show it. frame.setvisible(true); 6

7

} All Swing components whose names begin with "J" descend from the Jcomponent class } Selected features Tool tips Painting and borders Application-wide pluggable look and feel Support for layout Support for drag and drop Double buffering Key bindings 8

} JButton A common button } JCheck Box A check box button } JRadioButton One of a group of radio buttons. } JToggleButton Implements toggle functionality inherited by JCheckBox andjradiobutton. 9

} Menu Items have similar structure as buttons JMenuItem JCheckBoxMenuItem JRadioButtonMenuItem 10

} In Java you completely control how events are transmitted from the event sources (such as buttons or scrollbars) to event listeners. } You can designate any object to be an event listener } You can create more than one listener for the same event 11

MyListener listener = new MyListener (); JButton button = new JButton("Ok"); button.addactionlistener(liste ner); MyListener listener2 = new MyListener (); button.addactionlistener(liste ner2); class MyListener implements ActionListener { public void actionperformed(actioneven t event) { // reaction to button click goes here } } JButton ActionListener 12

} Not restricted to buttons } Examples an item is selected from a list box with a double click a menu item is selected the Enter key is clicked in a text field mluckner@mini.pw.edu.pl 11/30/16 13

} EventObject getsource() } AWTEvent extends EventObject } ActionEvent extends AWTEvent getactioncommand() 14

} Window Listeners } Mouse Listeners } Item Listeners } Property Change Listeners } and more 15

} Opening a window Showing a window for the first time. } Closing a window Removing the window from the screen. } Iconifying a window Reducing the window to an icon on the desktop. } Deiconifying a window Restoring the window to its original size. } Focused window The window which contains the "focus owner". } Activated window (frame or dialog) This window is either the focused window, or owns the focused window. } Deactivated window This window has lost the focus. } Maximizing the window Increasing a window's size to the maximum allowable size. 16

} WindowListener opening and closing the window, activation and deactivation of the window, iconification and deiconification of the window } WindowFocusListener becomes the focus owner loses the focus owner status } WindowStateListener iconified, deiconified, maximized, restored to normal. 17

} MouseListener mousepressed mousereleased mouseentered mouseexited mouseclicked } MouseMotionListener mousemoved mousedragged } MouseWheelListener mousewheelmoved 18

} MouseEvent getclickcount() getbutton() getx() gety() getpoint() } MouseWheelEvent extends MouseEvent getwheelrotation() 19

} Item events are fired by components that implement the ItemSelecable interface. check boxes, check menu items, toggle buttons, combo boxes. } Only one method public void itemstatechanged(itemevent e) 20

} getitem() Returns the item affected by the event. } getstatechange() Returns the type of state change (selected or deselected). } getitemselectable() Returns the originator of the event. 21

public class MyBean { private int value; private PropertyChangeSupport mpcs = new PropertyChangeSupport(this); public int getvalue() { return value;} public void setvalue(int value { mpcs.firepropertychange("value", this.value, value); this.value=value; } public void addpropertychangelistener(propertychangelist ener listener) { mpcs.addpropertychangelistener(listener); } public void removepropertychangelistener(propertychange Listener listener) { mpcs.removepropertychangelistener(listener); } } class MyListener implements PropertyChangeListener { public void propertychanged( PropertyChangeEvent e) } { } //action 22

} Swing's architecture enables multiple L&Fs CrossPlatformLookAndFeel Java build-in SystemLookAndFeel native Synth Defined by XML file 23

24

} BorderLayout } BoxLayout } CardLayout } FlowLayout } GridBagLayout } GridLayout } GroupLayout } SpringLayout 25