Berikut ini adalah bagaimana penggunaan Layout pada Java :
import
java.awt.*; \\ mengimport dari package java.awt
import javax.swing.*; \\ mengimport dari package javax.swing
class Multilayout extends JFrame {
\\ Mendeklarasikan Btnnol,Btn1, Btn2, Btn3, Btn4,Btn5, Btn6, Btn7, Btn8, Btn9, Btn10, Btn11
import javax.swing.*; \\ mengimport dari package javax.swing
class Multilayout extends JFrame {
\\ Mendeklarasikan Btnnol,Btn1, Btn2, Btn3, Btn4,Btn5, Btn6, Btn7, Btn8, Btn9, Btn10, Btn11
JButton Btnnol,Btn1, Btn2, Btn3, Btn4,Btn5,
Btn6, Btn7, Btn8, Btn9, Btn10, Btn11 ;
JLabel lNmFL,lNmNL,lNmGL;
JPanel PANEL1,PANEL2,PANEL3;
public layout() {
setTitle("MULTI LAYOUT"); \\ Membuat Nama Layout
JLabel lNmFL= new JLabel("Flow Layout" );
JButton Btnnol=new JButton ("0");
JButton Btn1=new JButton ("1");
JButton Btn2=new JButton ("2");
JButton Btn3=new JButton ("3");
JLabel lNmNL= new JLabel("None Layout" );
JButton Btn4=new JButton ("4");
JButton Btn5=new JButton ("5");
JButton Btn6=new JButton ("6");
JButton Btn7=new JButton ("7");
JLabel lNmGL= new JLabel("Grid Layout" );
JButton Btn8=new JButton ("8");
JButton Btn9=new JButton ("9");
JButton Btn10=new JButton ("10");
JButton Btn11=new JButton ("11");
PANEL1 = new JPanel();
PANEL2 = new JPanel();
PANEL3 = new JPanel();
setLayout(null);
add(lNmFL);
add(lNmNL);
add(lNmGL);
add(PANEL1);
add(PANEL2);
add(PANEL3);
lNmFL.setBounds(15,10,100,20);
lNmNL.setBounds(220,10,100,20);
lNmGL.setBounds(320,10,100,20);
PANEL1.setBounds(5,30,200,40);
PANEL2.setBounds(215,30,200,100);
PANEL3.setBounds(320,30,200,150);
PANEL1.setLayout(new FlowLayout( ));
PANEL1.add(Btnnol);
PANEL1.add(Btn1);
PANEL1.add(Btn2);
PANEL1.add(Btn3);
PANEL2.setLayout(null);
PANEL2.add(Btn4);
PANEL2.add(Btn5);
PANEL2.add(Btn6);
PANEL2.add(Btn7);
Btn4.setBounds(5,10,70,20);
Btn5.setBounds(5,30,70,20);
Btn6.setBounds(5,50,70,20);
Btn7.setBounds(5,70,70,20);
PANEL3.setLayout(new GridLayout(2,1));
PANEL3.add(Btn8);
PANEL3.add(Btn9);
PANEL3.add(Btn10);
PANEL3.add(Btn11);
PANEL3.setSize(100,100);
setSize(500,200);
setDefaultCloseOperation(3);
}
}
JLabel lNmFL,lNmNL,lNmGL;
JPanel PANEL1,PANEL2,PANEL3;
public layout() {
setTitle("MULTI LAYOUT"); \\ Membuat Nama Layout
JLabel lNmFL= new JLabel("Flow Layout" );
JButton Btnnol=new JButton ("0");
JButton Btn1=new JButton ("1");
JButton Btn2=new JButton ("2");
JButton Btn3=new JButton ("3");
JLabel lNmNL= new JLabel("None Layout" );
JButton Btn4=new JButton ("4");
JButton Btn5=new JButton ("5");
JButton Btn6=new JButton ("6");
JButton Btn7=new JButton ("7");
JLabel lNmGL= new JLabel("Grid Layout" );
JButton Btn8=new JButton ("8");
JButton Btn9=new JButton ("9");
JButton Btn10=new JButton ("10");
JButton Btn11=new JButton ("11");
PANEL1 = new JPanel();
PANEL2 = new JPanel();
PANEL3 = new JPanel();
setLayout(null);
add(lNmFL);
add(lNmNL);
add(lNmGL);
add(PANEL1);
add(PANEL2);
add(PANEL3);
lNmFL.setBounds(15,10,100,20);
lNmNL.setBounds(220,10,100,20);
lNmGL.setBounds(320,10,100,20);
PANEL1.setBounds(5,30,200,40);
PANEL2.setBounds(215,30,200,100);
PANEL3.setBounds(320,30,200,150);
PANEL1.setLayout(new FlowLayout( ));
PANEL1.add(Btnnol);
PANEL1.add(Btn1);
PANEL1.add(Btn2);
PANEL1.add(Btn3);
PANEL2.setLayout(null);
PANEL2.add(Btn4);
PANEL2.add(Btn5);
PANEL2.add(Btn6);
PANEL2.add(Btn7);
Btn4.setBounds(5,10,70,20);
Btn5.setBounds(5,30,70,20);
Btn6.setBounds(5,50,70,20);
Btn7.setBounds(5,70,70,20);
PANEL3.setLayout(new GridLayout(2,1));
PANEL3.add(Btn8);
PANEL3.add(Btn9);
PANEL3.add(Btn10);
PANEL3.add(Btn11);
PANEL3.setSize(100,100);
setSize(500,200);
setDefaultCloseOperation(3);
}
}
public
class TugasLayout {
public static void main(String[ ] args) {
Multilayout m = new Multilayout ( );
}
}
public static void main(String[ ] args) {
Multilayout m = new Multilayout ( );
}
}