we = new JButton(); we.addActionListener(Listener(x)); add(we);
} private class Listener implements ActionListener { private double myX; public Listener(double x) { myX = x; } public void actionPerformed(ActionEvent e) { double s = Double.parseDouble(label.getText()); s = s + myX; label.setText("$:"+s);
} } }
COMPILE ERROR:
Panel09.java:37: cannot find symbol symbol : method Listener(double) location: class Panel09 we.addActionListener(Listener(x)); ^ 1 error
msi_333
Question subject: Re: Need help with generic listeners
Posted: Sat Jan 24, 2009 10:51 am
Joined: Tue Mar 27, 2007 10:55 pm Posts: 2103 Location: Earth Has thanked: 39 time Have thanks: 56 time
Reply the line
Code:
we.addActionListener(Listener(x));
with
Code:
we.addActionListener(new Listener(x));
_________________ Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )
sd3245
Question subject: Re: Need help with generic listeners
Posted: Tue Jan 27, 2009 2:57 am
Joined: Sat Jan 24, 2009 1:28 am Posts: 2 Has thanked: 0 time Have thanks: 0 time
thank you so much, now it compiles btw:i think my code has more problems, cause now it just gives me a big button that does nothing..so any more help with that would be greatly appreciated:)
msi_333
Question subject: Re: Need help with generic listeners
Posted: Tue Jan 27, 2009 10:13 am
Joined: Tue Mar 27, 2007 10:55 pm Posts: 2103 Location: Earth Has thanked: 39 time Have thanks: 56 time
i think because you are using border layout .
Code:
setLayout(new BorderLayout());
_________________ Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )