0

私のコードでエラー(?)を見つけるのに少し助けが必要です.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 の場合、非アクティブな再生ボタンの画像が表示されますが、true の場合はクリック/リリース画像が表示されます。また、アクティブかアクティブでないかをシステム ボックス(?)(何と呼ばれているか不明)に出力します。

4

1 に答える 1

3
 if (active=true)

active を true に割り当てます。あなたがしたい:

 if (active==true)
于 2012-12-15T20:46:30.673 に答える