请教各位网友有什么方法可以根据事件类型的id来获得这个事件类型名?
本文导语: 各位网友,大家好: 先请看这样一段源代码: import java.awt.*; import java.awt.event.*; import javax.swing.*; class EventIdPanel extends JPanel implements ActionListener { public EventIdPanel() { JButton btn...
先请看这样一段源代码:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class EventIdPanel extends JPanel implements ActionListener
{
public EventIdPanel()
{
JButton btnEventId=new JButton("TestEvent");
add(btnEventId);
btnEventId.addActionListener(this);
}
public void actionPerformed(ActionEvent evt)
{
TestEventId();
}
public void TestEventId()
{
EventQueue evtq=Toolkit.getDefaultToolkit().getSystemEventQueue();
try
{
AWTEvent evt=evtq.getNextEvent();
int result=evt.getID();
System.out.println(result);
}
catch(InterruptedException e)
{
System.out.println("InterruptedException occured!");
}
}
}
class EventIdFrame extends JFrame
{
public EventIdFrame()
{
setTitle("My EventId Application!");
setSize(300,250);
Toolkit tk=Toolkit.getDefaultToolkit();
Dimension d=tk.getScreenSize();
int width=(d.width-300)/2;
int height=(d.height-250)/2;
setLocation(width,height);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent evt)
{
System.exit(0);
}
});
Container contentPane=getContentPane();
contentPane.add(new EventIdPanel());
}
}
public class EventId2
{
public static void main(String[] args)
{
JFrame MyFrame=new EventIdFrame();
MyFrame.show();
}
}
这段程序的作用是获取当按钮按下了后,事件队列中的下一个事件类型的ID号,我想请问各位网友的是:如何
根据这个事件类型的ID号知道这是个什么事件类型呢?因为ID号是int类型的,不太明了。好了,那位网友要是
知道的话,能告诉我吗?谢谢各位Java高人了哦!
|
/*
* @(#)Event.java 1.68 00/02/02
*
* Copyright 1995-2000 Sun Microsystems, Inc. All Rights Reserved.
*
* This software is the proprietary information of Sun Microsystems, Inc.
* Use is subject to license terms.
*
*/
package java.awt;
import java.awt.event.*;
import java.io.*;
/**
* Event is a platform-independent class that
* encapsulates events from the platform's Graphical User
* Interface in the Java 1.0 event model. In Java 1.1
* and later versions, the Event class is maintained
* only for backwards compatibilty. The information in this
* class description is provided to assist programmers in
* converting Java 1.0 programs to the new event model.
*
* In the Java 1.0 event model, an event contains an
* {@link Event#id} field
* that indicates what type of event it is and which other
* Event variables are relevant for the event.
*
* For keyboard events, {@link Event#key}
* contains a value indicating which key was activated, and
* {@link Event#modifiers} contains the
* modifiers for that event. For the KEY_PRESS and KEY_RELEASE
* event ids, the value of key is the unicode
* character code for the key. For KEY_ACTION and
* KEY_ACTION_RELEASE, the value of key is
* one of the defined action-key identifiers in the
* Event class (PGUP,
* PGDN, F1, F2, etc).
*
* @version 1.68 02/02/00
* @author Sami Shaio
* @since JDK1.0
*/
public class Event implements java.io.Serializable {
private transient long data;
/* Modifier constants */
/**
* This flag indicates that the Shift key was down when the event
* occurred.
*/
public static final int SHIFT_MASK = 1