change buttons backgroundcolor in awt

后端 未结 2 635
隐瞒了意图╮
隐瞒了意图╮ 2021-01-21 11:24

So i have a GUI program called Safe25. Basically, if you press the buttons in the right order which is \"15032018\" the program closes itself. If you input a correct number, let

2条回答
  •  伪装坚强ぢ
    2021-01-21 11:54

    have you red the javadoc for JButton?

    edit:

    Sorry i looked over your code to quickly. What your doing right now is setting the background color of every component in the current container. While your buttons array is global you could simply loop trough that collection again to get the correct components "the buttons" and setting the background color like so:

            for (JButton b : buttons) // line 75, i want this one
               b.setBackground(col); // to change the buttons backgroundcolor
            repaint(); // but it changes the frames backgroundcolor instead
    

提交回复
热议问题