【发布时间】:2016-03-26 00:44:00
【问题描述】:
我需要一个函数来检查鼠标的光标是否在一个组件上。组件将是JButton、JTextField 和JLabel。我试过下面的代码
@Override
public void paintComponent(Graphics g){
super.paintComponent(g);
boolean noDraw = false;
if(this.getWidth() > mX && mX > 0){
if( this.getHeight() > mY && mY > 0){
components = this.getComponents();
if( components != null){
for(int i = 0; i < components.length; ++i){
if( components[i].contains(mX, mY)){
noDraw = true;
break;
}
}
}
if(noDraw == false )
{
Cicle.draw(g);
}
}
}
}
【问题讨论】:
-
那么你有什么尝试?这不是代码编写服务。
-
@szym05 我的回答对你有用吗?
-
@Dan 感谢您的帮助。
标签: java button cursor components mouse