Development GUI Program General step: 1, import java.awt.* of introduction package; Import javax.swing.*; 2, inherit JFrame public class Demo3 extends JFrame {} 3, define required components//3. Define Components JButton jb1,jb2,jb3,jb4,jb5; int size=9; JButton Jbs[]=new Jbutton[size]; First allocate initial space 4, create component//4. Create Component Jb1=new JButton ("Middle"); Create a component for (int i=0;i<size;i++) {jbs[i]=new JButton (string.valueof (i)); } 5, set layout Manager//Set layout manager, default is the Boundary Layout manager this.setlayout (new FlowLayout (Flowlayout.left));//Flow Layout This.add (JB1, Borderlayout.center); Border Layout this.setlayout (new GridLayout (3,3,10,10)); Grid layout this.setlayout (null); Cancel Layout Manager 6, Add components//Add Components This.add (JB1); This.add (JB2); 7. Set form Properties//Set form Properties This.settitle ("Flow layout case"); Set the form title This.setsize (300, 200); Set the form size this.setlocation (200, 400); Set initial position this.setdefaultcloseoperation (jframe.exit_on_close); Close the virtual machine when the form is closed//prevents the user from changing the form size this.setresizable (false); 7. Display Form this.setvisible (true); 8. Display form create component with array://define component int size=9; JButton Jbs[]=new Jbutton[size]; Array to first allocate the initial emptyBetween//Create component for (int i=0;i<size;i++) {jbs[i]=new JButton (string.valueof (i)); }//Add component for (int i=0;i<size;i++) {this.add (jbs[i]);
Java Development GUI Program general steps: