1.AWT Simple Example
Testframe.java
1 ImportJava.awt.Button;2 ImportJava.awt.Frame;3 Importjava.awt.event.ActionEvent;4 ImportJava.awt.event.ActionListener;5 Importjava.awt.event.WindowEvent;6 ImportJava.awt.event.WindowListener;7 8 Public classTestframeextendsFrame {9 Ten Public voidlaunch () { OneButton B =NewButton ("Buttons"); AB.addactionlistener (NewMyActionListener1 ()); -B.addactionlistener (NewMyActionListener2 ()); - This. Add (b); the This. Pack (); - - This. Addwindowlistener (NewWindowListener () { - + @Override - Public voidwindowclosing (windowevent e) { +System.out.println ("Windowclosing"); ASystem.exit (0); at } - - @Override - Public voidwindowclosed (windowevent e) { -System.out.println ("windowclosed"); - } in - @Override to Public voidwindowopened (windowevent e) { + //TODO auto-generated Method Stub - the } * $ @OverridePanax Notoginseng Public voidwindowiconified (windowevent e) { - //TODO auto-generated Method Stub the + } A the @Override + Public voidwindowdeiconified (windowevent e) { - //TODO auto-generated Method Stub $ $ } - - @Override the Public voidwindowactivated (windowevent e) { - //TODO auto-generated Method StubWuyi the } - Wu @Override - Public voidwindowdeactivated (windowevent e) { About //TODO auto-generated Method Stub $ - } - - }); A + This. setvisible (true); the } - $ Private classMyActionListener1ImplementsActionListener { the the @Override the Public voidactionperformed (ActionEvent e) { theSystem.out.println ("MyActionListener1"); - } in the } the About Private classMyActionListener2ImplementsActionListener { the the @Override the Public voidactionperformed (ActionEvent e) { +System.out.println ("MyActionListener2"); - } the Bayi } the the - Public Static voidMain (string[] args) { - NewTestframe (). Launch (); the } the}
2. Running Results
Java-awt Simple Example