import java.awt.*; import java.awt.event.*; import javax.swing.*; class StopGo{ static window w; public static void main(String[] args){ w = new window(); w.addWindowListener(new myWindowListener()); w.show(); } } class myWindowListener extends WindowAdapter{ public void windowClosing(WindowEvent e){System.exit(0);} } class window extends Frame implements ActionListener{ Label l; Button b; boolean state = true; // Constructor public window(){ setLayout(new GridLayout(2,1)); l = new Label(); b = new Button(); l.setBackground(Color.red); add(l); b.setLabel("Stop"); b.setFont(new Font("Serif",Font.ITALIC,24)); b.setBackground(Color.white); add(b); b.addActionListener(this); setSize(200,200); } public void actionPerformed(ActionEvent e){ if(e.getSource()==b){ switchState(); } } public void switchState(){ if(state){ b.setLabel("Go"); l.setBackground(Color.green); } else{ b.setLabel("Stop"); l.setBackground(Color.red); } state = !state; return; } }