我的日食告诉我,我需要使用静态修饰符,但是当我这样做时,洞的事情就出错了。这是我的代码我希望你能帮助我并告诉我我做错了什么(我从 StealthyHunter7 得到了内部类的提示):
public class ClickBot
{
private class Key
implements KeyListener
{
private boolean spacebarPressed = false;
@Override
public void keyTyped(KeyEvent e)
{
}
@Override
public void keyPressed(KeyEvent e)
{
if(e.getKeyCode() == KeyEvent.VK_SPACE)
{
spacebarPressed = true;
}
}
@Override
public void keyReleased(KeyEvent e)
{
if(e.getKeyCode() == KeyEvent.VK_SPACE)
{
spacebarPressed = false;
}
}
public boolean isSpacebarPressed()
{
return spacebarPressed;
}
}
Key keyObject = new Key();
public static void main(String[] args) throws IOException, AWTException
{
JFrame.addKeyListener(keyObject);
final Robot robot = new Robot();
robot.delay(2000);
while(keyObject.spacebarPressed())
{
{
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.delay(30);
}
}
}
}