Error in Java when creating private class

0

Every time I try to create a private class in java I can not. Follow the complete code below.

package execucaodeprogramas;

import java.awt.event.ItemListener;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JTextField;

public class CheckBoxTest extends JFrame{
    private JTextField fiel;
    private JCheckBox bold, italic;

    public static void main(String[] args){
        CheckBoxTest application = new CheckBoxTest();
        application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    private class CheckBoxHandler implements ItemListener{

    }
}

I'm using netBeans and every time I get the error in this part. The error is in the class name.

private class CheckBoxHandler implements ItemListener{  
    }
    
asked by anonymous 13.08.2018 / 17:46

1 answer

6

The error is not related to method signature, but to the fact that you are implementing the ItemListener . When you implement an interface, you are required to implement all methods that this interface has, in the case of the interface mentioned, only has the itemStateChanged method, as shown below:

private class CheckBoxHandler implements ItemListener{

    @Override
    public void itemStateChanged(ItemEvent arg0) {
        // TODO Auto-generated method stub

    }

}

To better understand how interfaces work, I suggest that you visit any of the questions listed in this question here . p>     

13.08.2018 / 17:55