import java.awt.*;
import java.awt.event.*;
public class TwoListen implements
MouseMotionListener, MouseListener {
private Frame f;
private TextField tf;
public static void main(String args[]) {
TwoListen two = new TwoListen();
two.go();
} public void go() {
f = new Frame("Two listeners example");
f.add (new Label ("Click and drag the mouse"),"BorderLayout.NORTH"); // 似乎是这句有错误,但需要怎么改啊 tf = new TextField (30);
f.add (tf, "BorderLayout.SOUTH");
f.addMouseMotionListener(this);
f.addMouseListener (this);
f.setSize(300, 200);
f.setVisible(true);
}
// These are MouseMotionListener events
public void mouseDragged (MouseEvent e) {
String s =
"Mouse dragging: X = " + e.getX() +
" Y = " + e.getY();
tf.setText (s);
}
public void mouseMoved (MouseEvent e) {
}
// These are MouseListener events
public void mouseClicked (MouseEvent e) {
}
public void mouseEntered (MouseEvent e) {
String s = "The mouse entered";
tf.setText (s);
}
public void mouseExited (MouseEvent e) {
String s = "The mouse has left the building";
tf.setText (s);
}
public void mousePressed (MouseEvent e) {
}
public void mouseReleased (MouseEvent e) {
}
}
import java.awt.event.*;
public class TwoListen implements
MouseMotionListener, MouseListener {
private Frame f;
private TextField tf;
public static void main(String args[]) {
TwoListen two = new TwoListen();
two.go();
} public void go() {
f = new Frame("Two listeners example");
f.add (new Label ("Click and drag the mouse"),"BorderLayout.NORTH"); // 似乎是这句有错误,但需要怎么改啊 tf = new TextField (30);
f.add (tf, "BorderLayout.SOUTH");
f.addMouseMotionListener(this);
f.addMouseListener (this);
f.setSize(300, 200);
f.setVisible(true);
}
// These are MouseMotionListener events
public void mouseDragged (MouseEvent e) {
String s =
"Mouse dragging: X = " + e.getX() +
" Y = " + e.getY();
tf.setText (s);
}
public void mouseMoved (MouseEvent e) {
}
// These are MouseListener events
public void mouseClicked (MouseEvent e) {
}
public void mouseEntered (MouseEvent e) {
String s = "The mouse entered";
tf.setText (s);
}
public void mouseExited (MouseEvent e) {
String s = "The mouse has left the building";
tf.setText (s);
}
public void mousePressed (MouseEvent e) {
}
public void mouseReleased (MouseEvent e) {
}
}
解决方案 »
- 请教如何在函数中强制退出?
- 动态向jar包中添加文件的问题
- 运行在不同jre下的class如何进行方法调用
- 哪有封装好的pio下载?
- 高手快进来关于javamail的javax.activation.UnsupportedDataTypeException的问题****************************
- 一个关于容器的问题,求帮助
- 我做了一个application 来测试连接数据库,出现如下问题:
- 请问,大家都用java开发过什么项目?来者有分
- 不太难的问题,但我就是不知道,大侠们请帮忙
- InputStream is = socket.getInputStream(); is.read() 阻塞 这个怎么解决
- 数组打印1-100
- 关于time类的问题
......
f.add (tf, BorderLayout.SOUTH);