import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class LatGUI extends JFrame {
JLabel lbl=new JLabel("Belajar GUI");
JLabel label1=new JLabel("Nama Depan") ;
JLabel label2=new JLabel("Nama Belakang");
JLabel label3=new JLabel("Nama Lengkap");
JTextField text1=new JTextField();
JTextField text2=new JTextField();
JTextField text3=new JTextField();
JButton b1=new JButton("Proses");
JButton b2=new JButton("Hapus");
public LatGUI() {
add(lbl);
add(b1);
add(b2);
add(label1);
add(label2);
add(label3);
add(text1);
add(text2);
add(text3);
setLayout(null);
lbl.setBounds(100,20,100,25);
label1.setBounds(15,50,100,25);
label2.setBounds(15,80,100,25);
label3.setBounds(15,110,100,25);
text1.setBounds(120,50,100,25);
text2.setBounds(120,80,100,25);
text3.setBounds(120,110,100,25);
b1.setBounds(15,200,80,25);
b2.setBounds(120,200,80,25);
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
text3.setText(text1.getText()+" "+text2.getText());
}
});
b2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arum)
{
text1.setText("");
text2.setText("");
text3.setText("");
}
});
}
public static void main(String[] args) {
LatGUI latihan=new LatGUI();
latihan.setTitle("Latihan GUI");
latihan.setSize(300,300);
latihan.setVisible(true);
}
}
output dari program di atas adalah:
Langganan:
Postingan (Atom)