| Author |
What this code does?
|
Vivek Alampally
Ranch Hand
Joined: Jul 10, 2008
Posts: 67
|
|
Hi everybody,
Can anyone here tell me what the following code does
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
JLabel lbl = new JLabel("Hello World");
add(lbl);
}
});
It looks strange. I can't understand the syntax. Could anyone please explain what is this. I know Thread can be created by extending Thread class/implementing runnable.
But strange part here is it is creating an object by newing a Runnable which is an interface.
Thanks,
Vivek.
|
 |
Shanky Sohar
Ranch Hand
Joined: Mar 17, 2010
Posts: 1046
|
|
here we are creating a annonymouse inner class which implement the runnable interface.
donot worry you will see such kind of syntax when you reach the innerclass chapter if you are studing for SCJP
|
SCJP6.0,My blog Ranchers from Delhi
|
 |
Shanky Sohar
Ranch Hand
Joined: Mar 17, 2010
Posts: 1046
|
|
One more thing please use CODETAGS while posting your queries.
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
Vivek, run below code; this example is almost related to your question
the annonymous class allow you to override a method for a particular instance.
|
 |
 |
|
|
subject: What this code does?
|
|
|