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 latihan12;
- import javax.swing.JRadioButton;
- import javax.swing.SwingUtilities;
- import javax.swing.ButtonGroup;
- /**
- *
- * @author steven
- */
- public class FrameJComboBox12 extends javax.swing.JFrame {
- /**
- * Creates new form FrameJComboBox12
- */
- public FrameJComboBox12() {
- initComponents();
- buttonGroup1.add(jRadioButton1);
- buttonGroup1.add(jRadioButton2);
- buttonGroup1.add(jRadioButton3);
- // kode agar jRadioButton2 langsung dipilih saat form di load atau dijalankan
- // jRadioButton2.setSelected(true);
- // jRadioButton2.setActionCommand("Tikus");
- }
- /**
- * 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();
- jRadioButton1 = new javax.swing.JRadioButton();
- jRadioButton2 = new javax.swing.JRadioButton();
- jRadioButton3 = new javax.swing.JRadioButton();
- jButton1 = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jRadioButton1.setFont(new java.awt.Font("Cantarell", 1, 15)); // NOI18N
- jRadioButton1.setText("Kucing");
- jRadioButton2.setFont(new java.awt.Font("Cantarell", 1, 15)); // NOI18N
- jRadioButton2.setText("Tikus");
- jRadioButton3.setFont(new java.awt.Font("Cantarell", 1, 15)); // NOI18N
- jRadioButton3.setText("Ikan");
- jButton1.setFont(new java.awt.Font("Cantarell", 1, 15)); // NOI18N
- jButton1.setText("Print");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- 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)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jRadioButton3)
- .addGap(0, 0, Short.MAX_VALUE))
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jRadioButton1)
- .addComponent(jRadioButton2))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 77, Short.MAX_VALUE)
- .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addContainerGap())
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jRadioButton1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jRadioButton2))
- .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jRadioButton3)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- jRadioButton1.setActionCommand("Kucing");
- jRadioButton2.setActionCommand("Tikus");
- jRadioButton3.setActionCommand("Ikan");
- System.out.println("Radio button yang dipilih: " + buttonGroup1.getSelection().getActionCommand());
- }
- /**
- * @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(FrameJComboBox12.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(FrameJComboBox12.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(FrameJComboBox12.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(FrameJComboBox12.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 FrameJComboBox12().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.ButtonGroup buttonGroup1;
- private javax.swing.JButton jButton1;
- private javax.swing.JRadioButton jRadioButton1;
- private javax.swing.JRadioButton jRadioButton2;
- private javax.swing.JRadioButton jRadioButton3;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement