際際滷

際際滷Share a Scribd company logo
10 AWT Event ModelHUREE University ICTInstructor: M.J LEE
ContentsEventActions like clicking button with a mouse, pushing down a key on keyboardEvent SourceSources that cause events such as a button, a keyEvent HandlerMethods that get an occurred event, then handle proper actions2
How to handle event?When something happen(event occurs), this method handle the event.3import java.awt.*;public class ButtonTest {	public static void main(String args[]) {	Frame f = new Frame("Button Test");	Button b = new Button(Click!");b.addActionListener(new ButtonHandler());f.add(b);f.pack();f.setVisible(true);	}}
How to handle event?When something happens(a event occurs), this method handle the event.4import java.awt.event.*;public class ButtonHandlerimplements ActionListener{	public void actionPerformed(ActionEvent e) {System.out.println(button pushed!");System.out.println(e.getActionCommand());	}}
Method Categories and Interfaces5
6
ExamplesWe want to close the window when pushing down a close buttonHow to implement? Which method do we have to use?Find out event sourceApply addXXXListener() on the event source, define event handlerImplement event handler7
ExamplesFind out event source  window	What is the interface related with window? WindowListenerMatch the event source with event handlerImplement WindowHandler()8f.addWindowListener(new WindowHandler());
Examples9public class WindowHandlerimplementsWindowListener{	public void windowClosing(WindowEvent e) {System.exit(0); 	}windowOpened(WindowEvent e) { }windowIconified(WindowEvent e) { }windowDeiconified(WindowEvent e) { }windowClosed(WindowEvent e) { }windowActivated(WindowEvent e) { }windowDeactivated(WindowEvent e) { }}
10public class ButtonTest2 implements WindowListener {	private Frame f;	private Button b;	public ButtonTest2(String str) {		f = new Frame(str);f.addWindowListener(this);		b = new Button("Click!!");b.addActionListener(new ButtonHandler());f.add(b, "Center");f.pack();f.setVisible(true);	}	public static void main(String args[]) {		ButtonTest2 fa= new ButtonTest2("Button Test");	}	public void windowClosing(WindowEvent e) {f.setVisible(false); f.dispose(); System.exit(0); 	}	public void windowOpened(WindowEvent e) { }	public void windowIconified(WindowEvent e) { }	public void windowDeiconified(WindowEvent e) { }	public void windowClosed(WindowEvent e) { }	public void windowActivated(WindowEvent e) { }	public void windowDeactivated(WindowEvent e) { }}
11public class ButtonTest extends Frame implements WindowListener {public ButtonTest(String str) {super(str);addWindowListener(this);}public static void main(String args[]) {ButtonTestbt= new ButtonTest("Button Test");Button b = new Button("Click!!");b.addActionListener(new ButtonHandler());bt.add(b, "Center");bt.pack();bt.setVisible(true);}public void windowClosing(WindowEvent e) {setVisible(false); dispose(); System.exit(0); }public void windowOpened(WindowEvent e) { }public void windowIconified(WindowEvent e) { }public void windowDeiconified(WindowEvent e) { }public void windowClosed(WindowEvent e) { }public void windowActivated(WindowEvent e) { }public void windowDeactivated(WindowEvent e) { }}import java.awt.event.*;public class ButtonHandler implements ActionListener{public void actionPerformed(ActionEvent e) {System.out.println("button pushed!");System.out.println(e.getActionCommand());}}
Multiple Listener12We can add multiple event handlers on the one event source
Sensing moving, and being clocked.
MouseMotionListener / MouseListener interfaceDefine a event sourceAdd each event handler on the event sourceImplement two Event Handler
Ad

Recommended

final project for C#
final project for C#
Benjamin Fulker
Voices That Matter: JavaScript Events
Voices That Matter: JavaScript Events
Peter-Paul Koch
Vp lecture 6 ararat
Vp lecture 6 ararat
Saman M. Almufti
Introj Query Pt2
Introj Query Pt2
kshyju
Windows 8 Pure Imagination - 2012-11-25 - Extending Your Game with Windows 8 ...
Windows 8 Pure Imagination - 2012-11-25 - Extending Your Game with Windows 8 ...
Fr辿d辿ric Harper
Production Log
Production Log
FrankieHall0
Wix Automation - It's That Easy!
Wix Automation - It's That Easy!
Efrat Attas
Programming Without Coding Technology (PWCT) - ShellExplorer Sample
Programming Without Coding Technology (PWCT) - ShellExplorer Sample
Mahmoud Samir Fayed
Wikis for everyone
Wikis for everyone
dpmackenzie
Teo Te Wei
Teo Te Wei
cynrx
Rental POS - Microsoft RMS
Rental POS - Microsoft RMS
System Solutions
Total Weather (in progress)
Total Weather (in progress)
West Hollow MS Ms. Gill
Blog 2 eng 102
Blog 2 eng 102
Reanna Midkiff Byrd
Emp
Emp
ahfai7
The Emp Destroyer
The Emp Destroyer
Leeward Community College, Pearl City HI
Television broadcasting page 6
Television broadcasting page 6
arthur2031
Event Handling in java
Event Handling in java
Google
event-handling.pptx
event-handling.pptx
Good657694
Md11 gui event handling
Md11 gui event handling
Rakesh Madugula
What is Event
What is Event
Asmita Prasad
EventHandling in object oriented programming
EventHandling in object oriented programming
Parameshwar Maddela
Chapter 8 event Handling.ppt m m m m m m
Chapter 8 event Handling.ppt m m m m m m
zmulani8
Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024
nehakumari0xf
Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024
kashyapneha2809
Java eventhandling
Java eventhandling
Arati Gadgil
Event handling
Event handling
swapnac12
09events
09events
Waheed Warraich
Java gui event
Java gui event
SoftNutx
PPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKD
PPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKD
chessvashisth
Chapter 11.5
Chapter 11.5
sotlsoc

More Related Content

Viewers also liked (8)

Wikis for everyone
Wikis for everyone
dpmackenzie
Teo Te Wei
Teo Te Wei
cynrx
Rental POS - Microsoft RMS
Rental POS - Microsoft RMS
System Solutions
Total Weather (in progress)
Total Weather (in progress)
West Hollow MS Ms. Gill
Blog 2 eng 102
Blog 2 eng 102
Reanna Midkiff Byrd
Emp
Emp
ahfai7
The Emp Destroyer
The Emp Destroyer
Leeward Community College, Pearl City HI
Television broadcasting page 6
Television broadcasting page 6
arthur2031

Similar to 10 awt event model (20)

Event Handling in java
Event Handling in java
Google
event-handling.pptx
event-handling.pptx
Good657694
Md11 gui event handling
Md11 gui event handling
Rakesh Madugula
What is Event
What is Event
Asmita Prasad
EventHandling in object oriented programming
EventHandling in object oriented programming
Parameshwar Maddela
Chapter 8 event Handling.ppt m m m m m m
Chapter 8 event Handling.ppt m m m m m m
zmulani8
Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024
nehakumari0xf
Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024
kashyapneha2809
Java eventhandling
Java eventhandling
Arati Gadgil
Event handling
Event handling
swapnac12
09events
09events
Waheed Warraich
Java gui event
Java gui event
SoftNutx
PPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKD
PPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKD
chessvashisth
Chapter 11.5
Chapter 11.5
sotlsoc
Advance java for bscit
Advance java for bscit
YogeshDhamke2
Event Handling in JAVA
Event Handling in JAVA
Srajan Shukla
JEDI 際際滷s-Intro2-Chapter20-GUI Event Handling.pdf
JEDI 際際滷s-Intro2-Chapter20-GUI Event Handling.pdf
MarlouFelixIIICunana
JAVA AWT
JAVA AWT
shanmuga rajan
event handling new.ppt
event handling new.ppt
usama537223
EVENT DRIVEN PROGRAMMING SWING APPLET AWT
EVENT DRIVEN PROGRAMMING SWING APPLET AWT
mohanrajm63
Event Handling in java
Event Handling in java
Google
event-handling.pptx
event-handling.pptx
Good657694
Md11 gui event handling
Md11 gui event handling
Rakesh Madugula
EventHandling in object oriented programming
EventHandling in object oriented programming
Parameshwar Maddela
Chapter 8 event Handling.ppt m m m m m m
Chapter 8 event Handling.ppt m m m m m m
zmulani8
Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024
nehakumari0xf
Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024
kashyapneha2809
Java eventhandling
Java eventhandling
Arati Gadgil
Event handling
Event handling
swapnac12
Java gui event
Java gui event
SoftNutx
PPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKD
PPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKD
chessvashisth
Chapter 11.5
Chapter 11.5
sotlsoc
Advance java for bscit
Advance java for bscit
YogeshDhamke2
Event Handling in JAVA
Event Handling in JAVA
Srajan Shukla
JEDI 際際滷s-Intro2-Chapter20-GUI Event Handling.pdf
JEDI 際際滷s-Intro2-Chapter20-GUI Event Handling.pdf
MarlouFelixIIICunana
event handling new.ppt
event handling new.ppt
usama537223
EVENT DRIVEN PROGRAMMING SWING APPLET AWT
EVENT DRIVEN PROGRAMMING SWING APPLET AWT
mohanrajm63
Ad

Recently uploaded (20)

9-1-1 Addressing: End-to-End Automation Using FME
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
Key Requirements to Successfully Implement Generative AI in Edge DevicesOpt...
Key Requirements to Successfully Implement Generative AI in Edge DevicesOpt...
Edge AI and Vision Alliance
June Patch Tuesday
June Patch Tuesday
Ivanti
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
Turning the Page How AI is Exponentially Increasing Speed, Accuracy, and Ef...
Turning the Page How AI is Exponentially Increasing Speed, Accuracy, and Ef...
Impelsys Inc.
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
9-1-1 Addressing: End-to-End Automation Using FME
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
Key Requirements to Successfully Implement Generative AI in Edge DevicesOpt...
Key Requirements to Successfully Implement Generative AI in Edge DevicesOpt...
Edge AI and Vision Alliance
June Patch Tuesday
June Patch Tuesday
Ivanti
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
Turning the Page How AI is Exponentially Increasing Speed, Accuracy, and Ef...
Turning the Page How AI is Exponentially Increasing Speed, Accuracy, and Ef...
Impelsys Inc.
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
Ad

10 awt event model

  • 1. 10 AWT Event ModelHUREE University ICTInstructor: M.J LEE
  • 2. ContentsEventActions like clicking button with a mouse, pushing down a key on keyboardEvent SourceSources that cause events such as a button, a keyEvent HandlerMethods that get an occurred event, then handle proper actions2
  • 3. How to handle event?When something happen(event occurs), this method handle the event.3import java.awt.*;public class ButtonTest { public static void main(String args[]) { Frame f = new Frame("Button Test"); Button b = new Button(Click!");b.addActionListener(new ButtonHandler());f.add(b);f.pack();f.setVisible(true); }}
  • 4. How to handle event?When something happens(a event occurs), this method handle the event.4import java.awt.event.*;public class ButtonHandlerimplements ActionListener{ public void actionPerformed(ActionEvent e) {System.out.println(button pushed!");System.out.println(e.getActionCommand()); }}
  • 6. 6
  • 7. ExamplesWe want to close the window when pushing down a close buttonHow to implement? Which method do we have to use?Find out event sourceApply addXXXListener() on the event source, define event handlerImplement event handler7
  • 8. ExamplesFind out event source window What is the interface related with window? WindowListenerMatch the event source with event handlerImplement WindowHandler()8f.addWindowListener(new WindowHandler());
  • 9. Examples9public class WindowHandlerimplementsWindowListener{ public void windowClosing(WindowEvent e) {System.exit(0); }windowOpened(WindowEvent e) { }windowIconified(WindowEvent e) { }windowDeiconified(WindowEvent e) { }windowClosed(WindowEvent e) { }windowActivated(WindowEvent e) { }windowDeactivated(WindowEvent e) { }}
  • 10. 10public class ButtonTest2 implements WindowListener { private Frame f; private Button b; public ButtonTest2(String str) { f = new Frame(str);f.addWindowListener(this); b = new Button("Click!!");b.addActionListener(new ButtonHandler());f.add(b, "Center");f.pack();f.setVisible(true); } public static void main(String args[]) { ButtonTest2 fa= new ButtonTest2("Button Test"); } public void windowClosing(WindowEvent e) {f.setVisible(false); f.dispose(); System.exit(0); } public void windowOpened(WindowEvent e) { } public void windowIconified(WindowEvent e) { } public void windowDeiconified(WindowEvent e) { } public void windowClosed(WindowEvent e) { } public void windowActivated(WindowEvent e) { } public void windowDeactivated(WindowEvent e) { }}
  • 11. 11public class ButtonTest extends Frame implements WindowListener {public ButtonTest(String str) {super(str);addWindowListener(this);}public static void main(String args[]) {ButtonTestbt= new ButtonTest("Button Test");Button b = new Button("Click!!");b.addActionListener(new ButtonHandler());bt.add(b, "Center");bt.pack();bt.setVisible(true);}public void windowClosing(WindowEvent e) {setVisible(false); dispose(); System.exit(0); }public void windowOpened(WindowEvent e) { }public void windowIconified(WindowEvent e) { }public void windowDeiconified(WindowEvent e) { }public void windowClosed(WindowEvent e) { }public void windowActivated(WindowEvent e) { }public void windowDeactivated(WindowEvent e) { }}import java.awt.event.*;public class ButtonHandler implements ActionListener{public void actionPerformed(ActionEvent e) {System.out.println("button pushed!");System.out.println(e.getActionCommand());}}
  • 12. Multiple Listener12We can add multiple event handlers on the one event source
  • 13. Sensing moving, and being clocked.
  • 14. MouseMotionListener / MouseListener interfaceDefine a event sourceAdd each event handler on the event sourceImplement two Event Handler
  • 15. public class TwoListen implements MouseMotionListener, MouseListener { private Frame f; private TextFieldtf;public static void main(String args[]) { TwoListen two = new TwoListen(); two.go(); } public void go() { f = new Frame("Two listeners example"); f.add (new Label ("Click and drag the mouse"), BorderLayout.NORTH); tf = new TextField (30);f.add (tf, BorderLayout.SOUTH);f.addMouseMotionListener(this);f.addMouseListener (this);f.setSize(300, 200);f.setVisible(true); }... ...1Event sourceAdd listeners2
  • 16. ... ...public void mouseDragged (MouseEvent e) { String s = "Mouse dragging: X=+e.getX()+" Y=+ e.getY(); tf.setText (s); } public void mouseEntered (MouseEvent e) { String s = "The mouse entered"; tf.setText (s);} public void mouseExited (MouseEvent e) { String s = "The mouse has left the building"; tf.setText (s); } public void mouseMoved (MouseEvent e) { }public void mousePressed (MouseEvent e) { }public void mouseClicked (MouseEvent e) { }public void mouseReleased (MouseEvent e) { } } Implement all abstract methods in Listeners3