import Java.awt.flowlayout;import javax.swing.jbutton;import javax.swing.JFrame;//1. Inheriting the JFrame class//2. Defining components at the top//3. Creating a component in the construction method//4. Adding components in the construction method//5. Setting Form Properties//6. Display the form//7. Creating an object in the main function Public classFLOWLAYOUT1 extends jframe{JButton [] a={NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; Public Static voidMain (string[] args) {//TODO auto-generated Method StubFLOWLAYOUT1 f1=Newflowlayout1 (); } Publicflowlayout1 () {a[0]=NewJButton ("melon Seeds"); a[1]=NewJButton ("Plum"); a[2]=NewJButton ("Watermelon"); a[3]=NewJButton ("Strawberry"); a[4]=NewJButton ("Banana"); a[5]=NewJButton ("Apple"); a[6]=NewJButton ("Chestnut"); a[7]=NewJButton ("Cucumber"); //a[8]=new JButton ("Grape"); This. setlayout (NewFlowLayout (flowlayout.leading));//The default is the boundary layout, if you want to change to another layout, plus This. Add (a[0]); This. Add (a[1]); This. Add (a[2]); This. Add (a[3]); This. Add (a[4]); This. Add (a[5]); This. Add (a[6]); This. Add (a[7]); This. Settitle ("Flow Layout FlowLayout"); This. SetSize ( -, the); This. setlocation ( -, the); This. setresizable (true); This. Setdefaultcloseoperation (Jframe.exit_on_close); This. setvisible (true); }}
Swing's FlowLayout