Java Notes __ Form class/panel class/toolkit class

Source: Internet
Author: User

/*** Form Class*/ Public classMain { Public Static voidMain (string[] args) {MyFrame M1=NewMyFrame (); }}classMyFrameextendsframe{ PublicMyFrame () { This. Settitle ("My first Software");  This. SetSize (300,200);  This. SetBackground (Color.yellow);  This. setresizable (false);//resizing a form is not allowed         This. setlocation (300,300);  This. setlayout (NewFlowLayout ());//set the default layout of the form to "flow layout"//Add a button on a formButton B1 =NewButton ("Click Me.1");  This. Add (B1);  This. Add (NewButton ("Click Me.2"));  This. setvisible (true); }}

/*** Panel class (Faceplate Class), Component container*/ Public classMain { Public Static voidMain (string[] args) {Mypanel M1=NewMypanel (); }}classMypanelextendsframe{ PublicMypanel () { This. Settitle ("My first Software");  This. SetSize (600,400);  This. SetBackground (Color.yellow);  This. setresizable (false);//resizing a form is not allowed         This. setlocation (300,300);  This. setlayout (NewFlowLayout ());//set the default layout of the form to "flow layout"AddPanel ();  This. setvisible (true); }     Public voidAddPanel () {//The panel layout defaults to "pipelining layout"Panel P1 =NewPanel ();//Creating a Panel objectP1.setbackground (Color.green); P1.add (NewButton ("Click Me.1")); P1.add (NewButton ("Click Me.2")); P1.add (NewButton ("Click Me.3"));  This. Add (p1);//Add a panel to a form    }}

/*** Toolkit class: A toolkit for binding various components to the local system. */ Public classMain { Public Static voidMain (string[] args) {Mytoolkit M1=NewMytoolkit (); }}classMytoolkitextendsframe{ PublicMytoolkit () { This. Settitle ("My first Software");  This. SetSize (600,400);  This. SetBackground (Color.yellow); Toolkit T1= Toolkit.getdefaulttoolkit ();//Get Tool ObjectDimension D1 = t1.getscreensize ();//get the current screen size        DoubleW =d1.getwidth (); Doubleh =d1.getheight (); intx = (int) (W/2); inty = (int) (H/2);  This. setlocation (x-300,y-200); //Set the form icon (create a new package, put the picture in)URL url = This. GetClass (). getClassLoader (). GetResource ("pkg1/image/fish.jpg");//written pkg1.image.fish.jpg can't beImage IMA1 =t1.getimage (URL);  This. Seticonimage (IMA1);  This. setresizable (false);//resizing a form is not allowed         This. setlayout (NewFlowLayout ());//set the default layout of the form to "flow layout"                 This. setvisible (true); }}

Java Notes __ Form class/panel class/toolkit class

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.