Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package latihan13;
- import java.awt.BorderLayout;
- import java.awt.GridLayout;
- import java.util.Enumeration;
- import javax.swing.AbstractButton;
- import javax.swing.BorderFactory;
- import javax.swing.ButtonGroup;
- import javax.swing.JCheckBox;
- import javax.swing.JCheckBoxMenuItem;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.JRadioButton;
- import javax.swing.JRadioButtonMenuItem;
- import javax.swing.JToggleButton;
- import javax.swing.border.Border;
- /**
- *
- * @author steven
- */
- public class RadioButton1 extends javax.swing.JFrame {
- /**
- * Creates new form RadioButton1
- */
- public RadioButton1() {
- initComponents();
- AbstractButton abstract1 = jToggleButton1;
- buttonGroup1.add(abstract1);
- AbstractButton abstract2 = jRadioButton1;
- buttonGroup1.add(abstract2);
- AbstractButton abstract3 = jCheckBox1;
- buttonGroup1.add(abstract3);
- buttonGroup1.setSelected(abstract1.getModel(), true);
- Enumeration elements = buttonGroup1.getElements();
- while(elements.hasMoreElements()){
- AbstractButton tombol = (AbstractButton)elements.nextElement();
- if(tombol.isSelected()){
- System.out.println("Maka juaranya adalah : " + tombol.getText());
- }
- }
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- buttonGroup1 = new javax.swing.ButtonGroup();
- jToggleButton1 = new javax.swing.JToggleButton();
- jRadioButton1 = new javax.swing.JRadioButton();
- jCheckBox1 = new javax.swing.JCheckBox();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jToggleButton1.setText("jToggleButton1");
- jRadioButton1.setText("jRadioButton1");
- jCheckBox1.setText("jCheckBox1");
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jToggleButton1)
- .addComponent(jRadioButton1)
- .addComponent(jCheckBox1))
- .addContainerGap(268, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jToggleButton1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jRadioButton1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jCheckBox1)
- .addContainerGap(198, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(RadioButton1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(RadioButton1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(RadioButton1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(RadioButton1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new RadioButton1().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.ButtonGroup buttonGroup1;
- private javax.swing.JCheckBox jCheckBox1;
- private javax.swing.JRadioButton jRadioButton1;
- private javax.swing.JToggleButton jToggleButton1;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement