📄 class1.java
字号:
import java.awt.*;
import java.awt.event.*;
class TwoListen implements MouseMotionListener ,MouseListener,WindowListener{
private Frame f;
private TextField tf;
void go(){
f=new Frame("Two listeners example");
f.add(new Label("Click and drag the mouse"),"North");
tf=new TextField(30);
f.add(tf,"South");
f.addMouseMotionListener(this);
f.addMouseListener(this);
f.addWindowListener (this);
f.setSize(300,200);
f.setVisible(true);
}
void mouseDragged(MouseEvent e){
String s="Mouse dragging:x="+e.getX()+"Y="+e.getY();
tf.setText(s);
}
void mouseMoved(MouseEvent e){}
void mouseClicked(MouseEvent e){}
void mouseEnter(MouseEvent e){
String s="The mouse entered";
tf.setText(s);
}
void mouseExited(MouseEvent e){
String s="The mouse has left the building";
tf.setText(s);
}
void mousePressed(MouseEvent e){}
void mouseReleased(MouseEvent e){}
void windowsClosing(WindoEvent e){
System.exit(1);
};
void windowOpened(WindoEvent e){}
void windowIconified(WindoEvent e){}
void windowDeiconified(WindoEvent e){}
void windowClosed(WindoEvent e){}
void windowActivated(WindoEvent e){}
void windowDeactivated(WindoEvent e){}
}
public class Class1{
public static void main (String[] args)
{
TwoListen two=new TwoListen();
two.go();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -