package com.vp.jump.dd; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JFrame; import javax.swing.JLabel; public class Jump extends JFrame{ int x0,y0,x1,y1; boolean flag=true; //创建一个窗口,创建一个窗口的构造函数 public Jump(){ super("微信跳一跳");//调用父类方法 //设置窗口大小,初始化窗口是不可见的 this.setSize(295,605); //去掉装饰的窗口 this.setUndecorated(true); //设置透明度 this.setOpacity(0.4f); //设置位置居中 this.setLocationRelativeTo(null); //设置窗口置顶 this.setAlwaysOnTop(true); //设置窗口可见 this.setVisible(true); //创建一个小面板 final JLabel lable1=new JLabel(); this.add(lable1); //判断点击的次数 //监听鼠标事件 点击 this.addMouseListener(new MouseAdapter() { //鼠标点击方法 获取鼠标的事件源 public void mouseClicked (MouseEvent e) { // System.out.println(e); if(e.getButton()==MouseEvent.BUTTON1){//点击鼠标左键的时候执行 if (flag) {//等于true是第一次 //执行具体的东西 //获取点击的坐标 x0=e.getX(); y0=e.getY(); System.out.println("第一次点击的坐标是"+x0+"=="+y0); flag=false; }else {//第二次点击 x1=e.getX(); y1=e.getY(); System.out.println("第二次点击的坐标是"+x1+"=="+y1); //执行的东西 flag=true; } } } }); } //Java 主函数 程序的入口 public static void main(String[] args) { new Jump(); } }
监听事件加坐标轴的写入
猜你喜欢
转载自blog.csdn.net/qq_41985556/article/details/80172268
今日推荐
周排行