Package Org.rui.swin;import Java.awt.flowlayout;import Javax.swing.jbutton;import javax.swing.jframe;import Org.rui.utils.swingconsole;public class Button1 extends Jframe{private JButton button1=new JButton ("Button1"), Button2=new JButton ("Button2");p ublic Button1 () {setlayout (New FlowLayout ()); Add (button1); add (button2);} public static void Main (string[] args) {Swingconsole.run (New Button1 (), 200,300);}}
Package Org.rui.swin;import Java.awt.flowlayout;import Java.awt.event.actionevent;import Java.awt.event.actionlistener;import Javax.swing.jbutton;import Javax.swing.jframe;import Javax.swing.JTextField; Import org.rui.utils.swingconsole;/** * Capture event * @author PC * */public class Button2 extends JFrame {private JButton BUT1 = New JButton ("Button1"), But2 = new JButton ("Button2"); JTextField TEXTF = new JTextField (10);//Listener Processing class Buttonlistener implements ActionListener {@Overridepublic void actionperformed (ActionEvent arg0) {//system.out.println ((JButton) Arg0.getsource ()). GetText ()); String name = ((JButton) Arg0.getsource ()). GetText (); Textf.settext (name);}} Private Buttonlistener bl = new Buttonlistener ();p ublic Button2 () {but1.addactionlistener (BL); But2.addactionlistener (BL); setlayout (new FlowLayout ()); Add (but1); add (but2); add (TEXTF);} public static void Main (string[] args) {Swingconsole.run (New Button2 (), 300, 200);}}
Package Org.rui.swin;import Java.awt.flowlayout;import Java.awt.event.actionevent;import Java.awt.event.actionlistener;import Java.util.hashmap;import Java.util.map;import Java.util.Map.Entry;import Javax.swing.jbutton;import Javax.swing.jframe;import Javax.swing.jscrollpane;import Javax.swing.JTextArea;import Org.rui.utils.swingconsole;public class TextArea extends JFrame {private JButton but1 = new JButton ("Add Data"), But2 = NE W JButton ("Clear Data");p rivate jtextarea t = new JTextArea (+);p rivate map<string, string> m = new Hashmap<s Tring, string> ();p ublic TextArea () {m.put ("CH", "China"), M.put ("EN", "United States"), M.put ("CC", "Kingdom of Heaven"); But1.addactionlistener ( New ActionListener () {@Overridepublic void actionperformed (ActionEvent e) {for (Entry En:m.entryset ()) {T.append ( En.getkey () + ":" +en.getvalue () + "\ n");}}); But2.addactionlistener (new ActionListener () {@Overridepublic void actionperformed (ActionEvent e) {t.settext ("");}}); SetLayout (New FlowLayout ()); Add (new JScrollPane (t)); Add (buT1); add (but2);} public static void Main (string[] args) {Swingconsole.run (New TextArea (), 500, 600);}}