Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
JFrame にカラー インジケーターを追加したいと考えています。ボタンをクリックすると赤くなり、ボタンをクリックしないと緑になります。これをどのように実装すればよいですか?
JLabel lblLed = new JLabel("•"); lblLed.setForeground(Color.Green);
JButton に ChangeListener を追加し、StateChanged() メソッドにこれを追加します。
if (buttonIsPressed) { lblLed.setForeground(Color.Red); } else { lblLed.setForeground(Color.Green); }