|
-
October 17th, 2011, 08:44 AM
#1
Error in ActionListener
Hi Guys,
Anyone can help me please??
I am newbie in Java and I tried simple ActionListener and I got an error "Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code - cannot find symbol
symbol: variable item1.
I created the item1 as JTextField already but it seem it didn't detected.
Attached the code :
public DemoForm() {
super ("Entry Form");
setSize(255,80);
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
setVisible(true);
setLayout(new FlowLayout());
JLabel LabelNumberOfCustomer = new JLabel("Number of the customer : ", JLabel.RIGHT);
add (LabelNumberOfCustomer);
setVisible(true);
LabelNumberOfCustomer.setToolTipText("This is tool tip text");
JTextField item1 = new JTextField (3) ;
add (item1);
theHandler handler = new theHandler();
item1.addActionListener(handler);
}
private class theHandler implements ActionListener {
public void actionPerformed (ActionEvent event){
String string = "";
if (event.getSource()==item1){
string = String.format("Number of Customer : %s", event.getActionCommand());
}
JOptionPane.showMessageDialog(null, string);
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|