我想将代码关闭(不可见(一些按钮,以便我可以闪烁一系列颜色。请注意,我是Java的新手。不要打扰阅读每个人,如果else
public void runPattern() //shows the pattern of colors
{
System.out.println("runPatternStart");
SimonSaysPanel.invisible();
repaint();
for(int j = 0; j < SimonSaysPanel.maxCount; j++)
{
if(array[j] == 1)
{
System.out.println("runPattern1");
myBuffer.setColor(new Color(60, 255, 0));
myBuffer.fillRect(0, 0, 150, 150);
repaint();
timeDelay(2000);
myBuffer.setColor(new Color(36, 185, 20));
myBuffer.fillRect(0, 0, 150, 150);
repaint();
}
else if(array[j] == 2)
{
System.out.println("runPattern2");
myBuffer.setColor(new Color(255, 255, 0));
myBuffer.fillRect(0, 150, 150, 150);
repaint();
timeDelay(2000);
myBuffer.setColor(new Color(204, 200, 16));
myBuffer.fillRect(0, 150, 150, 150);
repaint();
}
else if(array[j] == 3)
{
System.out.println("runPattern3");
myBuffer.setColor(Color.RED);
myBuffer.fillRect(150, 0, 150, 150);
repaint();
timeDelay(2000);
myBuffer.setColor(new Color(209, 20, 20));
myBuffer.fillRect(150, 0, 150, 150);
repaint();
}
else if(array[j] == 4)
{
System.out.println("runPattern4");
myBuffer.setColor(Color.BLUE);
myBuffer.fillRect(150, 150, 150, 150);
repaint();
timeDelay(2000);
myBuffer.setColor(new Color(31, 97, 183));
myBuffer.fillRect(150, 150, 150, 150);
repaint();
}
else
{
System.out.println("runPatternError");
}
}
SimonSaysPanel.visible();
repaint();
}
是我称为无形方法的地方,而无形和可见的方法看起来像这样:
public static void invisible()
{
System.out.println("invisible");
button1.setEnabled(false);
button2.setEnabled(false);
button3.setEnabled(false);
button4.setEnabled(false);
}
public static void visible()
{
System.out.println("visible");
button1.setEnabled(true);
button2.setEnabled(true);
button3.setEnabled(true);
button4.setEnabled(true);
}
我尝试了设置,固定和固定的固定,我认为它们都没有起作用。我认为这是调用方法和输出打印为"可见"one_answers"隐形"的正确方法,因此我不知道怎么了。我认为可见和不可见的方法正确完成。
使用setopaque((以及setEnable((。