精品丰满熟女一区二区三区_五月天亚洲欧美综合网_亚洲青青青在线观看_国产一区二区精选

  • <menu id="29e66"></menu>

    <bdo id="29e66"><mark id="29e66"><legend id="29e66"></legend></mark></bdo>

  • <pre id="29e66"><tt id="29e66"><rt id="29e66"></rt></tt></pre>

      <label id="29e66"></label><address id="29e66"><mark id="29e66"><strike id="29e66"></strike></mark></address>
      學(xué)習(xí)啦 > 學(xué)習(xí)電腦 > 電腦硬件知識 > 鍵盤鼠標(biāo) > java的鼠標(biāo)移動(dòng)事件

      java的鼠標(biāo)移動(dòng)事件

      時(shí)間: 沈迪豪908 分享

      java的鼠標(biāo)移動(dòng)事件

        愛學(xué)習(xí)的小伙伴們,可能都可能都學(xué)過Java,但是你知道java的鼠標(biāo)移動(dòng)事件是什么嗎?不知道的話跟著學(xué)習(xí)啦小編一起來學(xué)習(xí)了解java的鼠標(biāo)移動(dòng)事件。

        java的鼠標(biāo)移動(dòng)事件代碼介紹

        import java.awt.BorderLayout;

        import java.awt.event.MouseAdapter;

        import java.awt.event.MouseEvent;

        import java.awt.event.MouseMotionListener;

        import javax.swing.JButton;

        import javax.swing.JFrame;

        import javax.swing.JPanel;

        import javax.swing.JTextField;

        public class mymouse {

        static JFrame frm;

        static JTextField tf;

        static JButton btn;

        static int x, y,px, py,bx,by,offx,offy; //

        public static void main(String[] args) {

        frm = new JFrame("dialog");

        frm.setBounds(400, 100, 500, 400);

        frm.setLayout(null);

        tf = new JTextField();

        tf.setBounds(60,200,200,20);

        btn = new JButton("move me");

        btn.setBounds(60,40,100,50);

        frm.add(tf);

        frm.add(btn);

        btn.addMouseMotionListener(new mymousemotion());

        btn.addMouseListener(new mymouselistener());

        frm.setVisible(true);

        frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        }

        static class mymousemotion implements MouseMotionListener{

        public void mouseDragged(MouseEvent e) {

        //

        x=e.getX()-px+bx;

        y=e.getY()-py+by;

        btn.setLocation(x, y);

        tf.setText("button location :"+x+","+y);

        bx=x;

        by=y;

        }

        public void mouseMoved(MouseEvent e) {

        }

        }

        static class mymouselistener extends MouseAdapter{

        public void mousePressed(MouseEvent e){

        //鼠標(biāo)點(diǎn)擊位置相對 btn 的坐標(biāo).

        px=e.getX();

        py=e.getY();

        //獲取 btn 相對 frm 的坐標(biāo)

        bx=btn.getLocation().x;

        by=btn.getLocation().y;

        String str=px+","+py+" . "+bx+","+by;

        tf.setText(str);

        }

        }

        }

      java的鼠標(biāo)移動(dòng)事件相關(guān)文章:

      1.怎么使用jquery實(shí)現(xiàn)鼠標(biāo)停止移動(dòng)事件

      2.如何設(shè)置鼠標(biāo)事件

      3.css設(shè)置鼠標(biāo)事件

      4.鼠標(biāo)事件屬性詳解

      5.計(jì)算機(jī)網(wǎng)絡(luò)實(shí)驗(yàn)論文

      6.計(jì)算機(jī)微機(jī)監(jiān)控論文

      1998133