Chap 7

  • December 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Chap 7 as PDF for free.

More details

  • Words: 2,068
  • Pages: 18


 % '0''&/'@'22o'    "78/4'9"+ "%8 :;"1'(<""='@AL%1'(C%$"!:(<1(0 -7B/.,51'(1,+4D31'(E 1('JJƒ19"!:(<1(0 ~YO !5$.(A0B D2".'11'(<""='"A$'0@'040'$C/64D31'(E <""='#'&:(>  Event %B 1%B$@C2/61,+4D31'(E1('JJƒ1DH'6F <""='/A"D/(EJ& :(>  Listener %B9I29"1'((,+J]64D31'(E  /LA+'$@AL%1'(.,51'(1,+4D31'(E 1('JJƒ14#'$F4D31'(E<#D/" 2'$C/6+ :;"1'(<""='#'&:(> }NV 

% &/'@  4D31'(E } :;"&*'"1'(E %B1A5CS8"9"C(,"!:(<1(0 /' A IH" 1'(9I2 /A"-3D 0'&E4(7/%$E+/(E5 DA5DH/1,+!:(<1(0 ~YO 1'(1A54D31'(E9"!:(<1(0>'?' .'@'.:;"1'(&(2'6//:.KC/6#'&:(>  Event I"A5DH'6FCS8"0'D'0:(> C/6 4D31'(E/' A IH" - 07B/#7B/"0'&E9"J(0.1A5//:.KC/6#'&MouseEventCS8"0' - 07B/:ƒ5J(0.1A5//:.KC/6#'&WindowEventCS8"0' - 07B/15:30™ %B/$MH9"J(0.1A5//:.KC/6#'&ActionEventCS8"0' - 07B/-A0-EC2/@'09" TextField .1A5//:.KC/6#'& KeyEvent CS8"0'  #'&:(>  Event.&7+ /50'.'1#'& ObjectEvent&H@"#'&:(>  Event &='4(,+4D31'(E '61('JJƒ1.&7+ /50'.'1#'& AWTEvent %B &7+ /50'.'1#'& ObjectEvent /%1DH/4"SB6 RSB6#'&:(>  Event &='4(,+ 4D31'(E '61('JJƒ1 ,86405./$M9H "<-1K. java.awt.event !5$&'0'(*<&56 #='5,+I,8"C/61'(&7+ /5G5256, <&569"(M: %BvQP    

    

    







  3! #='5,+I,8"1'(&7+ /5C/6#'&:(> Event 

!5$ @,B G:/6E:(1/+C/64D31'(E.0%&'0&H@"5,6<&569"(M: %BvQ7/ PQ <-871 7///:.K:(>  Event D'0I"A5C/64D31'(E %B1A5CS8"IH" //:.KC/6#'&WindowEvent Q <-871>=20587///:.K %B ='9421A54D31'(EIH"//:.KC/6#'&Frame %B:;"&H@" %B ='9421A54D31'(E1'(:ƒ5J(0 cQ <-871 q,7J380  7///:.K .%B  ='4"2' .%B ,51'(1,+4D31'(E %B1A5CS8" !5$0% 0L/5 .%B (,+//:.K:(>  Event %B1A5CS8"<#0%='&,6B 9"1'(.,51'(1,+ 4D31'(E-7B/!D2D/+1,+WM29I2

 



  3!$ /6E:(1/+C/64D31'(E

% ;qr]:ZUd 

#'& AWTEvent :;"   X C/6#'&:(>  Event &='4(,+4D31'(E ActionEvent, '652'"1('JJƒ1RSB6.0%/$MH 6,8 405 PP #'&7/

AdjustmentEvent, ComponentEvent, ItemEvent, TextEvent, FocusEvent, WindowEvent, InputEvent, ContainerEvent, 8 1#H'@*S60L/5C/6 KeyEvent <# MouseEvent 5,6<&569"(M: %B vQP "78/4'9"+ "%.

B&% =',n H'",8" RSB6#'& ObjectEvent0%0L/5 %B&=',n5,6"%8

#'&:(> 

 

AWTEvent

AWTEvent

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

<##'&

 x

Object getSource()

:;"0L/59"#'& \ X x

ObjectEvent

-7B/(%$15M//:.K:(>  }

int geID()

:;"0L/59"#'& AWTEvent %B&6H H'.='"@"DK0-7B/(+3I"A5C/64D31'(E 0L/5"%80%:(!$I"E&='4(,+4D31'(EC/6#'& MouseEvent RSB60%4D31'(E G524#'$I"A5 !5$0%H'.='"@"DK0(+3I"A5C/64D31'(E /' A IH" MOUSE_CLICKED 4(7/MOUSE_DRAGGED:;"D2" 

%

ActionEvent

 //:.KC/6#'& !:(<1(0~YO5,6"%8

ActionEvent

.*M1&(2'6CS8"9"1(% 0%B %4D31'(E1A5CS8"9"

x 07B/0%1'(#A10'&E+":30™ //:.KC/6#'&Button x 07B/0%1'(:„/"%$E} 9"TextField x 07B/0%1'(#7/1('$1'(9"0"MC/6MenuItem x 07B/0%1'(155,++A#8 #A1bJ=2f3853/5we 9"List #'&ActionEvent0%0L/5 %B1%B$@C2/65,6"%8 x

String getActionCommand()

,86"%8='&,B6C/6 :;"0L/5 .%B &H6I7B/='&,B6 %B 1A5CS8".'1 ActionEvent ActionEvent .1='4"5CS8"!5$//:.KC/6 } \ X 9"1(% %B:;" //:.KC/6#'& Button 4(7/ MenuItem 1K.7/C2/@'0 d %B :('1Z+":3™04(7/0"M  "/1.'1"%8('&'0'(* %B.1='4"5I7B/='&,B6C/6//:.K C/6#'& Button4(7/ MenuItem942
int getModifiers()

:;"0L/5 .%B &H6&*'"C/6%$E kV %$EN`  `k<#\ %B1A5 .'1//:.KC/6#'&ActionEvent0L/5"%8.&H6I"A5C2/0M#<++int %B0% H'6 %B7"0'7/ ALT_MASK, CTRL_MASK, META_MASK <# SHIFT_MASK

    

    





%

WindowEvent

 //:.KC/6#'& WindowEvent .*M1&(2'6CS8"9"1(% 0%B %4D31'(E1A5CS8":;" //:.KC/6#'&:(> Window!5$0%4D31'(E %B1A5CS8"G525,6"%8 x V:;"4D31'(E %B 1A5CS"8 07B/0%1'(:ƒ5Window x XV:;"4D31'(E %B 1A5CS8"07B/0%1'(:ƒ5Window x X:;"4D31'(E %B 1A5CS8"C1='#,6:ƒ5Window x XV:;"4D31'(E07B///:.KC/6#'&Window/$MH9"(M:C/6G//" x J8/5=7/?/8J  :;"4D31'(E07B///:.KC/6#'& Window G0HG52/$M9H "(M:C/6 G//" x XV:;"4D31'(E %B1A5CS8"07B/Window1='#,6 ='6'"/$MH x VXV:;"4D31'(E %B 1A5CS8"07B/WindowG0HG52 ='6'"/$MH #'&WindowEvent0%0L/5 %B&'= ,n7/ x

Object getWindow()

:;"0L/5 &%B H6//:.KC/6#'&:(>  Window %B :;" <-871 >=2058 7" 0'

%"

MouseEvent

 //:.KC/6#'& MouseEvent .*M1&(2'6CS8"9"1(% %B0%1'(9I26'"0'&E-7B/ DA5DH/1,+WM92 I2!5$0%4D31'(E B% 1A5CS8"G525,6"%8 x V V  :;"4D31'(E %B 1A5CS8"07B/0%1'(#7B/"0'&E<#2@15:30™ C/60'&E-(2/0 1," x V:;"4D31'(E %B1A5CS8"07B/0%1'(#7B/"0'&E x XXwV:;"4D31'(E %B1A5CS8"07B/0%1'(#A10'&E x  V  :;"4D31'(E %B 1A5CS8"07B/0%1'(#7B/"0'&EC2'G:9"C/+CDC/6 //:.KC/6#'& %B :;"&H@":(1/+1('JJƒ195F x bV  :;"4D31'(E %B 1A5CS8"07B/D='<4"H6C/60'&E/$M"H /1C/+CDC/6 //:.KC/6#'& %B :;"&H@":(1/+1('JJƒ195F x  V:;"4D31'(E %B 1A5CS"8 07B/0%1'(15:30™ +"0'&E  

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 x V:;"4D31'(E %B 1A5CS8"07B/0%1'(:#H/$:3™0 %B15+"0'&E #'&MouseEvent0%0L/5 %B&=',n7/ x

int getX()

:;"0L/5 .%B &H6D='<4"H6-A1,5C/60'&E+"<1" x %B0%I"A5C2/0M#:;" int7" 0' x

int getY()

:;"0L/5 .%B &H6D='<4"H6-A1,5C/60'&E+"<1" y %B0I% "A5C2/0M#:;" int7" 0' x

Point getPoint()

:;"0L/5 .%B &H6D='<4"H6-A1,5 (x,y) C/60'&E7"0' !5$0%I"A5C2/0M#:;" //:.KC/6#'&Point x

int getClickCount()

:;"0L/5 .%B &H6.='"@"(,86C/61'(#A10'&E7"0'

%&

ItemEvent

 //:.KC/6#'& !:(<1(0~YO5,6"%8

ItemEvent

.*M1&(2'6CS8"9"1(% 0%B %4D31'(E1A5CS8"9"

x 07B/0%1'(#7/14(7/$1#A1('$1'(9"List4(7/Checkbox x 07B/0%1'(#A10'&E9"('$1'(9"Choice #'&ItemEvent0%0L/5 &%B =',n5,6"%8 x

ItemSelectable getItemSelectable()

:;"0L/5 .%B &H6//:.KC/6#'&:(>  }\ X7"0' x

ItemSelectable

%B:;"

Object getItem()

:;"0L/5 .%B &H6//:.KC/6('$1'( %B*M1#7/17"0' x

int getStateChange()

:;"0L/5 .%B &H6H'6 %BI"A5 int %B0%H':;" SELECTED DESELECTED-7B/(+3&*'"1'(E#7/1C/6('$1'(7"0'

    

4(7/

    





%- M?JIC C <-1K.java.awt.event$,60%#'& %B :;"4D31'(E '652'"1('JJƒ1/7B"F5,6"%8 x

KeyEvent:;"#'&

x

FocusEvent:;"#'&

x

%B0%1'(&(2'6//:.K07B/0%4D31'(E1'(15%$E+/(E5

B0% %1'(&(2'6//:.K07B/WM29I2#7B/"/3:1(E/A"-3D0'I%8 $,6//:.KC/6&H@":(1/+1('JJƒ195F ComponentEvent

:;"#'& 0%B %1'(&(2'6//:.K07/B 0%4D31'(ERSB6 //:.KC/6&H@":(1/+1('JJƒ10%1'(:#%B$"<:#6IH" #7B/" %B4(7/:(,+ C"'5

x

ContainerEvent  :;"#'&

0%B %1'(&(2'6//:.K07B/0%4D31'(E9"1'(9&H 4(7/$1#A1//:.KC/6&H@":(1/+1('JJƒ1 #69"//:.KC/6#'&:(>  Container x AdjustmentEvent :;"#'& %B0%1'(&(2'6//:.K07B/0%4D31'(E9"1'( :(,+D='<4"H6I%8C/6//:.KC/6#'&ScrollBar4(7/ScrollPane x

TextEvent

 :;"#'& %B0%1'(&(2'6//:.K07B/0%4D31'(E9"1'( :#%B$"<:#6C2/@'09"//:.KC/6#'&TextArea

%" 2Listener  >'?'.'@'..,51'(1,+4D31'(E !5$1'(&(2'6//:.K %B&'0'(*(,+J]64D31'(E .'1#'& %Bimplements/A"D/(EJ&:(> Listener %B&/5#2/61,"RSB6//:.K"%8. ='4"2' %B:;" <-871 q,7J380 /' AIH" //:.K .%B .,51'(1,+4D31'(E:(>  ActionEvent .D2/6 implements /A"D/(EJ& ActionListener !5$D2/6C%$" +#K/1='&,B69"0L/5 actionPerformed() /A"D/(EJ&:(>  Listener 0% ,86405PPI"A5RSB6&/5#2/61,+#'&:(> Event5,6"%8

 

x

ActionListener ActionEvent

x

AdjustmentListener AdjustmentEvent

x

ComponentListener ComponentEvent

:;"/A"D/(EJ&&='4(,+//:.KC/6#'& :;"/A"D/(EJ&&='4(,+//:.KC/6#'& :;"/A"D/(EJ&&='4(,+//:.KC/6#'&

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 x

ContainerListener ContainerEvent

x

FocusListener FocusEvent

x

ItemListener

x

KeyListener

x

MouseListener MouseEvent

x

MouseMotionListener MouseEvent

x

TextListener

x

WindowListener WindowEvent

:;"/A"D/(EJ&&='4(,+//:.KC/6#'& :;"/A"D/(EJ&&='4(,+//:.KC/6#'&

:;"/A"D/(EJ&&='4(,+//:.KC/6#'& :;"/A"D/(EJ&&='4(,+//:.KC/6#'&

ItemEvent KeyEvent

:;"/A"D/(EJ&&='4(,+//:.KC/6#'& :;"/A"D/(EJ&&='4(,+//:.KC/6#'&

:;"/A"D/(EJ&&='4(,+//:.KC/6#'&

TextEvent

:;"/A"D/(EJ&&='4(,+//:.KC/6#'&

//:.K95F D%B 2/61'(.,51'(1,+4D31'(E.D2/6#6 +%$"    (,+J]6 4D31'(E",8"52@$!5$D2/69I20L/5 %B&/5#2/61,"5,6<&569"D'('6 %B vQP &H@"/A"D/(EJ& :(>  Listener
 G0 D)2y&/'@

ActionListener

addActionListener()

ItemListener

addItemListener()

KeyListener

addKeyListener()

MouseListener

addMouseListener()

MouseMotionListener

addMouseMotionListener()

TextListener

addTextListener()

FocusListener

addFocusListener()

AdjustmentListener

addAdjustmentListener()

ComponentListener

addComponentListener()

ContainerListener

addContainerListener()

WindowListener

addWindowListener()

    

    





 3!$0L/5 %BD2/6implementsLU '  GL &Event 2 ActionListener ItemListener MouseMotionListener

MouseListener

KeyListener

FocusListener AdjustmentListener

ComponentListener

WindowListener

ContainerListener TextListener

 G0 implements actionPerformed(ActionEvent) itemStateChanged(ItemEvent) mouseDragged(MouseEvent) mouseMoved(MouseEvent) mouseClicked(MouseEvent) mouseEntered(MouseEvent) mouseExited(MouseEvent) mousePressed(MouseEvent) mouseReleased(MouseEvent) keyPressed(KeyEvent) keyReleased(KeyEvent) keyTyped(KeyEvent) focusGained(FocusEvent) focusLost(FocusEvent) adjustmentValueChanged (AdjustmentEvent) componentMoved(ComponentEvent) componentHidden(ComponentEvent) componentResized(ComponentEvent) componentShown(ComponentEvent) windowOpened(WindowEvent) windowClosed(WindowEvent) windowClosing(WindowEvent) windowIconified(WindowEvent) windowDeiconified(WindowEvent) windowActivated(WindowEvent) windowDeactivated(WindowEvent) componentAdded(ContainerEvent) componentRemoved(ContainerEvent) textValueChanged(TextEvent)

%& '0''&/'@  >'?'.'@'.0%@AL%1'(.,51'(1,+4D31'(E %B (%$1@H'  kV !5$.0% 4#,11'(5,6"%8  

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 x //:.KC/6&H@":(1/+1('JJƒ195F&'0'(*:;"//:.K:(>  <-871 >=2058G52 /' AIH"//:.KC/6#'& Button&'0'(*:;"<-871>=2058 C/6ActionEvent G52 x #'&95F&'0'(*(,+J]64D31'(E95F1KG52 *2'#'&",8" implements /A"D/(EJ&:(>  Listener %B&/5#2/61,"/' A IH" #'& %BD2/61'((,+ J]64D31'(E ActionEvent .D2/6 implements /A"D/(EJ& I%B 7B/ ActionListener x //:.K:(>  Event %B1A5.'1<-871>=2058.*M1&H6G:$,6//:.KC/6 #'& &%B '0'(*(,+J]64D31'(E:(> ",8"  .'14#,11'(C2'6D2" !:(<1(0>'?'.'@'.0%@AL%1'(C%$"='&,B6-7B/.,51'(1,+ 4D31'(EDH'6F5,6"%8  <-871 >=2058 95D2/61'( %B..,51'(1,+4D31'(E95D2/6#6 +%$"-7B/(,+J]6 4D31'(E!5$0%(M:<++5,6"%8   eventSource.addXxxListener(listener)  !5$ %B x x

eventSource

:;"I7B/C/6//:.K %B:;"<-871>=2058

:;"0L/5 9%B I29"1'(#6 +%$"(,+J]64D31'(E!5$ .D2/6#7/19I20L/5 &%B /5#2/61,"9"1'((,+J]64D31'(E
ActionEvent

x

:;"//:.KC/6#'& Xxxlistener RSB6&'0'(*(,+J]6 4D31'(E %BD2/61'(.,51'(G52<# ='4"2' %B :;"<-871q,7J380

listener

 :;"#'& %B implements /A"D/(EJ&:(>  Listener %B&/5#2/61,"  1'(C%$"!:(<1(0-7B/.,51'(1,+4D31'(E&'0'(* %B C%$"#'& %B :;" <-871 q,7J380G524#'$(M:<++5,6"%8 x

XxxListener

x 1='4"5#'&>'$"/1#'& 9%B I29"1'(.,51'(4D31'(E x 1='4"5#'& %B :;"#'&>'$9"/$MH9"#'& %B9I29"1'(.,51'(4D31'(E

    

    





x 1='4"5942#'& 9%B I29"1'(.,51'(4D31'(E implements /A"D/(EJ& :(>  Listener %B&/5#2/61," <#&(2'6//:.KC/6#'&5,61#H'@ >'$9"#'&/6 x 1='4"5#'&>'$9"0L/5#'&:(> ,7=7];=2K

%& '*  #+'  !:(<1(0 %B vQP <&56D,@/$H'61'(.,51'(1,+4D31'(E %B 1A5.'11'(15:3™0 !5$ 1='4"5#'& ActionHandler 942:;"#'&:(>  <-871 q,7J380 RSB6#'&"%8./$MH >'$"/1#'& EventDemo1 RSB6:;"#'& %B9I29"1'(.,51'(1,+4D31'(E1'(15:30™ #'& EventDemo1 .0%//:.KC/6#'& Button %BI7B/ bn1 //:.K bn1 G52#6 +%$" (,+J]64D31'(EActionEvent !5$9I2='&,B6 bn1.addActionListener(new ActionHandler())

!5$ %B='&,B6

:;"1'(&(2'6//:.KC/6#'& ActionHandler %B. ='4"2' %B:;" <-871 q,7J380 5,6",8"#'& ActionHandler .D2/6 implements /A"D/(EJ& ActionListener !5$0%0L/55%$@ %B.D2/6C%$" +#K/1='&,B67/ new

ActionHandler()

public void actionPerformed(ActionEvent ev)

RSB6W##,-LE %BG52.'11'((,"!:(<1(0 %BvQP.G525,6<&569"(M: %B vQc

%& '*  #+D  !:(<1(0 %B vQ <&56D,@/$H'61'(.,51'(1,+4D31'(E %B 1A5CS8".'11'(#7B/"0'&E !5$1='4"5#'&:(>  <-871 q,7J380 942/$MH>'$9"#'& %BD2/61'(.,51'(1,+4D31'(E MouseHandler RSB6:;"#'& %B.(,+J]64D31'(EI"A5 .'1D,@/$H'6"%8#'& MouseMotionListener !5$:;"#'&>'$9" %B/$MH9"#'& EventDemo2 %B0% //:.KC/6#'& Frame I%B 7B/ fr RSB61'(#6 +%$"(,+J]64D31'(E MouseEvent !5$9I2='&,B6 fr.addMouseMotionListener(new MouseHandler())

!5$ %B='&,B6 MouseHandler

:;"1'(&(2'6//:.KC/6#'& .%B  ='4"2' %B:;"<-871q,7J380!:(<1(0"%8.G52W##,-LE5,6<&569"(M: new

MouseHandler()

%BvQu

 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 

("'  3! 1'(.,51'(1,+4D31'(E %B 1A5.'11'(15:30™          

import java.awt.*; import java.awt.event.*; public class EventDemo1 { public static void main(String args[]) { Frame fr = new Frame("Event Demo"); Button bn1 = new Button("Exit"); fr.setLayout(new FlowLayout()); bn1.addActionListener(new ActionHandler()); fr.add(bn1); fr.setSize(200,200); fr.setVisible(true); } } ------------------------------------------------------public class ActionHandler implements ActionListener { public void actionPerformed(ActionEvent ev) { System.exit(0); } }



   3!% W##,-LE %BG52.'11'((,"!:(<1(0 %BvQP         

    





("'  3!$ 1'(.,51'(1,+4D31'(E %B1A5CS8".'11'(#7B/"0'&E  import java.awt.*;  import java.awt.event.*;  public class EventDemo2 { private Frame fr;  private TextField tf; public EventDemo2() {  fr = new Frame("Event Demo"); tf = new TextField(15);  fr.setLayout(new FlowLayout());  fr.add(tf); fr.setFont(new Font("TimesRoman",Font.BOLD,16));  fr.addMouseMotionListener(new MouseHandler()); fr.setSize(200,200);  fr.setVisible(true); }  public class MouseHandler implements MouseMotionListener public void mouseDragged(MouseEvent ev) {  tf.setText("X="+ev.getX()+" Y="+ev.getY());  } public void mouseMoved(MouseEvent ev) { }  } public static void main(String args[]) {  EventDemo2 obj = new EventDemo2(); }  }   



  3!, W##,-LE %BG52.'11'((,"!:(<1(0 %BvQ

 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

{



%&" '* +D #0+ ' ('&'0'(* %B.1='4"5942#'& %BD2/61'(..,51'(1,+4D31'(E :;"#'&:(>  <-871 q,7J380 G52/6 !5$1'(1='4"5942#'&",8" implements /A"D/(EJ&:(>  Listener %B&/5#2/61," !:(<1(0 %BvQc<&56D,@/$H'6C/6#'&EventDemo3 RSB6. 0%//:.KC/6#'& Frame %BI7B/ fr RSB6.(,+J]64D31'(E:(>  WindowEvent #'&"%8.:;"#'&:(>  <-871 q,7J380 52@$ !5$1'(  /A"D/(EJ& WindowListener !:(<1(0"%8G52&(2'6//:.KC/6#'& EventDemo CS8"0' <#9I2 ='&,B6 fr.addWindowListener(this)

 -7B/#6 +%$"(,+J]64D31'(E<#942//:.KC/6#'&"%8(this) RSB6:;"//:.K :(>  <-871 q,7J380 9"1'(.,51'(1,+4D31'(E !:(<1(0"%8. ='942&'0'(*:ƒ5J(0G52 !5$1'(#A10'&E %B (7B/640'$1'1+' D(6d  ,86"%8 "7B/6.'1#'& EventDemo3 0%='&,6B 9"0L/5 windowClosing() -7B///1.'1!:(<1(0 (='&,B6 System.exit(0)) !:(<1(0"%8.G52W##,-LE5,6<&569"(M: %BvQt ("'  3!% #'& 0%B %1'((,+J]64D31'(E:(> WindowEvent        

import java.awt.*; import java.awt.event.*;  public class EventDemo3 implements WindowListener{ public static void main(String args[]) { EventDemo3 obj = new EventDemo3(); obj.init(); } public void init() { Frame fr = new Frame("Event Demo"); fr.addWindowListener(this); fr.setSize(200,200); fr.setVisible(true); } public void windowClosing(WindowEvent ev) { System.exit(0); } public void windowOpened(WindowEvent ev) {} public void windowClosed(WindowEvent ev) {} public void windowIconified(WindowEvent ev) {} public void windowDeiconified(WindowEvent ev) {} public void windowActivated(WindowEvent ev) {} public void windowDeactivated(WindowEvent ev) {} }

    

    





  3!- W##,-LE %BG52.'11'((,"!:(<1(0 %BvQc 

%&& '2y&/'@&#+&/'@ >'?'.'@'/"3n'D942//:.KC/6#'& %B :;"&H@"1('JJƒ1 G52-(2/01,"/' AIH" *2'//:.K fr :;"//:.KC/6 Frame ('&'0'(* %B.#6 +%$"(,+J]64D31'(EG525,6"%8 fr.addMouseMotionListener(this); fr.addWindowListener(this);

 RSB6:;"1'(1='4"5942//:.K fr (,+J]64D31'(E %B 1A5.'11'(#7B/"0'&E<# 4D31'(E %B 1%B$@C2/61,+J(0-(2/01,"  #'&95F&'0'(* .%B  implements /A"D/(EJ&:(>  Listener G524#'$ I"A5IH" public class EventDemo4 implements MouseMotionListener, WindowListener { ... }

:;"1'(1='4"5#'& EventDemo4 942:;"#'&:(>  <-871 q,7J380 %B implement /A"D/(EJ& MouseMotionListener <# WindowListener >'$9"#'&5%$@1," "/1.'1"%8#'&:(>  <-871 q,7J380 95F&'0'(* 9%B I29"1'(&(2'6//:.K<#2@ .,51'(1,+//:.K %B:;"<-871>=2058 G524#'$//:.K ,86"%8 ,0^2;871 %B:;"//:.KC/6 #'&:(>  Event .0%0L/5 9%B I29"1'((+3//:.KC/6 <-871 >=2058 G52/' AIH" (0L/5getSource())

 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

  !:(<1(0 %B vQu <&56D,@/$H'6C/6#'& EventDemo4 RSB60%//:.K fr B% #6 +%$"(,+J]64D31'(E&/6I"A5 <##'&"%8 implements /A"D/(EJ& 6,8 &/6I"A5 B% &/5#2/61,"!:(<1(0"%.8 942W##,-LE5,6(M: %BvQ… ("'  3!, #'& #%B 6 +%$"(,+J]64D31'(E&/6I"A5 import java.awt.*; import java.awt.event.*; public class EventDemo4 implements MouseMotionListener, WindowListener { private Frame fr; private TextField tf; public EventDemo4() { fr = new Frame("Event Demo"); tf = new TextField(15); fr.setLayout(new FlowLayout()); fr.add(tf); fr.setFont(new Font("TimesRoman",Font.BOLD,16)); fr.addMouseMotionListener(this); fr.addWindowListener(this); fr.setSize(200,200);  fr.setVisible(true);  } public static void main(String args[]) {  EventDemo4 obj = new EventDemo4();  } public void mouseDragged(MouseEvent ev) {  tf.setText("X="+ev.getX()+" Y="+ev.getY());  } public void mouseMoved(MouseEvent ev) { }  public void windowClosing(WindowEvent ev) {  System.exit(0); }  public void windowOpened(WindowEvent ev) { } public void windowClosed(WindowEvent ev) { } public void windowIconified(WindowEvent ev) { } public void windowDeiconified(WindowEvent ev) { } public void windowActivated(WindowEvent ev) { } public void windowDeactivated(WindowEvent ev) { } }

    

    





   3!. W##,-LE G%B 52.'11'((,"!:(<1(0 %BvQu

%&- #M?JICbW>SCJB

#'&:(>  <-871 PJ,B180 7/#'& %BG52 implements /A"D/(EJ&:(>  ListenerG@2<#2@!5$G521='4"50L/5DH'6FC/6/A"D/(EJ& %BD2/6C%$"+#K/1='&,6B G@2<#2@ '$9"+#K/1 #'&:(>  <-871 PJ,B180 .IH@$ ='942C%$"!:(<1(0 %B :;"#'&:(>  <-871 q,7J380 G526H'$CS8"!5$#5.='"@"0L/5 %B .D2/6C%$"+#K/1='&,B6 1'(C%$"#'&:(>  <-871 q,7J380 "%8.D2/6&7+ /50'.'1 #'&:(>  <-871 PJ,B180 &='4(,+1'((,+J]64D31'(E %B&/5#2/61,"<#.1='4"5 0L/5<++ =-800/JJ87 |-'0L/5 %BD2/61'(.,51'(1,+4D31'(E #'&:(>  <-871 PJ,B180.0%/$MH##'&5,6"%8 

 

7/#'& %B

x

MouseAdapter MouseListener

x

MouseMotionAdapter MouseMotionListener

x

ComponentAdapter ComponentListener

x

ContainerAdapter ContainerListener

x

KeyAdapter KeyListener

x

WindowAdapter WindowListener

implements

/A"D/(EJ& I%B 7B/

7/#'& %B implements /A"D/(EJ& I%B 7B/ 7/#'& %B

implements

/A"D/(EJ& I%B 7B/

7/#'& %B

implements

/A"D/(EJ& I%B 7B/

7/#'& %B 7/#'& %B

implements

implements

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

/A"D/(EJ& I%B 7B/ /A"D/(EJ& I%B 7B/

 x

FocusAdapter FocusListener

7/#'& %B

implements

/A"D/(EJ& I%B 7B/



!:(<1(0 %B vQt <&56D,@/$H'6C/61'(1='4"5#'&:(>  <-871 PJ,B180 B&% 7+ /50'.'1#'& WindowAdapter !:(<1(0"%8. ='942&'0'(*:ƒ5J(0RSB6W##,-LE BG% 52 .:;"IH"5%$@1,+W##,-LE %BG52.'11'((,"!:(<1(0 %BvQc5,6<&569"(M: %BvQt ("'  3!- #'&:(> %B&7+ /50'.'1#'&WindowAdapter import java.awt.*; import java.awt.event.*;  public class EventDemo5 { public static void main(String args[]) { Frame fr = new Frame("Event Demo"); fr.addWindowListener(new WindowHandler()); fr.setSize(200,200); fr.setVisible(true); } } public class WindowHandler extends WindowAdapter { public void windowClosing(WindowEvent ev) { System.exit(0); } }

%&4 ' #">INIqLNDX   ('&'0'(*&(2'6#'&:(> <-871q,7J380 >'$9"0L/5 %B9I29"1'(#6 +%$" (,+J]64D31'(E (0L/5:(>  addXXxListener()) #'&:(> "%8 (%$1@H'#'& <++,7=7];=2K RSB60,1.9I21MH ,+#'&:(> <-871PJ,B180 !5$"A$09I21,+1'(:ƒ5J(0 /' AIH"='&,B6 fr.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent ev) { System.exit(0); } }); :;"1'(&(2'6#'&<++ ,7=7];=2K >'$9"0L/5 addWindowListener()

-7B/:ƒ5J(0C/6//:.K fr!:(<1(0 %B vQ…<&56D,@/$H'6C/6#'&9"(M:<++"%8 RSB6W##,-LE %BG52.:;"IH"5%$@1,+W##,-LE %BG52.'11'((,"!:(<1(0 %BvQc5,6<&569"(M: %BvQt

    

    





("'  3!. #'&<++,7=7];=2K import java.awt.*; import java.awt.event.*; public class EventDemo6 { public static void main(String args[]) { Frame fr = new Frame("Event Demo"); fr.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent ev) { System.exit(0); } }); fr.setSize(200,200); fr.setVisible(true); } }

/& x //:.KC/6#'&:(>  Event9"<-.1K. java.awt.event.*M1&(2'6CS8" 07B/0%4D31'(E1A5CS8"1,+//:.KC/6&H@":(1/+1('JJƒ1 IH" ActionEvent 1A5CS8"07B/0%1'(15Button4(7/WindowEvent1A5CS8"07B/0%1'(:ƒ5Frame x 1'(..,51'(1,+ <-871 :(> 95",8" !5$ ,B@G:.D2/6&(2'6//:.KC/6#'& %B implements /A"D/(EJ& & %B /5#2/61,"1,+ <-871 ",8"52@$ IH"*2'D2/61'( .,51'(1,+ WindowEvent .D2/6&(2'6//:.KC/6#'& %B implements /A"D/(EJ& WindowListener !5$1'(&(2'6//:.K/'.&(2'6.'1#'&940H #'&>'$9"#'&5%$@1,"4(7/#'&:(> ,7=7];=2KRSB6#'&:(> "%8.*M1 (%$1@H'#'&:(> <-871q,7J380 x #'&95F&'0'(* implements /A"D/(EJ&G524#'$D,@ ='942&'0'(* %B.CS8" +%$"(,+J]64D31'(EG524#'$4D31'(E x #'&:(>  <-871 PJ,B180 7/#'& %B implements /A"D/(EJ&:(>  `/K18780 S M<#2@ !5$G521='4"50L/5DH'6FC/6/A"D/(EJ& D%B 2/6C%$"+#K/1='&,B6 G@2<#2@'$9"+#K/1 

 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

Related Documents

Chap 7
May 2020 11
Chap 7
November 2019 31
Chap 7
December 2019 20
Chap 7
June 2020 13
Chap 7
November 2019 16
Chap 7
November 2019 25