gpt4 book ai didi

java - 运行时 boolean 值发生变化

转载 作者:行者123 更新时间:2023-12-02 00:05:52 27 4
gpt4 key购买 nike

只需要一点帮助来定位我的代码中的错误(?),将 boolean avtive 的默认值设置为 false,但当我运行代码时,它神秘地变成 true

    import javax.swing.*;
import java.awt.*;
import java.net.URL;

@SuppressWarnings("serial")
public class openScreenBuild extends JPanel{
String picPath = "pictures/";
String[] fileName = { "openScreen.png", "playButtonPress.png",
"playButtonRelease.png", "playButtonInactive.png" };
ClassLoader cl = openScreenBuild.class.getClassLoader();
URL imgURL[] = new URL[4];
Toolkit tk = Toolkit.getDefaultToolkit();
Image imgBG, imgPlayPress, imgPlayRelease, imgPlayInactive;
Boolean active=false, playPress = false;

public openScreenBuild() throws Exception {
for (int x = 0; x < 4; x++) {
imgURL[x] = cl.getResource(picPath + fileName[x]);
}
imgBG = tk.createImage(imgURL[0]);
imgPlayPress = tk.createImage(imgURL[1]);
imgPlayRelease = tk.createImage(imgURL[2]);
imgPlayInactive = tk.createImage(imgURL[3]);
}
public void updateScreen(){
repaint();
}
public void paintComponent(Graphics g) {
g.drawImage(imgBG, 0, 0, 600, 460, 0, 0, 600, 460, this);
if (active=true){
if (playPress == false)
g.drawImage(imgPlayRelease, 410, 355, 590, 450, 0, 0, 163, 87, this);
else if (playPress == true)
g.drawImage(imgPlayPress, 410, 355, 590, 450, 0, 0, 163, 87, this);
System.out.println("Active");
}
else if(active=false){
g.drawImage(imgPlayInactive, 410, 355, 590, 450, 0, 0, 163, 87, this);
System.out.println("Inactive");
}
g.setColor(Color.WHITE);
g.drawString("ABOUT PROGRAM STUFF", 25, 375);
}
public void checkCoord(Point point){
int xPos=(int)point.getX();
int yPos=(int)point.getY();
if (active==true){
if ((yPos>=355)&&(yPos<=450)&&(xPos>=410)&&(xPos<=590))
playPress=true;
}
updateScreen();
}
public void resetScreen(){
playPress=false;
updateScreen();
}
}

如您所见,如果 active 为 false,则应显示非 Activity 播放按钮图像,但如果为 true,则显示单击/释放图像。如果它处于 Activity 状态或不活动状态,它也会在系统框中输出(?)(不确定它叫什么)

最佳答案

 if (active=true)

将 active 指定为 true。你想要:

 if (active==true)

关于java - 运行时 boolean 值发生变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13896040/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com