0
点赞
收藏
分享

微信扫一扫

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

一世独秀 2022-05-02 阅读 52
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 条评论