Contoh FlowLayout menggunakan klas javax.swing dan java.awt pada NetBeans
package latihan.pkg1;
/**
*
* @author ASUS N43S
*/
import java.awt.*;
import javax.swing.*;
public class Latihan1 {
/**
* @param args the command line arguments
*/
public Latihan1 ()
{
JFrame frame = new JFrame ("Contoh FlowLayout");
frame.setSize (300,300);
frame.setLocation(300, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel ();
frame.add(panel);
panel.setBackground(Color.BLACK);
JPanel panel1 = new JPanel ();
panel1.setPreferredSize(new Dimension (300,50));
panel1.setBackground(Color.RED);
panel.add(panel1);
JPanel panel2 = new JPanel ();
panel2.setPreferredSize (new Dimension (300,50));
panel2.setBackground(Color.WHITE);
panel.add(panel2);
JPanel panel3 = new JPanel ();
panel3.setPreferredSize (new Dimension (300,50));
panel3.setBackground(Color.BLUE);
panel.add(panel3);
frame.setVisible(true);
}
public static void main(String[] args) {
// TODO code application logic here
new Latihan1 ();
}
}