Link:
Http://blog.sina.com.cn/s/blog_614f347b0101egah.html
Code:
Importjava.awt.*;Importjava.awt.event.*;classframedemo{//define the components required for the form to facilitate other function references PrivateFrame F; PrivateButton btn;//Button PrivateButton btn1; PrivateLabel label;//label PublicTextArea Ta;//Text Area//ConstructorsFramedemo () {init (); } Public voidinit () {f=NewFRAME ("My Forms Frame"); /*(all static property settings)*/ //basic settings for a form//f.setsize (300,200); //f.setlocation (100,200);F.setbounds (100,50,1200,1000); F.setlayout (NewFlowLayout ()); F.setbackground (Color.gray); //component (Custom)BTN =NewButton ("Exit"); BTN1=NewButton ("1"); Label=NewLabel ("This is a text", Label.center); Ta=NewTextArea ("Test", 30,70,1);//The last parameter is set to show the scroll bar, 1 shows the vertical scrollbar, 2 shows the horizontal scroll bar, and 0 is all displayed. //Component Property SettingsLabel.setbackground (Color.pink); Label.setfont (NewFont ("Dialog", Font.Bold, 12)); Label.setsize (300,200); //add a component to a framef.add (label); F.add (TA); F.add (BTN); F.add (BTN1); //Load Form events (all response events)MyEvent (); //Show FormF.setvisible (true); } Private voidMyEvent () {/*rule: Xxxlistener (new Xxxadapter ()) Xxxevent e*/ //form Close EventF.addwindowlistener (NewWindowadapter () { Public voidwindowclosing (windowevent e) {system.exit (0); } }); //Button Response EventBtn.addactionlistener (NewActionListener () { Public voidactionperformed (ActionEvent e) {//Button ResponseSystem.out.println ("Exit, Button dry"); System.exit (0); } }); Btn1.addactionlistener (NewActionListener () { Public voidactionperformed (ActionEvent e) {//Button 1 ResponseString tacontent =Ta.gettext (); Label.settext (tacontent); } }); } Public Static voidMain (string[] args) {NewFramedemo (); }}
Only two buttons were implemented, and when the button clicked, the text of the text area was captured and displayed on the label.
OK: the label label size cannot be set due to defect type of component in AWT, SetSize no effect
Use of three components of the Java GUI