CSI 3125, Preliminaries, page 1 Adapter Class. CSI 3125, Preliminaries, page 2 Adapter Class Java provides a special feature, called an adapter class,

Slides:



Advertisements
Similar presentations
CSE 341, S. Tanimoto Java-PolyDraw- 1 A Java Case Study: An Applet for Drawing Polygons Motivation -- See a number of AWT features integrated. Get ideas.
Advertisements

Managing Input Events in Swing Week 5 Workshop Lyn Bartram.
Liang,Introduction to Java Programming,revised by Dai-kaiyu 1 Chapter 12 Event-Driven Programming 找出画中真谛 — 保罗. 塞尚.
Computer Science 209 Graphics and GUIs. Working with Color The class java.awt.Color includes constants for typical color values and also supports the.
Event Handling Feb 14, Event Model Revisited zRecall that a component can fire an event. zEach type of event is defined as a distinct class. zAn.
Inner Classes in Java CMSC 432 Shon Vick. 2 Conceptual Structure package p 1 class A 1 class A 2... class A n... package n class A 1 class A 2... class.
Jan Event Handling -1.1 Yangjun Chen Dept. Business Computing University of Winnipeg.
Events CSC 171 FALL 2001 LECTURE 9. History: the ABC John Vincent Atanasoff, with John Berry, developed the machine we now call the ABC -- the.
Mouse Events and Keyboard Events
Event Handling Events and Listeners Timers and Animation.
For IST410 Students only Events-1 Event Handling.
Unit 111 Event-Driven Programming Listener or Event handler Example: Handling Button Events Example: Handling Mouse Events Example: Handling Keyboard Events.
Event-Driven Programming
OOP Java1 Event Handling Overview Listeners, Adapters and Event Sources Inner classes Event Handling Details Applets and GUI Applications Event.
1 Gui Programming (Part I) Graphical User Interfaces (Part I) l Introduction to events. l A Brief history. l Event sources and listeners. l The delegation.
Intermediate Java1 An example that uses inner classes Week Four Continued.
1 lecture 12Lecture 13 Event Handling (cont.) Overview  Handling Window Events.  Event Adapters Revisited.  Introduction to Components and Containers.
Mouse Events. Handling Mouse Events Java provides two listener interfaces to handle mouse events: MouseListener;  MouseListener;  MouseMotionListener.
Cs884(Prasad)java12AWT1 Abstract Windowing Toolkit Support for Graphical User Interface (Event-driven programming)
Applets Session 8. Java Simplified / Session 8 / 2 of 31 Review The Abstract Windowing Toolkit (AWT) is a set of classes that allow us to create a graphical.
Java GUI’s are event driven, meaning they generate events when the user interacts with the program. Typical events are moving the mouse, clicking a mouse.
SD2071 Games Programming Abstraction, inheritance and interfaces Exceptions Two dimensional arrays Java collections framework Files Aaron Kans.
OOP (Java): GUI II/ OOP Objectives – –describe some more GUI features: JPanel, and mouse listeners/adapters Semester 2,
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
The Drawing program – Java Applets
Graphics in Java CS 21b. The paint() Method Method in a visual component that specifies what that component looks like Particularly important for applets,
Lec 16 Adding Mouse and KeyEvent handlers to an Applet Class.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
Java Applet Basics (2). The Body Mass Index Calculator.
Universidad Nacional de Colombia Facultad de Ingeniería Departamento de Sistemas ertificación en AVA.
Week 6: Basic GUI Programming Concepts in Java Example: JFrameDemo.java container : a screen window/applet window/panel that groups and arranges components.
© Marty Hall, Larry Brown Web core programming 1 Handling Mouse and Keyboard Events.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Index Event Handling Events Event Source Event Listener Event Classes Action Event Class Adjustment event Class Event Source Event Listener Interface Using.
©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 10: Event Handling 1 Event Handling.
GUI DYNAMICS Lecture 11 CS2110 – Fall GUI Statics and GUI Dynamics  Statics: what’s drawn on the screen  Components buttons, labels, lists, sliders,
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 10: Event Handling 1 Chapter 10 Event Handling.
Mouse Listeners Moving the mouse will also generate events like the Timer –To have your program respond, you must implement either or both of MouseListener.
Chapter 2 Creating a Java Application and Applet.
Events in JAVA Needed for Applets and GUI based programs. Applet uses GUI to interact with user. Most of the events are generated by Mouse, Keyboard.
CSI 3125, Preliminaries, page 1 AWT Control. CSI 3125, Preliminaries, page 2 AWT Control The AWT supports the following types of controls: ■ Labels ■
CSI 3125, Preliminaries, page 1 AWT. CSI 3125, Preliminaries, page 2 AWT Java AWT (Abstract Windowing Toolkit) is an API to develop GUI or window-based.
CSI 3125, Preliminaries, page 1 Applet. CSI 3125, Preliminaries, page 2 Applet An applet is a Java program that runs in a Web browser. An applet can be.
Events (Chapter 11) Java Certification Study Group January 25, 1999 Mark Roth.
1 Event Handling – Lecture 4 Prepared by: Ahmad Ramin Rahimee Assistant Professor ICTI.
Laboratory Study November, Demonstrates Life Cycle of an Applet + Mouse Events + Scrolling.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 10.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Chapter 6: Events in Java 1.0 Model –Event class –selecting component to handle –handleEvent method –helper methods (action, keyUp, mouseUp, etc.) 1.1.
2/17/2016 DEPT OF CSE 1 EVENT HANDLING. 2/17/2016 DEPT OF CSE 2 Event handling is at the core of successful applet programming There are several types.
What Is an Event? Events – Objects that describe what happened Event sources – The generator of an event Event handlers – A method that receives an event.
CSI 3125, Preliminaries, page 1 Event Handling. CSI 3125, Preliminaries, page 2 Event Handling An Event Change in the state of an object is known as event.
Lesson 33: Layout management and drawing – Java GUI.
Output Programs These slides will present a variety of small programs. Most of the programs deal with DecimalFormat objects or Polygon objects. Our concern.
Prepared by: Dr. Abdallah Mohamed, AOU-KW Unit7: Event-driven programming 1.
EVENT HANDLING 10/8/2017.
Events and Event Handling
Java Applets.
Lecture 8 Object Oriented Programming Using Java
Programming in Java, 2e Sachin Malhotra Saurabh Choudhary.
Programming in Java Sachin Malhotra, Chairperson, PGDM-IT, IMS Ghaziabad Saurabh Chaudhary, Dean, Academics, IMS Ghaziabad.
Event Handling Chapter 2 Objectives
Computer Science 209 Graphics and GUIs.
CSE Software Engineering Fall 1999 Updated by J. Brown
GUI Programming using Java - Mouse Events
Java Applets.
Web Design & Development Lecture 12
Web Design & Development Lecture 13
Presentation transcript:

CSI 3125, Preliminaries, page 1 Adapter Class

CSI 3125, Preliminaries, page 2 Adapter Class Java provides a special feature, called an adapter class, that can simplify the creation of event. An adapter class provides an empty implementation of all methods in an event listener interface. Adapter classes are useful when want to receive and process only some of the events that are handled by a particular event listener interface. By extending one of the adapter classes and implementing only those events in which you are interested.

CSI 3125, Preliminaries, page 3 Adapter Class For example, the MouseMotionAdapter class has two methods, mouseDragged( ) and mouseMoved( ). If you were interested in only mouse drag events, then simply extend MouseMotionAdapter and implement mouseDragged( ). commonly used adapter classes in java.awt.event

CSI 3125, Preliminaries, page 4 Adapter Class Listener InterfaceAdapter Class ComponentListenerComponentAdapter ContainerListenerContainerAdapter FocousListenerFocousAdapter KeyListenerKeyAdapter MouseListenerMouseAdapter MouseMotionListenerMouseMotionAdapter WindowListenerWindowAdapter

CSI 3125, Preliminaries, page 5 MouseAdapter Class prog import java.applet.*; import java.awt.event.*; /* */ public class M3 extends Applet { MyMouseAdapter k=new MyMouseAdapter(); public void init() { addMouseListener(k); } class MyMouseAdapter extends MouseAdapter { public void mousePressed(MouseEvent me) { showStatus("Mouse Pressed”); }

CSI 3125, Preliminaries, page 6 MouseAdapter Class prog (Inner Class) import java.applet.*; import java.awt.event.*; /* */ public class M3 extends Applet { public void init() { addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent me) { showStatus("Mouse Pressed”); } } ); }

CSI 3125, Preliminaries, page 7 MouseAdapter Class to draw rect Prog (Inner Class) import java.applet.*; import java.awt.*; import java.awt.event.*; /* */ public class M3 extends Applet { int X1,Y1,X2,Y2; public void init() { addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent me) { X1 = me.getX(); Y1 = me.getY(); } public void mouseReleased(MouseEvent me) { X2=me.getX();Y2=me.getY(); repaint(); } }); } public void paint(Graphics g) {g.drawRect(X1, Y1, X2-X1, Y2-Y1); } }

CSI 3125, Preliminaries, page 8 WindowAdapter Class (Inner class) Prog public class w1 extends java.awt.Frame { public w1() { addWindowListener( new java.awt.event.WindowAdapter() { public void windowClosing( java.awt.event.WindowEvent e ) { System.out.println( "good bye" ); } ); } public static void main( String[] args ) { w1 foo = new w1() ; foo.setSize( 200, 200 ); foo.setVisible( true ); }

CSI 3125, Preliminaries, page 9 Adapter Class

CSI 3125, Preliminaries, page 10 Adapter Class