1.Frame
In Java, aFrame is a control that can be loaded as a parent form for other swing controls. Case:
1 Packagecn.itcast_01;2 3 ImportJava.awt.Frame;4 5 Public classFramedemo {6 Public Static voidMain (string[] args) {7 //Create a Form object8 //frame f = new frame ();9 //Frame (String title)TenFrame f =NewFrame ("Brigitte"); One A //set the form title - //f.settitle ("HelloWorld"); - //Set Form size theF.setsize (400, 300);//units: Pixels - //set the form position -F.setlocation (400, 200); - + //invokes a method that sets the form to be visible - //f.show (); +F.setvisible (true); A at //System.out.println ("HelloWorld"); - } -}
The effect of running:
2. Optimization of the Code:
Packagecn.itcast_01;Importjava.awt.Dimension;ImportJava.awt.Frame;ImportJava.awt.Point; Public classFrameDemo2 { Public Static voidMain (string[] args) {//Creating ObjectsFrame f =NewFrame ("Relationship of Method call")); //Dimension (int width, int height)Dimension d = new Dimension (400, 300); F.setsize (d); //Point (int x, int y)Point p = New point (400, 200); f.setlocation (P); //one way to fix setbounds (int x, int y, int width, int height); //f.setbounds ( .); F.setvisible (true); }}
GUI Programming Note 04:gui (HelloWorld) Form case