Hi all
Im currently trying to run the below source code, but the
(MyItemListener) keeps highlighting error? Could somebody offer some
advice in where i am going wrong.
Thanks Elvis
// class header
public class SwingFrameCount extends JFrame implements ActionListener{
String[] items = {"item1", "item2"};
JComboBox cb = new JComboBox(items);
cb.setEditable(true);
// problem area
MyItemListener actionListener = new MyItemListener();
cb.addItemListener(actionListener);
class MyItemListener implements ItemListener {
public void itemStateChanged(ItemEvent evt) {
JComboBox cb = (JComboBox)evt.getSource();
// Get the affected item
Object item = evt.getItem();
if (evt.getStateChange() == ItemEvent.SELECTED) {
// Item was just selected
} else if (evt.getStateChange() == ItemEvent.DESELECTED)
{
// Item is no longer selected
}
}
}
Chris Smith - 12 Jan 2006 19:39 GMT
> Im currently trying to run the below source code, but the
> (MyItemListener) keeps highlighting error? Could somebody offer some
> advice in where i am going wrong.
You are writing code without including it in a method. That's not
allowed. Grab a basic book on Java that will show you how to define and
use methods and trace the flow of control through them.

Signature
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation