Java error when creating private class

Asked

Viewed 89 times

0

Every time I try to create a private class in java I’m not getting it. Follow the full 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 am using netbeans and every time error on this part. The error is in the class name.

private class CheckBoxHandler implements ItemListener{  
    }
  • 1

    Which error appears?

1 answer

6


The error is not related to method signature, but rather because you are implementing the interface ItemListener. When you implement an interface, you are required to implement all methods that this interface has, in the case of the interface cited, has only the method itemStateChanged, as an example 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 you visit all the questions listed in this question here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.