Board index » jbuilder » What's wrong with this code?

What's wrong with this code?


2006-02-15 06:31:30 AM
jbuilder14
Hi,
Could someone please tell me what's wrong with the following code?
I tried to run the splash screen on a seperate thread, but it will only show
up after the main thread is finished.
Is there a way to allow the two thread starting at the same time?
Any suggestion will be appreciated.
Thanks,
Tom
here is my code snip.
....
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception exception) {
exception.printStackTrace();
}
Runnable runner = new Runnable() {
public void run() {
try {
Thread.sleep(1000);
}catch (InterruptedException e){}
validate_users();
String status = "Loading... Please wait...";
JDialog jwin = new JDialog();
JLabel l = new JLabel();
JPanel jpanel = new JPanel();
l.setText("Now Loading...");
l.setIcon(image3);
l.setVisible(true);
jpanel.add(
new JLabel("Now Loading...",
SwingConstants.CENTER));
jpanel.setVisible(true);
jwin.getContentPane().add(jpanel, BorderLayout.CENTER);
jwin.setTitle(status);
jwin.setResizable(false);
//jwin.setModal(true);
jwin.setBackground(Color.lightGray);
jwin.setBounds(400, 400, 250, 150);
jwin.setVisible(true);
jwin.repaint();
}
};
EventQueue.invokeLater(runner);
new Appilcation();
}
});
}
 
 

Re:What's wrong with this code?

tom wrote:
Quote
Hi,

Could someone please tell me what's wrong with the following code?
I tried to run the splash screen on a seperate thread, but it will only show
up after the main thread is finished.
Is there a way to allow the two thread starting at the same time?

Any suggestion will be appreciated.

Thanks,

Tom

here is my code snip.

....
public static void main(String[] args) {

SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception exception) {
exception.printStackTrace();
}

Runnable runner = new Runnable() {
public void run() {
try {
Thread.sleep(1000);
}catch (InterruptedException e){}

validate_users();

String status = "Loading... Please wait...";
JDialog jwin = new JDialog();

JLabel l = new JLabel();
JPanel jpanel = new JPanel();

l.setText("Now Loading...");
l.setIcon(image3);
l.setVisible(true);
jpanel.add(
new JLabel("Now Loading...",
SwingConstants.CENTER));

jpanel.setVisible(true);
jwin.getContentPane().add(jpanel, BorderLayout.CENTER);

jwin.setTitle(status);
jwin.setResizable(false);
//jwin.setModal(true);
jwin.setBackground(Color.lightGray);
jwin.setBounds(400, 400, 250, 150);
jwin.setVisible(true);
jwin.repaint();

}

};
EventQueue.invokeLater(runner);

new Appilcation();
}

});

}


Googling for - swing splash thread
Yields:
www.javaworld.com/javaworld/javatips/jw-javatip104.html
--
Regards,
Lori Olson [TeamB]
------------
Save yourself, and everyone else, some time and search the
newsgroups and the FAQ-O-Matic before posting your next
question.
Google Advanced Newsgroup Search
www.google.ca/advanced_group_search
Other Newsgroup Searches:
www.borland.com/newsgroups/ngsearch.html
Joi Ellis's FAQ-O-Matic:
www.visi.com/~gyles19/fom-serve/cache/1.html