简体   繁体   English

Java条件语句问题

[英]Java conditional statement issues

I just started Java yesterday and been having some issues with conditional statements.我昨天刚开始使用 Java,但在条件语句方面遇到了一些问题。 Trying to disable and autoclicker when my mouse is up, and enable it when my mouse is down.尝试在鼠标启动时禁用和自动点击器,并在鼠标关闭时启用它。 But the clicker still clicks?但是点击器仍然点击? How should I have this set up?我应该如何设置这个?

public class Random {
public boolean held;
Random(){
    held = false;
}
public void printhi() {
    System.out.print("hi");
}


public void setHeld(boolean held) throws AWTException {
    this.held = held;
    if(held == true) {
        Robot robot = new Robot();
        robot.mousePress(MouseEvent.BUTTON1_DOWN_MASK);
        robot.delay(100);
        robot.mouseRelease(MouseEvent.BUTTON1_DOWN_MASK);
        if(held != true) {
            
        }
    }

    
    
        
}

Just take another look at your logic:再看看你的逻辑:

if(held == true) {
    if(held != true) {
        
    }
}

I only removed some lines to hint you to the mistake :)我只是删除了一些行来提示你错误:)

public class Random {
    public boolean held = false;

    Random() {
    }

    public static void printhi() {
        System.out.print("hi");
    }


    public void setHeld(boolean held) throws AWTException {
        this.held = held;
        if (held) {
            Robot robot = new Robot();
            robot.mousePress(MouseEvent.BUTTON1_DOWN_MASK);
            robot.delay(100);
            robot.mouseRelease(MouseEvent.BUTTON1_DOWN_MASK);
        } else {
            //do stuff
        }


    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM