/*** 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