Note that there are some explanatory texts on larger screens.

plurals
  1. PONot sure what this issue is?
    primarykey
    data
    text
    <p>I am required me to use RadioButtons and Checkboxes in my Java program so the user can easily select the options they would like to use (It is a "gas station").</p> <pre><code>import javax.swing.*; import java.awt.*; import java.awt.event.*; public class New_Gas_Bar extends JFrame { public JPanel panel1,panel2,panel3,panel4,panel5; public JLabel main1, main2, main3; public JLabel gasBar,total; public JButton button1,button2,button3,button4; public JRadioButton bronzeG,silverG,goldG,selfS,fullS,fullService,selfService; public JCheckBox oilC,windWash,windClean; static double fullCost,selfCost; public New_Gas_Bar() { super (" New Gas Bar"); setSize(640,640); Container container = getContentPane(); panel1=new JPanel(); panel2=new JPanel(); panel1.setBackground(new Color(107,202,226)); panel1.setLayout(new GridLayout(7,1)); main1 = new JLabel (" Gas Bar Project "); main2 = new JLabel (" ICS4U0 - September 2013"); main3 = new JLabel (" "); button1 = new JButton ("Gas Station"); button2 = new JButton ("Car Wash"); button3 = new JButton ("Total"); button4 = new JButton ("Exit"); panel2.setBackground(new Color(144,160,170)); panel2.setLayout(new GridLayout(4,1)); panel2.add (button1); panel2.add (button2); panel2.add (button3); panel2.add (button4); panel1.add (main1); panel1.add (main2); //panel2.add(gasBar); //panel3.add(total); container.setLayout(new BorderLayout()); container.add(panel1,BorderLayout.NORTH); container.add(panel2,BorderLayout.CENTER); ButtonHandler handler = new ButtonHandler (); button1.addActionListener (handler); button2.addActionListener (handler); button3.addActionListener (handler); button4.addActionListener (handler); ButtonGroup serveStyle = new ButtonGroup(); fullS = new JRadioButton ("Full Serve"); selfS = new JRadioButton ("Self Serve"); serveStyle.add (fullS); serveStyle.add (selfS); ButtonGroup serveGas = new ButtonGroup(); bronzeG = new JRadioButton("Bronze Service"); silverG = new JRadioButton("Silver Service"); goldG = new JRadioButton("Gold Service"); serveGas.add (bronzeG); serveGas.add (silverG); serveGas.add (goldG); oilC = new JCheckBox("Oil Change"); windWash = new JCheckBox("Windshield Wash"); windClean = new JCheckBox("Windshield Cleaning"); RadioButtonHandler radioHand = new RadioButtonHandler (); bronzeG.addItemListener (radioHand); CheckBoxHandler checkHand = new CheckBoxHandler(); oilC.addItemListener (checkHand); setVisible(true); pack(); } public static void main (String [] args) { New_Gas_Bar application = new New_Gas_Bar(); } public class ButtonHandler implements ActionListener { public void actionPerformed (ActionEvent event) { if (event.getSource () == button1) { panel1.setVisible(true); panel2.setVisible(false); panel3.setVisible(true); panel4.setVisible(false); panel5.setVisible(false); } else if (event.getSource () == button2) { } else if (event.getSource () == button3) { } else if (event.getSource () == button4) { System.exit(0); } } } public class RadioButtonHandler implements ActionListener { public void actionPerformed (ActionEvent event) { if (event.getSource () == fullS) { } else if (event.getSource () == selfS) { } if (event.getSource () == bronzeG) { } else if (event.getSource () == silverG) { } else if (event.getSource () == goldG) { } } } public class CheckBoxHandler implements ActionListener { public void actionPerformed (ActionEvent event) { if (event.getSource () == checkBox1) { } else if (event.getSource () == checkBox2) { } else if (event.getSource () == checkBox3) { } } } } } </code></pre> <p>The error I am getting is at this part</p> <pre><code>RadioButtonHandler radioHand = new RadioButtonHandler (); bronzeG.addItemListener (radioHand); CheckBoxHandler checkHand = new CheckBoxHandler(); oilC.addItemListener (checkHand); </code></pre> <p>I do not understand why at <code>bronzeG.addItemListener</code>, it says </p> <pre><code>addItemListener(java.awt.event.ItemListener) in javax.swing.AbstractButton cannot be applied to (New_Gas_Bar.RadioButtonHandler) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload