import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Form2 extends JFrame {
public Form2(){
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
Container con = this.getContentPane();
final JRadioButton RB1 = new JRadioButton("Anggota Satu");
final JRadioButton RB2 = new JRadioButton("Anggota Dua");
final JRadioButton RB3 = new JRadioButton("Anggota Tiga");
final JRadioButton RB4 = new JRadioButton("Anggota Empat");
ButtonGroup radioBgroup = new ButtonGroup();
final JLabel lblNPM = new JLabel("NPM ");
final JLabel lblNama = new JLabel("Nama ");
final JLabel lblJK = new JLabel("Jenis Kelamin ");
final JLabel lblKelas = new JLabel("Kelas ");
final JTextField txtNPM = new JTextField(5);
final JTextField txtNama = new JTextField(5);
final JTextField txtJK = new JTextField(5);
final JTextField txtKelas = new JTextField(5);
final JButton cmdTampil = new JButton("Tampil");
final JButton cmdKosong = new JButton("Kosongkan");
final JButton cmdExit = new JButton("Keluar");
con.setLayout(new GridLayout(1,2));
panel1.setLayout(new GridLayout(3,3,2,5));
panel2.setLayout(new GridLayout(6,3,2,5));
panel1.setBorder(BorderFactory.createTitledBorder("Anggota"));
panel2.setBorder(BorderFactory.createTitledBorder("Data"));
con.add(panel1);
con.add(panel2);
radioBgroup.add(RB1);
radioBgroup.add(RB2);
radioBgroup.add(RB3);
radioBgroup.add(RB4);
panel1.add(RB1);
panel1.add(RB2);
panel1.add(RB3);
panel1.add(RB4);
panel2.add(lblNPM);
panel2.add(txtNPM);
panel2.add(lblNama);
panel2.add(txtNama);
panel2.add(lblJK);
panel2.add(txtJK);
panel2.add(lblKelas);
panel2.add(txtKelas);
panel2.add(cmdTampil);
panel2.add(cmdKosong);
panel2.add(cmdExit);
cmdTampil.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
if (RB1.isSelected()){
txtNPM.setText("50416855");
txtNama.setText("Anggi Alberto");
txtJK.setText("Laki - laki");
txtKelas.setText("2IA22");
}
if (RB2.isSelected()){
txtNPM.setText("54214149");
txtNama.setText("Bella");
txtJK.setText("Perempuan");
txtKelas.setText("3IA22");
}
if (RB3.isSelected()){
txtNPM.setText("51941520");
txtNama.setText("Aris");
txtJK.setText("Laki - laki");
txtKelas.setText("3IA22");
}
if (RB4.isSelected()){
txtNPM.setText("53215265");
txtNama.setText("Najmi");
txtJK.setText("Perempuan");
txtKelas.setText("3IA18");
}
}
});
cmdKosong.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
txtNPM.setText(" ");
txtNama.setText(" ");
txtJK.setText(" ");
txtKelas.setText(" ");
radioBgroup.clearSelection();
}
});
cmdExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
System.exit(0);
}
});
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocation(40,120);
this.setSize(520,230);
this.setVisible(true);
}
public static void main(String[] args) {
new Form2();
}
}