Use of three components of the Java GUI

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.