Tester2009

java

Nov 26th, 2015
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.52 KB | None | 0 0
  1. class butangRadio extends JPanel implements ActionListener {
  2.     private JRadioButton radioSatu, radioDua, radioTiga;
  3.     private JLabel labelSatu, labelDua, labelTiga;
  4.    
  5.     public butangRadio() {
  6.         super.setLayout(new FlowLayout());
  7.         radioSatu = new JRadioButton("Label SATU");
  8.         radioDua = new JRadioButton("Label DUA");
  9.         radioTiga = new JRadioButton("Label TIGA");
  10.        
  11.         labelSatu = new JLabel("Tunjuk Label SATU");
  12.         labelDua = new JLabel("Tunjuk Label DUA");
  13.         labelTiga = new JLabel("Tunjuk Label TIGA");
  14.        
  15.         labelSatu.setVisible(false);
  16.         labelDua.setVisible(false);
  17.         labelTiga.setVisible(false);
  18.        
  19.         radioSatu.setActionCommand("rdio1");
  20.         radioDua.setActionCommand("rdio2");
  21.         radioTiga.setActionCommand("rdio3");
  22.        
  23.         radioSatu.addActionListener(this);
  24.         radioDua.addActionListener(this);
  25.         radioTiga.addActionListener(this);
  26.        
  27.         ButtonGroup butangDen = new ButtonGroup();
  28.         butangDen.add(radioSatu);
  29.         butangDen.add(radioDua);
  30.         butangDen.add(radioTiga);
  31.        
  32.         add(radioSatu);
  33.         add(radioDua);
  34.         add(radioTiga);
  35.        
  36.         add(labelSatu);
  37.         add(labelDua);
  38.         add(labelTiga);
  39.     }
  40.     public void actionPerformed(ActionEvent eS) {
  41.         if("rdio1".equals(eS.getActionCommand())) {
  42.             labelSatu.setVisible(true);
  43.             labelDua.setVisible(false);
  44.             labelTiga.setVisible(false);
  45.         }
  46.         if("rdio2".equals(eS.getActionCommand())) {
  47.             labelSatu.setVisible(false);
  48.             labelDua.setVisible(true);
  49.             labelTiga.setVisible(false);
  50.         }
  51.         if("rdio3".equals(eS.getActionCommand())) {
  52.             labelSatu.setVisible(false);
  53.             labelDua.setVisible(false);
  54.             labelTiga.setVisible(true);
  55.         }
  56.     }
  57. }   //  end of butangRadio class
  58.  
  59.  
  60.  
  61.  
  62.  
  63.     public static void main(String[] args) {
  64.         // TODO code application logic here
  65.         /*
  66.        
  67.         butang uji = new butang("TEKAN.LA");
  68.         uji.setSize(300, 150);
  69.         uji.setVisible(true);
  70.         uji.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  71.        
  72.         */
  73.        
  74.         JFrame kerangka = new JFrame("Guna butang radio");
  75.         kerangka.setSize(180, 300); // pixel X, pixel Y
  76.         kerangka.setVisible(true);
  77.         kerangka.add(new butangRadio());
  78.         kerangka.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  79.     }
Add Comment
Please, Sign In to add comment