I want to execute an ItemListener method if a JButton is pressed (as written in my ActionListener method). I feel like I'm missing something important, because as far as I know, you cannot have method within another method.
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JOptionPane;
    public class spelling2 extends JFrame {
        private static final long serialVersionUID = 1L;
        JFrame frame = new JFrame();
        JButton question1;
        JButton question2;
        private JCheckBox q1a1;
        private JCheckBox q1a2;
        private JCheckBox q1a3;
        public spelling2() {
        super("Question 1");
        setLayout(new FlowLayout());
        q1a1 = new JCheckBox("recipracate");
        q1a2 = new JCheckBox("reciprocate");
        q1a3 = new JCheckBox("reciprokate");
        add(q1a1);
        add(q1a2);
        add(q1a3);
        question1 = new JButton("Question 1");
        add(question1);
        question2 = new JButton("Question 2");
        add(question2);
        HandlerClass handler = new HandlerClass();
        q1a1.addItemListener(handler);
        q1a2.addItemListener(handler);
        q1a3.addItemListener(handler);
        question1.addActionListener(handler);
        question2.addActionListener(handler);
        }
        private class HandlerClass implements ActionListener, ItemListener {
        public void actionPerformed (ActionEvent event) {
        if (question1.isSelected()) {
            d
        }
        public void itemStateChanged (ItemEvent event) {
        if (q1a2.isSelected())
            JOptionPane.showMessageDialog(frame, "quintessence is the correct answer");
        else if (q1a1.isSelected())
            JOptionPane.showMessageDialog(frame, "That is the wrong answer");
        else if (q1a3.isSelected())
            JOptionPane.showMessageDialog(frame, "That is the wrong answer");
        }
    }
}
 
     
    