import java.awt.*;
import java.awt.event.*; //这里不是java.event.*;
public class TwoListen implements MouseMotionListener,MouseListener,WindowListener{
private Frame f;
private TextField tf;
public static void main(String args[]){ //这里public写错了.
TwoListen two=new TwoListen();
two.go();
}
public 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.setSize(300,200);
f.setVisible(true);
}
public void mouseDragged(MouseEvent e){
String s="Mouse dragging : X="+e.getX()+"Y="+e.getY();
tf.setText(s);
}
public void mouseMoved(MouseEvent e){}
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 buolding";
tf.setText(s);
}
public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e){System.exit(1);}
public void windowOpened(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void windowClosed(WindowEvent e){} //这里WindowEvent写错了
public void windowActivated(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
public void windowClosing(WindowEvent e){} //缺少这个方法
}
import java.awt.event.*; //这里不是java.event.*;
public class TwoListen implements MouseMotionListener,MouseListener,WindowListener{
private Frame f;
private TextField tf;
public static void main(String args[]){ //这里public写错了.
TwoListen two=new TwoListen();
two.go();
}
public 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.setSize(300,200);
f.setVisible(true);
}
public void mouseDragged(MouseEvent e){
String s="Mouse dragging : X="+e.getX()+"Y="+e.getY();
tf.setText(s);
}
public void mouseMoved(MouseEvent e){}
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 buolding";
tf.setText(s);
}
public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e){System.exit(1);}
public void windowOpened(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void windowClosed(WindowEvent e){} //这里WindowEvent写错了
public void windowActivated(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
public void windowClosing(WindowEvent e){} //缺少这个方法
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货