Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class butangRadio extends JPanel implements ActionListener {
- private JRadioButton radioSatu, radioDua, radioTiga;
- private JLabel labelSatu, labelDua, labelTiga;
- public butangRadio() {
- super.setLayout(new FlowLayout());
- radioSatu = new JRadioButton("Label SATU");
- radioDua = new JRadioButton("Label DUA");
- radioTiga = new JRadioButton("Label TIGA");
- labelSatu = new JLabel("Tunjuk Label SATU");
- labelDua = new JLabel("Tunjuk Label DUA");
- labelTiga = new JLabel("Tunjuk Label TIGA");
- labelSatu.setVisible(false);
- labelDua.setVisible(false);
- labelTiga.setVisible(false);
- radioSatu.setActionCommand("rdio1");
- radioDua.setActionCommand("rdio2");
- radioTiga.setActionCommand("rdio3");
- radioSatu.addActionListener(this);
- radioDua.addActionListener(this);
- radioTiga.addActionListener(this);
- ButtonGroup butangDen = new ButtonGroup();
- butangDen.add(radioSatu);
- butangDen.add(radioDua);
- butangDen.add(radioTiga);
- add(radioSatu);
- add(radioDua);
- add(radioTiga);
- add(labelSatu);
- add(labelDua);
- add(labelTiga);
- }
- public void actionPerformed(ActionEvent eS) {
- if("rdio1".equals(eS.getActionCommand())) {
- labelSatu.setVisible(true);
- labelDua.setVisible(false);
- labelTiga.setVisible(false);
- }
- if("rdio2".equals(eS.getActionCommand())) {
- labelSatu.setVisible(false);
- labelDua.setVisible(true);
- labelTiga.setVisible(false);
- }
- if("rdio3".equals(eS.getActionCommand())) {
- labelSatu.setVisible(false);
- labelDua.setVisible(false);
- labelTiga.setVisible(true);
- }
- }
- } // end of butangRadio class
- public static void main(String[] args) {
- // TODO code application logic here
- /*
- butang uji = new butang("TEKAN.LA");
- uji.setSize(300, 150);
- uji.setVisible(true);
- uji.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- */
- JFrame kerangka = new JFrame("Guna butang radio");
- kerangka.setSize(180, 300); // pixel X, pixel Y
- kerangka.setVisible(true);
- kerangka.add(new butangRadio());
- kerangka.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
Add Comment
Please, Sign In to add comment