Visual Programming - Flow Layout2
Masih Contoh FlowLayout menggunakan klas javax.swing dan java.awt pada NetBeans, kali ini mencoba menumpuk beberapa panel pada panel lainnya...
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package latihan3;
import javax.swing.*;
import java.awt.*;
/**
*
* @author ASUS N43S
*/
public class Latihan3 {
public Latihan3()
{
JFrame frame = new JFrame();
frame.setSize(600,600);
frame.setLocation(600,600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
panel.setBackground(Color.WHITE);
frame.add(panel);
JPanel panelA = new JPanel();
panelA.setPreferredSize(new Dimension (600,50));
panelA.setBackground(Color.BLACK);
frame.add(panelA,BorderLayout.NORTH);
JPanel panel21 = new JPanel();
panel21.setPreferredSize(new Dimension (40,40));
JPanel panel22 = new JPanel();
panel22.setPreferredSize(new Dimension (40,40));
JPanel panel23 = new JPanel();
panel23.setPreferredSize(new Dimension (40,40));
panelA.add(panel21);
panelA.add(panel22);
panelA.add(panel23);
panelA.setLayout(new FlowLayout (FlowLayout.LEFT));
JPanel panelB = new JPanel();
panelB.setPreferredSize(new Dimension (200,500));
frame.add(panelB,BorderLayout.WEST);
panelB.setBackground(Color.RED);
JPanel panelC = new JPanel();
panelC.setPreferredSize(new Dimension (200,500));
frame.add(panelC,BorderLayout.CENTER);
panelC.setBackground(Color.GREEN);
JPanel panelD = new JPanel();
panelD.setPreferredSize(new Dimension (200,500));
frame.add(panelD,BorderLayout.EAST);
panelD.setBackground(Color.BLUE);
JPanel panel4 = new JPanel();
panel4.setPreferredSize(new Dimension (80,140));
JPanel panel5 = new JPanel();
panel5.setPreferredSize(new Dimension (80,140));
JPanel panel6 = new JPanel();
panel6.setPreferredSize(new Dimension (80,140));
panelC.add(panel4, new GridLayout(1,1));
panelC.add(panel5, new GridLayout(2,1));
panelC.add(panel6, new GridLayout(3,1));
JPanel panel7 = new JPanel();
panel7.setPreferredSize(new Dimension (80,140));
JPanel panel8 = new JPanel();
panel8.setPreferredSize(new Dimension (80,140));
JPanel panel9 = new JPanel();
panel9.setPreferredSize(new Dimension (80,140));
panelC.add(panel7, new GridLayout(1,2));
panelC.add(panel8, new GridLayout(2,2));
panelC.add(panel9, new GridLayout(3,2));
JPanel panelE = new JPanel();
panelE.setPreferredSize(new Dimension (600,50));
panelE.setBackground(Color.BLACK);
frame.add(panelE,BorderLayout.SOUTH);
JPanel panel10 = new JPanel();
panel10.setPreferredSize(new Dimension (40,40));
JPanel panel11 = new JPanel();
panel11.setPreferredSize(new Dimension (40,40));
JPanel panel12 = new JPanel();
panel12.setPreferredSize(new Dimension (40,40));
panelE.add(panel10);
panelE.add(panel11);
panelE.add(panel12);
panelE.setLayout(new FlowLayout (FlowLayout.RIGHT));
frame.setVisible(true);
}
public static void main(String[] args) {
// TODO code application logic here
new Latihan3 ();
}
}
Labels:
Coding