Itemlistener problem

T

tuurbo46

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
}
}
}
 
C

Chris Smith

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.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,058
Members
48,769
Latest member
Clifft

Latest Threads

Top