📄 multilistener.java
字号:
/******************************************
* class MultiListener(version 1.1)
*******************************************/
import java.awt.*;
import java.awt.event.*;
public class MultiListener implements MouseListener,MouseMotionListener,WindowListener
//实现多个监听器接口
{
private Frame f;
private TextField tf;
public static void main(String args[])
{
MultiListener ml = new MultiListener();
ml.go();
}
public void go()
{
Frame f = new Frame("MultiListener Test 1.1");
f.add( new Label("Click and Drag the mouse"), "North" );
tf = new TextField(30);
f.add( tf, "South");
//同时监听容器f上发生的多种事件
f.addMouseListener(this);
f.addMouseMotionListener(this);
f.addWindowListener(this);
f.resize(200,200);
f.show();
}
//MouseMotionListener
public void mouseDragged(MouseEvent e)
{
//通过事件获得其详细信息
String s = "Mouse dragging : X = " + e.getX() + " Y = " + e.getY();
tf.setText(s);
}
public void mouseMoved(MouseEvent e){}
//MouseListener
public void mouseEntered(MouseEvent e)
{
String s = "The mouse Entered";
tf.setText(s);
}
public void mouseExited(MouseEvent e)
{
String s = "The mouse Exited";
tf.setText(s);
}
public void mouseClicked(MouseEvent e){}
public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
//WindowListener
//注意关闭窗口的方法是windowClosing(),而不是windowClosed()
public void windowClosing(WindowEvent e)
{
System.exit(1);
}
public void windowClosed(WindowEvent e){}
public void windowOpened(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
public void windowActivated(WindowEvent e){}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -