//notepad gg.java // javac gg.java // java gg import java.awt.*; import java.awt.event.*; public class gg { Button c = new Button("bye"); public static void main(String [ ] xxx) { new gg( ); } gg( ) { Frame f = new Frame("2009"); f.setSize(500, 300); f.setVisible(true); // f.show( ); Panel p = new Panel( ); Button b = new Button("AAAAA"); p.add(b); p.add(new Button("NoNameBBB")); f.add(p, "North"); p.add(c); // bye button Button s = new Button("Ha ha ha"); f.add(s, "South"); s.setBackground(Color.red); f.validate( ); YLau ar3 = new YLau(b); b.addActionListener(ar3); f.addWindowListener(ar3); c.addActionListener(ar3); } class YLau extends WindowAdapter implements ActionListener { Button x; // call it this.x if necessary YLau(Button x) { this.x = x; } int tog = 0; public void actionPerformed(ActionEvent e) { System.out.print(" ActionEvent "); if(e.getSource( ) == x) { if(tog == 0) c.setBackground(Color.green); else c.setBackground(Color.blue); tog = 1 - tog; } if(e.getSource( ) == c) System.exit(0); } public void windowClosing(WindowEvent e) { Frame w = new Frame("Ha ha ha ... "); w.setSize(300,300); w.setVisible(true); w.addWindowListener(this); }//windowClosing }// YLau } // class gg