eventqueue.invokelater in main method

R

Richie

I heard that sun system recommends that following java code placed in
the main method to conform to the j2se 1.5 standard or convention. I am
using eclipse 3.1. How do i make eclipse insert the
eventqueue.invokelater statement in main method every time i create a
new project or a new item that requires a main method?


public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new anyobject().setVisible(true);
}
});
}
 
T

Thomas Weidenfeller

Richie said:
I heard that sun system recommends that following java code placed in
the main method to conform to the j2se 1.5 standard or convention. [...]


public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new anyobject().setVisible(true);
}
});
}

That's not what Sun recommends. Since 1.4 Sun insists that you construct
the complete GUI on the EDT now, in addition to the previous requirement
of only calling methods of Swing/AWT classes from the EDT, once a GUI
has been realized.

/Thomas
 
R

Richie

Can any one answer my eclipse question? All I want is make eclipse
create a main method mentioned in my original message when I choose a
new visual class swing application.
 
R

Roedy Green

Can any one answer my eclipse question? All I want is make eclipse
create a main method mentioned in my original message when I choose a
new visual class swing application.

You are just inventing yet another template. Not all your main methods
will have this in them.
see Eclipse help on code templates.
 
R

Richie

thanks. please forgive ignorance. i am new eclipse and new to java. i
will try creating templates
 
R

Richie

my swing applications uses awt listeners and awt events. does it matter
if i use the invokelater from java.swing.swingutilities or java.awt?
 
T

Thomas Hawtin

Richie said:
my swing applications uses awt listeners and awt events. does it matter
if i use the invokelater from java.swing.swingutilities or java.awt?

The SwingUtilities version just calls the EventQueue version. The former
is only there because back in JRE 1.1 EventQueue didn't have that method.


There is a misconception that you can add and remove listeners from
swing components outside of the EDT. This is not in fact thread-safe.
Also, because AWT is full of threading bugs, it's wise to treat AWT
components with the same caution as you do swing.

Tom Hawtin
 
R

Roedy Green

my swing applications uses awt listeners and awt events. does it matter
if i use the invokelater from java.swing.swingutilities or java.awt?

I think they likely do the same thing. You can also check for @since.
One might go back further than the other.
 
R

Richie

OK. Thanks. How come eclipse and netbeans all use awt listeners to the
swing applications?
 
C

Chris Smith

Richie said:
Can some one answer my question?

Probably not, because your question didn't make much sense. It wasn't
grammatically correct, which makes it harder to guess what you meant.

Swing uses the AWT event model. It just adds some not event and
listener classes. Perhaps that answers your question?

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
R

Richie

Yes. thanks. I am sorry for my improper grammar. I will use the
swingutilities event threading model for my swing applications and see
how that goes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top