Hello!
I got the following code:
import javax.swing.JFrame; import javax.swing.Timer; class MainClass extends JFrame { Timer timer; int counter; MainClass(String title) { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ActionListener a = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Counter = " + counter); if (++counter > 10) { timer.stop(); System.exit(0); } } }; timer = new Timer(300, a); timer.start(); pack(); setVisible(true); } public static void main(String[] args) { new MainClass("Timer Demo1"); } }
Now I got question. ActionListener is actually a interface. How is allowed to create instance of the interface ActionListener by stating ActionListener a = new ActionListener() ?
I got another question about the red part:
ActionListener a = new ActionListener() [COLOR="Red"]{ public void actionPerformed(ActionEvent e) { System.out.println("Counter = " + counter); if (++counter > 10) { timer.stop(); System.exit(0); } } };[/COLOR]
What is actually the red part?
Thanks in advance.