0

Hi Everyone,

I am playing around with some Java following some tutorial online and ran into a problem that I cant seem to figure out. In the code below, inside of the groupButton method I get the error 'JRadioButton1,JRadioButton2 and JRadioButton3 cannot be resolved to a variable'. Can you please help me identify the problem?

package form_controls_lesson;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.AbstractButton;
import javax.swing.ButtonGroup;
import javax.swing.JComboBox;
import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.DefaultComboBoxModel;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.TextField;

import javax.swing.JTextField;

import java.awt.Color;

import javax.swing.JCheckBox;

import java.awt.TextArea;

import javax.swing.JRadioButton;


@SuppressWarnings("serial")
public class FormObjects extends JFrame {

    private JPanel contentPane;
    private JTextField txtComboBoxItem;
    private final TextArea taOne = new TextArea();


    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    FormObjects frame = new FormObjects();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
    private void groupButton(){
        ButtonGroup bg1 = new ButtonGroup();

        bg1.add(jRadioButton1);
        bg1.add(jRadioButton2);
        bg1.add(jRadioButton3);
    }

    /**
     * Create the frame.
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public FormObjects() {
        groupButton();      
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 498, 466);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);

        final JComboBox comboOne = new JComboBox();
        comboOne.setForeground(Color.BLUE);
        comboOne.setBackground(Color.CYAN);
        comboOne.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent arg0) {
                String itemText=(String)comboOne.getSelectedItem();
                txtComboBoxItem.setText(itemText);

            }

        });     

        comboOne.setModel(new DefaultComboBoxModel(new String[] {"C Sharp", "Java", "PHP", "Visual Basic .NET"}));
        comboOne.setBounds(12, 13, 120, 22);
        contentPane.add(comboOne);

        JButton btnComboBox = new JButton("Get Drop Down Item");
        btnComboBox.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
            }
        });
        btnComboBox.setBounds(144, 13, 149, 22);
        contentPane.add(btnComboBox);

        txtComboBoxItem = new JTextField();
        txtComboBoxItem.setBounds(305, 13, 116, 22);
        contentPane.add(txtComboBoxItem);
        txtComboBoxItem.setColumns(10);

        JPanel panel = new JPanel();
        panel.setBounds(12, 69, 120, 139);
        contentPane.add(panel);
        panel.setLayout(null);

        final JCheckBox jCheckBox1 = new JCheckBox("C Sharp");
        jCheckBox1.setBounds(0, 9, 113, 25);
        panel.add(jCheckBox1);

        final JCheckBox jCheckBox2 = new JCheckBox("Java");
        jCheckBox2.setBounds(0, 41, 113, 25);
        panel.add(jCheckBox2);

        final JCheckBox jCheckBox3 = new JCheckBox("PHP");
        jCheckBox3.setBounds(0, 71, 113, 25);
        panel.add(jCheckBox3);

        final JCheckBox jCheckBox4 = new JCheckBox("Visual Basic");
        jCheckBox4.setBounds(0, 101, 113, 25);
        panel.add(jCheckBox4);

        JButton btnCheckBoxes = new JButton("Selected Items");
        btnCheckBoxes.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String s1="";
                if (jCheckBox1.isSelected()){
                    s1=s1+" "+jCheckBox1.getText()+ '\n';
                }
                if (jCheckBox2.isSelected()){
                    s1=s1+" "+jCheckBox2.getText()+ '\n';
                }
                if (jCheckBox3.isSelected()){
                    s1=s1+" "+jCheckBox3.getText()+ '\n';
                }
                if (jCheckBox4.isSelected()){
                    s1=s1+" "+jCheckBox4.getText()+ '\n';
                } 
                taOne.setText(s1);  }

            });
        btnCheckBoxes.setBounds(162, 127, 120, 22);
        contentPane.add(btnCheckBoxes);
        taOne.setBounds(288, 69, 133, 139);
        contentPane.add(taOne);

        JPanel panel_1 = new JPanel();
        panel_1.setBounds(12, 254, 143, 108);
        contentPane.add(panel_1);
        panel_1.setLayout(null);

        JRadioButton jRadioButton2 = new JRadioButton("Debit Card");
        jRadioButton2.setBounds(24, 39, 127, 25);
        panel_1.add(jRadioButton2);

        JRadioButton jRadioButton1 = new JRadioButton("Credit Card");
        jRadioButton1.setBounds(24, 9, 93, 25);
        panel_1.add(jRadioButton1);

        JRadioButton jRadioButton3 = new JRadioButton("PayPal");
        jRadioButton3.setBounds(24, 69, 127, 25);
        panel_1.add(jRadioButton3);



    }




}
2
Contributors
1
Reply
12
Views
2 Years
Discussion Span
Last Post by cgeier
0

jRadioButton1, jRadioButton2, jRadioButton3 don't exist in "groupButton". They are only in the constructor.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.