java监视鼠标事件

yybjroam05 yybjroam05 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我写一个小程序,监视鼠标的点击事件,但一直有问题,编绎不过,
请帮我看看,我是新手,
谢谢!

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import java.awt.event.MouseListener;
import java.awt.Toolkit;
public class Wmain{
public static void main(String[] args){
JFrame myjf=new testchress();
}
}

public class testchress extends JFrame implements MouseListener {
public testchress(){
this.setVisible(true);
this.setTitle("我是标题");
this.setSize(300,200);//窗口宽300,高200
this.setLocation(400,400);
int width=Toolkit.getDefaultToolkit().getScreenSize().width;//获取屏幕宽度
int height=Toolkit.getDefaultToolkit().getScreenSize().height;//获取屏幕高度
this.setLocation((width-200)/2,(height-200)/2);
this.addMouseListener(this);
}
public void mouseClicked(MouseEvent e){
System.out.println("你单击了");
JOptionPane.showMessageDialog(this, "你单击了内容");
}

public void mousePressed(MouseEvent e){
System.out.println("你按下了键");
}

public void mouseReleased(MouseEvent e){
System.out.println("抬起了");
}

/**
* 进入事件
*/
public void mouseEntered(MouseEvent e){

}

//鼠标移出事件
public void mouseExited(MouseEvent e){

}
}
...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部
yybjroam05
Java SE 62,620 成员 307,251 内容