Results 1 to 4 of 4
Thread: Anonymous class
- 12-24-2007, 10:31 AM #1
Senior Member
- Join Date
- Nov 2007
- Posts
- 115
- Rep Power
- 0
- 12-24-2007, 11:42 AM #2
I think its useful 2 u
Anonymous Classes in Java
- 12-24-2007, 10:00 PM #3
More (pseudo code) examples:
Java Code:JButton button = new JButton("say something"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("something"); } }); SpinnerNumberModel model = new SpinnerNumberModel(10,0,100,1); JSpinner spinner = new JSpinner(model); spinner.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { int value = ((Integer)((JSpinner)e.getSource()).getValue()).intValue(); tellSomeone(value); } }); // Although not an anonymous listener in the strict // sense, this approach can make sense sometimes: JButton someButton = new JButton("compute"); final JTextField textField = new JTextField(12); ActionListener al = new ActionListener() { public void actionPerformed(ActionEvent e) { int n = Integer.parseInt(textField.getText()); doSomething(n); } }; someButton.addActionListener(al); textField.addActionListener(al);
- 12-25-2007, 10:56 AM #4
Senior Member
- Join Date
- Nov 2007
- Posts
- 115
- Rep Power
- 0
Similar Threads
-
what is the Priority for execution of Interface class and a Abstract class
By Santoshbk in forum Advanced JavaReplies: 0Last Post: 04-02-2008, 07:04 AM -
Accessing inner class from outer class (an example)
By Java Tip in forum Java TipReplies: 0Last Post: 02-17-2008, 09:03 AM -
An example of accessing outer class from inner class
By Java Tip in forum Java TipReplies: 0Last Post: 02-17-2008, 09:01 AM -
Inner class accessing outer class
By Java Tip in forum Java TipReplies: 0Last Post: 02-17-2008, 08:59 AM -
Name of Anonymous class
By eva in forum New To JavaReplies: 1Last Post: 12-31-2007, 01:07 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks