Java:1、 编写一个关闭就结束程序的窗口,其中有一个文本框,它能跟踪记录鼠标在窗口中拖动时的坐标

阅读 54

2022-05-02

public class pro extends JFrame {
    JTextField f;
    java实验2(String s){
        f=new JTextField(20);
        setLayout(new FlowLayout());
        this.setBounds(100,100,400,400);
        this.add(f);
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        B b=new B();
        this.addMouseMotionListener(b);
    }
    //内部类
    class B implements MouseMotionListener{
        public void mouseMoved(MouseEvent e){}
        public void mouseDragged(MouseEvent e){
            f.setText((e.getX()+":"+e.getY()));
        }
    }
    public static void main(String[] args){
        new pro("我的第二个窗口");
    }
}

精彩评论(0)

0 0 举报