import java.awt.*;
import java.awt.event.*;public class MyApp333 extends Frame
{
public MyApp333()
{
this.addWindowListener (new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
System.exit(0);
}
});
}

public static void main(String args[])
{
System.out.println("Starting App");
MyApp333 f = new MyApp333();
f.setSize(100,100);
f.show();
}
}

解决方案 »

  1.   

    不知道你的jdk的版本是多少,我用jdk2.1.3没有出现你说的问题。
      

  2.   

    我的jdk版本是1.3,以下是我的一段程序:(用1.3版本编译后运行就出问题,请指教)import java.awt.*;
    import java.awt.event.*;public class TwoListenInner
    {
    private Frame f;
    private TextField tf;

    public static void main(String args[]){
    TwoListenInner That=new TwoListenInner();

    }

    public  TwoListenInner(){
    f=new Frame("Two listeners example");
    f.add("North",new Label("Click and drag the mouse"));
    tf=new TextField(30);
    f.add("South",tf);
    f.addMouseMotionListener(new MouseMotionHandler());
    f.addMouseListener(new MouseEventHandler());
    f.setSize(300,300);
    f.setEnabled(true);
    f.setVisible(true);
        }

    public class MouseMotionHandler extends MouseMotionAdapter{
    public void mouseDragged(MouseEvent e){
    String s="Mouse dragging: X="+e.getX()+"Y="+e.get();
    tf.setText(s);
    }
    }

    public class MouseEventHandler extends MouseAdapter{
    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);


    }
    }
    }
      

  3.   

    加上window监听器试试看 :)
    import java.awt.*;
    import java.awt.event.*;public class TwoListenInner
    {
    private Frame f;
    private TextField tf;
    public static void main(String args[]){
    TwoListenInner That=new TwoListenInner();
    }public  TwoListenInner(){f=new Frame("Two listeners example");
    f.add("North",new Label("Click and drag the mouse"));
    f.addWindowListener (new WindowAdapter(){
    public void windowClosing(WindowEvent e){
    System.exit(0);
    }
    });tf=new TextField(30);
    f.add("South",tf);
    f.addMouseMotionListener(new MouseMotionHandler());
    f.addMouseListener(new MouseEventHandler());
    f.setSize(300,300);
    f.setEnabled(true);
    f.setVisible(true);
    }
    public class MouseMotionHandler extends MouseMotionAdapter{
    public void mouseDragged(MouseEvent e){
    String s="Mouse dragging: X="+e.getX()+"Y="+e.getY();
    tf.setText(s);
    }
    }public class MouseEventHandler extends MouseAdapter{
    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);
    }
    }
    }