Jumat, 12 Desember 2008

Source Code Java penggunaan Flow Layout, BorderLayout, Panel

import java.awt.*;

class ComplexLayout extends Frame
{
public static void main(String args[])
{
ComplexLayout cl = new ComplexLayout();
Panel panelNorth = new Panel();
Panel panelCenter = new Panel();
Panel panelSouth = new Panel();

//panel utara
//panel menggunakan FlowLayout sebagai default
panelNorth.add(new Button("ONE"));
panelNorth.add(new Button("TWO"));
panelNorth.add(new Button("THREE"));

//panel tengah
panelCenter.setLayout(new GridLayout(4,4));
panelCenter.add(new TextField("1st"));
panelCenter.add(new TextField("2nd"));
panelCenter.add(new TextField("3rd"));
panelCenter.add(new TextField("4th"));

//Panel Selatan
panelSouth.setLayout(new BorderLayout());
panelSouth.add(new Checkbox("Choose Me !"), BorderLayout.CENTER);
panelSouth.add(new Checkbox("I am here !"), BorderLayout.EAST);
panelSouth.add(new Checkbox("Pick Me !"), BorderLayout.WEST);

//menambahkan panel pada kontainer Frame
//Frame menggunakan BorderLayout sebagai frame
cl.add(panelNorth, BorderLayout.NORTH);
cl.add(panelCenter, BorderLayout.CENTER);
cl.add(panelSouth, BorderLayout.SOUTH);
cl.setSize(300,300);
cl.setVisible(true);
}
}

Source code diambil dari Java Education Network Indonesia (JENI).

Tidak ada komentar: