import java.awt.Color;  
import java.awt.event.ItemListener;  
import java.awt.event.ItemEvent;  
import javax.swing.*;  

public class framed implements ItemListener {  

    JToggleButton jtButton;  
    public JPanel createAndShowNewPane() {  


        JPanel GUI= new JPanel();  
        GUI.setLayout(null);  

        JPanel buttonPane= new JPanel();  
        buttonPane.setLayout(null);  
        buttonPane.setSize(200,300);  
        buttonPane.setLocation(0,0);  
        GUI.add(buttonPane);  


        jtButton= new JToggleButton("On");  
        jtButton.setSize(90,50);  
        jtButton.setLocation(100,0);  
        jtButton.addItemListener(this);  
        buttonPane.add(jtButton);  






        return GUI;  


    }  

    public static void window(){  
        JFrame.setDefaultLookAndFeelDecorated(true);  
        JFrame frame= new JFrame("Hi");  
        framed frame1= new framed();  
        frame.setContentPane(frame1.createAndShowNewPane());  
        frame.setVisible(true);  
        frame.setSize(100,100);  
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  


    }  
     public void actionPerformed(ItemEvent e) {  
            if(e.getStateChange() == ItemEvent.SELECTED)  
            {  
             jtButton.setText("Off");  

            }  
            else   
            {  
               jtButton.setText("On");  
            }}  
public static void main(String[] args){  
    SwingUtilities.invokeLater(new Runnable(){  
        public void run(){window();}  
    } );  
}  
} 

Hey,

I was just wondering what is up with this. I got the framed class must implement inherited abstract class ItemListener.itemStateChange(ItemEvent); error when I tried to implement ItemListner, and it highlighted framed. I tryed my own version as this: GuideBook . I don't know what the issue is. I tried to google this issue, as well as cross reference the other example, and nothing. Could anyone shed some light on this? Thanks!

... OK... you renamed "itemStateChanged" to "actionPerformed." The compiler is looking for "itemStateChanged" because that's what ItemListener requires.

I simply changed the name back and the code ran fine.

This article has been dead for over six months. Start a new discussion instead.