전체 글
- java 관련 자료 사이트 2008.02.12 1
- JAVA Event에 관한 내용. 2008.02.09
- Java Event 관련 Interface 및 Method 2008.02.09
java 관련 자료 사이트
JAVA Event에 관한 내용.
자바에서 각 이벤트는 하나의 이벤트 타입에 속하게 됩니다.
사용자가 JButton 컴포넌트를 클릭할 때 발생하는 actionPerformed 이벤트는 ActionEvent라고 하는 이벤트 타입에
속합니다. 여기에서 이벤트 타입은 EventObject 클래스에서 파생되는 클래스로 정의됩니다.
그리고 각 이벤트 타입에 속하는 모든 이벤트는 리스너 인터페이스의 멤버가 됩니다.
예를 들어 ActionEvent 이벤트 타입에 속하는 actionPerformed 이벤트는 ActionListener라고 하는 리스너
인터페이스의 멤버가 되는 것이지요.
결국 하나의 이벤트 타입에 대하여 하나의 리스터 인터페이스가 있는 셈입니다.
Interface |
Class |
ActionListener |
ActionEvent |
AdjustmentListener |
AdjustmentEvent |
AWTEventListener |
AWTEvenetListenerProxy |
ComponentListener |
ComponentAdapter |
ContainerListener |
ComponentEvent |
FocusListener |
ContainerAdapter |
HierachyBoundsListener |
ContainerEvent |
HierachyListener |
FocusAdapter |
InputMethodListener |
FocusEvent |
ItemListener |
HierachyBoundsAdapter |
KeyListener |
HierachyEvent |
MouseListener |
InputEvent |
MouseMotionListener |
InputMethodEvent |
MouseWheelListener |
InvocationEvent |
TextListener |
ItemEvent |
WindowFocusListener |
KeyAdapter |
WindowListener |
KeyEvent |
WindowStateListener |
MouseAdapter |
|
MouseEvent |
|
MouseMotionAdapter |
|
MouseWheelEvent |
|
PaintEvent |
|
TextEvent |
|
WindowAdapter |
|
WindowEvent |
하나의 리스너 인터페이스에 여러 메소드 즉, 여러 이벤트가 포함될 수 있습니다.
예를 들어 창과 관련된 이벤트에서는 windowActivated, windowClosed, windowClosing, windowDeactivated,
windowDeiconified windowIconified, windowOpened 등이 있으며, 이들 이벤트는 모두 windowListener라고 하는
리스너 인터페이스의 멤버가 됩니다.
이러한 리스너 인터페이스를 구현하는 클래스를 어댑터(Adapter)라고 하며, 어댑터의 인스턴스를 리스너라고 합니다.
그리고 리스너 인터페이스를 구현하고 있는 리스너를 이벤트 소스에 등록시켜야 합니다.
이벤트 소스란 이벤트를 발생시키는 객체입니다.
public class MyPanel extends Jpanel implements ActionListener{
public void actionPerformed(ActionEvent e){
JoptionPane.showMessageDialog(
this,
getSource().ToString() + “ 를 클릭했습니다.”,
“actionPerformed 이벤트”,
JoptionPane.OK_OPTION);
}
public MyPanel(){
jButton = new Jbutton(“클릭하세요.”);
jButton.addActionListener(this);
}
}
public class MyPanel extends Panel{
ActionAdapter actionAdapter = new ActionAdapter();
public MyPanel(){
jButton = new Jbutton(“클릭하세요.”);
jButton.addActionListener(actionAdapter);
}
}
class WindowClosing extends WindowAdapter{
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
class MyFrame extends JFrame{
public MyFrame(){
WindowClosing listener = new WindowClosing();
addWindowListener(listener);
}
}
class MyFrame extends JFrame{
public MyFrame(){
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
}
* “예전에 누가 Adapter를 사용하면 리스너에 있는 method()를 모두 구현하지 않아도
되며 필요한 method()만 구현하면 된다고 했었는데, 사실은 Adapter 클래스를
상속받아서 새로운 리스너를 구현하는 것입니다.”
Java Event 관련 Interface 및 Method
Method Categories and Interface
Category |
Interface Name |
Methods |
Action |
ActionListener |
actionPerformed(ActionEvent) |
Item |
ItemListener |
itemStateChanged(ItemEvent) |
Mouse |
MouseListener |
mousePressed(MouseEvent) mouseReleased(MouseEvent) mouseEnterd(MouseEvent) mouseExited(MouseEvent) mouseClicked(MouseEvent) |
Mouse Motion |
MouseMotionListener |
mouseDragged(MouseEvent) mouseMoved(MouseEvent) |
Key |
KeyListener |
keyPressed(KeyEvent) keyReleased(KeyEvent) keyTyped(KeyEvent) |
Focus |
FocusListener |
focusGained(FocusEvent) focusLost(FocusEvent) |
Adjustment |
AdjustmentListener |
adjustmentValueChanged(AdjusmentEvent) |
Component |
ComponenetListener |
componentMoved(ComponentEvent) componentHidden(ComponentEvent) componentResized(ComponentEvent) componentShown(ComponentEvent) |
Window |
WindowListener |
windowClosing(WindowEvent) windowOpened(WindowEvent) windowIconified(WindowEvent) windowDeiconified(WindowEvent) windowClosed(WindowEvent) windowActivated(WindowEvent) windowDeactivated(WindowEvent) |
Container |
ContainerListener |
componentAdded(ContainerEvent) componentRemoved(ContainerEvent) |
Text |
TextListener |
textValueChanged(TextEvent) |
AWT Components
Component Type |
Description |
Button |
A named rectangular box used for receiving mouse clicks |
Canvas |
A panel used for drawing |
Checkbox |
A component allowing the user to select an item |
ChekboxMenuItem |
A checkbox within a menu |
Choice |
A pull-down static list of items |
Component |
The parent of all AWT components, except menu components |
Container |
The parent of all AWT containers |
Dialog |
The base class of all modal dialog boxes |
Frame |
The base class of all GUI windows with window manager controls |
Label |
A text string component |
List |
A component that containers a dynamic set of items |
Menu |
An element under the menu bar, which containers a set of menu items |
MenuItem |
An item within a menu |
Panel |
A basic container class used most often to create complex layouts |
Scrollbar |
A component that allows a user to “select from a range of values” |
ScrollPane |
A container class that implements automatic horizontal and vertical Scrolling for a single child component |
TextArea |
A component that allows the user to enter a block of text |
TextField |
A component that allows the user to enter a single line of text |
Window |
The base class of all GUI windows, without window manager controls |
Component Events
Component Type |
Act |
Adj |
Cmp |
Cnt |
Foc |
Itm |
Key |
Mou |
MM |
Text |
Win |
Button |
V |
|
V |
|
V |
|
V |
V |
V |
|
|
Canvas |
|
|
V |
|
V |
|
V |
V |
V |
|
|
Checkbox |
|
|
V |
|
V |
V |
V |
V |
V |
|
|
CheckboxMenuItem |
|
|
|
|
|
V |
|
|
|
|
|
Choice |
|
|
V |
|
V |
V |
V |
V |
V |
|
|
Component |
|
|
V |
|
V |
|
V |
V |
V |
|
|
Container |
|
|
V |
V |
V |
|
V |
V |
V |
|
|
Dialog |
|
|
V |
V |
V |
|
V |
V |
V |
|
V |
Frame |
|
|
V |
V |
V |
|
V |
V |
V |
|
V |
Label |
|
|
V |
|
V |
|
V |
V |
V |
|
|
List |
V |
|
V |
|
V |
V |
V |
V |
V |
|
|
MenuItem |
V |
|
|
|
|
|
|
|
|
|
|
Panel |
|
|
V |
V |
V |
|
V |
V |
V |
|
|
Scrollbar |
|
V |
V |
|
V |
|
V |
V |
V |
|
|
ScrollPane |
|
|
V |
V |
V |
|
V |
V |
V |
|
|
TextArea |
|
|
V |
|
V |
|
V |
V |
V |
V |
|
TextField |
V |
|
V |
|
V |
|
V |
V |
V |
V |
|
Window |
|
|
V |
V |
V |
|
V |
V |
V |
|
V |
Act – ActionListener
Adj – AdjustmentListener
Cmp – ComponentListener
Cnt – ContainerListener
Foc – FocusListener
Itm – ItemListener
Key – KeyListener
Mou – MouseListener
MM – MouseMotionListener
Text – TextListener
Win – WindowListener