我正在使用布尔型 canclick 鼠标变量来暂时禁用我的mouse listener
,但是当我重新启用它时,它似乎mouse listener
会记住我单击的位置:
class MouseHelper extends MouseAdapter
{
public void mouseClicked(MouseEvent e)
{
if(!canclick)
{
return;
}
int a=e.getX();
int b=e.getY();
if(a>=473&&a<=502&&b>=139&&b<=153&&start==true)
{
runonce=1;
repaint();
start=false;
}
所以这就是我将canclick设置为false的地方,在它完成显示正确的屏幕后将其重置canclick
为true
:
if(runonce==2)
{
canclick=false;
System.out.println("Set as false");
g.setFont(new Font("TimesRoman",Font.BOLD,40));
g.drawString("Correct!",325,250);
try {
Thread.sleep(10000);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
runonce=1;
}
if(runonce==1)
{
g.setFont(new Font("Arial",Font.BOLD,10));
g.setColor(Color.WHITE);
g.fillRect(0,0,1000,1000);
drawboxes(g);
says();
s=10;
g.setColor(Color.BLACK);
g.drawString(colr.get(colr.size()-1),401,s);
count=Integer.toString(level+1);
g.drawString("Level:"+count,401,s+10);
canclick=true;
}
}
我的问题是,当我在正确的屏幕上单击时,wherecanclick
设置为false
,whencanclick
再次设置为 true,它会记住我单击的所有位置。