User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » Java Thread Question Page [1]  
BlackSheep
Suspended
1575 Posts
user info
edit post

I have an application that goes out and logs into a data base using "login" method below. While this app is logging in, i want to show a status Dialog which implements Runnable (also described below).

The problem I am having is that the Dialog is not fully drawn until after the login thread is executed. I can't figure out why so any help would be appreciated.


   
public class Proteus extends Frame {
.
.
.
public void login(Login myLogin, Frame parentFrame) {





try {

if (myLogin.loginName == null || myLogin.password == null || myLogin.serverAddress == null) {

//myLogin.readConfig();
myLogin.show();
myLogin.hide();

}

//**************Problem is Here*********************
//When this is enclosed in a thread, it is not fully drawn.

try{
Thread myThread= new Thread(new StatusBar(parentFrame, true));
myThread.start();
}catch(Exception e){
System.out.println(e);

}


//**************End of Problem*********************

System.out.println("serverAddress " + myLogin.getProteusServer());

service = ProteusAPIUtils.connect(myLogin.getProteusServer(), true, "C:\\Cert\\client.ks");// For dynamic user
// myIndicator.updateStatus("Sending user info...");


// status.show();

try {

System.out.println("myLogin " + myLogin.getLoginName());
service.login(myLogin.getLoginName(), myLogin.getPassword());//For dynamic user



} catch (IOException e) {
// myIndicator.updateStatus(e.getMessage());
}

// Get an existing configuration using
// getEntityByName( long parentId, String name, String type )
// myIndicator.updateStatus("Now Logged In.");

//dlg.setVisible(false);

//new JOptionPane().showMessageDialog(this, "Now Logged In");

System.out.println("Now Logged In");
} catch (ServiceException g) {
// myIndicator.updateStatus(g.getMessage());
//new JOptionPane().showMessageDialog(this, "Unable To Login");

System.out.println("Unable To Login");
}



}



 

public class StatusBar extends JDialog implements Runnable{

/** Creates new form StatusBar */
public StatusBar(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
this.setLocationRelativeTo(parent);
//this.show();
}
.
.
.
public void run() {


StatusBar dialog = new StatusBar(new java.awt.Frame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);


}

5/10/2011 11:20:13 AM

rabrunkh
Veteran
191 Posts
user info
edit post

I think you are running into thread safety issues with swing:

http://download.oracle.com/javase/6/docs/api/javax/swing/package-summary.html#threading

5/10/2011 4:33:54 PM

CaelNCSU
All American
7082 Posts
user info
edit post

Looks more like you may want to draw the stuff in StatusBar run() first and do database stuff in the thread.

That's more of a common pattern since most IO is blocking. The IO is holding up the main thread.

5/10/2011 8:12:44 PM

qntmfred
retired
40726 Posts
user info
edit post

^

5/10/2011 8:50:51 PM

 Message Boards » Tech Talk » Java Thread Question Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.39 - our disclaimer.