I
want to share how to CODING FOR MYLAYOUT in J2SE. You can use this code
but if you copy this code and paste in your blog/website, please insert this
link of article.
import javax.swing.*;
import java.awt.GridLayout;
public class MyLayout extends JFrame {
public MyLayout() {
JLabel lbl0 = new JLabel("NIM :");
lbl0.setPreferredSize(new Dimension(95, 32));
JTextField txtNIM = new JTextField(15);
JPanel pnlNIM = new JPanel();
pnlNIM.setLayout(new FlowLayout(FlowLayout.LEFT, 15, 10));
pnlNIM.add(lbl0);
pnlNIM.add(txtNIM);
JLabel lbl1 = new JLabel("NAMA :");
lbl1.setPreferredSize(new Dimension(95, 32));
JTextField txtNama = new JTextField(15);
JPanel pnlNama = new JPanel();
pnlNama.setLayout(new FlowLayout(FlowLayout.LEFT, 15, 10));
pnlNama.add(lbl1);
pnlNama.add(txtNama);
JLabel lbl2 = new JLabel("JENIS KELAMIN :");
lbl2.setPreferredSize(new Dimension(95, 22));
JTextField txtAlamat = new JTextField(15);
JPanel pnlAlamat = new JPanel();
pnlAlamat.setLayout(new FlowLayout(FlowLayout.LEFT, 15, 10));
pnlAlamat.add(lbl2);
pnlAlamat.add(txtAlamat);
JPanel pnlBtn = new JPanel();
JButton btnOK = new JButton("TAMPIL");
JButton btnCancel = new JButton("HAPUS");
JButton btnmetu = new JButton("KELUAR");
pnlBtn.add(btnOK);
pnlBtn.add(btnCancel);
pnlBtn.add(btnmetu);
JPanel pnlCenter = new JPanel();
pnlCenter.setLayout(new GridLayout(5, 20, 20, 0));
pnlCenter.add(pnlNIM, 0);
pnlCenter.add(pnlNama, 1);
pnlCenter.add(pnlAlamat, 2);
pnlCenter.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createEmptyBorder(0,90,-3,0),
BorderFactory.createEtchedBorder()));
add(pnlCenter, "North");
add(pnlCenter, "Center");
add(pnlBtn, "South");
setTitle("PROGRAM DATA MAHASISWA");
pack();
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new MyLayout();
}
});
}
}
0 komentar:
Posting Komentar