Advertisement
albertoanggi

LA PERT 4 - PBO

Apr 8th, 2018
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.99 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4.  
  5. public class Form2 extends JFrame {
  6.     public Form2(){
  7.  
  8.         JPanel panel1 = new JPanel();
  9.         JPanel panel2 = new JPanel();
  10.         Container con = this.getContentPane();
  11.  
  12.         final JRadioButton RB1 = new JRadioButton("Anggota Satu");
  13.         final JRadioButton RB2 = new JRadioButton("Anggota Dua");
  14.         final JRadioButton RB3 = new JRadioButton("Anggota Tiga");
  15.         final JRadioButton RB4 = new JRadioButton("Anggota Empat");
  16.  
  17.         ButtonGroup radioBgroup = new ButtonGroup();
  18.  
  19.         final JLabel lblNPM   = new JLabel("NPM ");
  20.         final JLabel lblNama  = new JLabel("Nama ");
  21.         final JLabel lblJK    = new JLabel("Jenis Kelamin ");
  22.         final JLabel lblKelas = new JLabel("Kelas ");
  23.  
  24.         final JTextField txtNPM   = new JTextField(5);
  25.         final JTextField txtNama  = new JTextField(5);
  26.         final JTextField txtJK    = new JTextField(5);
  27.         final JTextField txtKelas = new JTextField(5);
  28.         final JButton cmdTampil   = new JButton("Tampil");
  29.         final JButton cmdKosong   = new JButton("Kosongkan");
  30.         final JButton cmdExit     = new JButton("Keluar");
  31.  
  32.         con.setLayout(new GridLayout(1,2));
  33.         panel1.setLayout(new GridLayout(3,3,2,5));
  34.         panel2.setLayout(new GridLayout(6,3,2,5));
  35.         panel1.setBorder(BorderFactory.createTitledBorder("Anggota"));
  36.         panel2.setBorder(BorderFactory.createTitledBorder("Data"));
  37.  
  38.         con.add(panel1);
  39.         con.add(panel2);
  40.  
  41.         radioBgroup.add(RB1);
  42.         radioBgroup.add(RB2);
  43.         radioBgroup.add(RB3);
  44.         radioBgroup.add(RB4);
  45.  
  46.         panel1.add(RB1);
  47.         panel1.add(RB2);
  48.         panel1.add(RB3);
  49.         panel1.add(RB4);
  50.  
  51.         panel2.add(lblNPM);
  52.         panel2.add(txtNPM);
  53.         panel2.add(lblNama);
  54.         panel2.add(txtNama);
  55.         panel2.add(lblJK);
  56.         panel2.add(txtJK);
  57.         panel2.add(lblKelas);
  58.         panel2.add(txtKelas);
  59.         panel2.add(cmdTampil);
  60.         panel2.add(cmdKosong);
  61.         panel2.add(cmdExit);
  62.  
  63.         cmdTampil.addActionListener(new ActionListener() {
  64.             public void actionPerformed(ActionEvent ae) {
  65.                 if (RB1.isSelected()){
  66.                     txtNPM.setText("50416855");
  67.                     txtNama.setText("Anggi Alberto");
  68.                     txtJK.setText("Laki - laki");
  69.                     txtKelas.setText("2IA22");
  70.                 }
  71.  
  72.                 if (RB2.isSelected()){
  73.                     txtNPM.setText("54214149");
  74.                     txtNama.setText("Bella");
  75.                     txtJK.setText("Perempuan");
  76.                     txtKelas.setText("3IA22");
  77.                 }
  78.  
  79.                 if (RB3.isSelected()){
  80.                     txtNPM.setText("51941520");
  81.                     txtNama.setText("Aris");
  82.                     txtJK.setText("Laki - laki");
  83.                     txtKelas.setText("3IA22");
  84.                 }
  85.  
  86.                 if (RB4.isSelected()){
  87.                     txtNPM.setText("53215265");
  88.                     txtNama.setText("Najmi");
  89.                     txtJK.setText("Perempuan");
  90.                     txtKelas.setText("3IA18");
  91.                 }
  92.             }
  93.         });
  94.  
  95.         cmdKosong.addActionListener(new ActionListener() {
  96.             public void actionPerformed(ActionEvent ae) {
  97.                 txtNPM.setText(" ");
  98.                 txtNama.setText(" ");
  99.                 txtJK.setText(" ");
  100.                 txtKelas.setText(" ");
  101.                 radioBgroup.clearSelection();
  102.             }
  103.         });
  104.  
  105.         cmdExit.addActionListener(new ActionListener() {
  106.             public void actionPerformed(ActionEvent ae) {
  107.                 System.exit(0);
  108.             }
  109.         });
  110.  
  111.         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  112.         this.setLocation(40,120);
  113.         this.setSize(520,230);
  114.         this.setVisible(true);
  115.     }
  116.  
  117.     public static void main(String[] args) {
  118.         new Form2();
  119.     }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement