By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,027 Members | 1,998 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,027 IT Pros & Developers. It's quick & easy.

java eqivalent for Application.DoEvents()

P: 39
Hi,
can any one tell me the eqivalent for Application.DoEvents() in java.I am swing application so i need to do this to elimate the hangling of my application.
Regards,
nags.
Sep 18 '07 #1
Share this Question
Share on Google+
9 Replies


10K+
P: 13,264
Hi,
can any one tell me the eqivalent for Application.DoEvents() in java.I am swing application so i need to do this to elimate the hangling of my application.
Regards,
nags.
What does Application.DoEvents() do?
Sep 18 '07 #2

P: 39
Application.DoEvents() is the method wich is used to do any user interaction in the parent form.for example
while(true)
{
//some code
}
if you do any updation inside this while loop then the application will hanges.so if we want to elimate that condition just put "Application.DoEvents()" inside the loop.
Sep 18 '07 #3

10K+
P: 13,264
Application.DoEvents() is the method wich is used to do any user interaction in the parent form.for example
while(true)
{
//some code
}
if you do any updation inside this while loop then the application will hanges.so if we want to elimate that condition just put "Application.DoEvents()" inside the loop.
Why don't you post the Java code that you have and explain the problem you are getting in the code.
Sep 18 '07 #4

100+
P: 553
NagarajanS should have also mentioned that DoEvents is a VB function.

DoEvents function returns control to the operating system while a loop is still executing.

NagarajanS wants to know similar functions in Java.

Qi

Why don't you post the Java code that you have and explain the problem you are getting in the code.
Sep 18 '07 #5

10K+
P: 13,264
NagarajanS should have also mentioned that DoEvents is a VB function.

DoEvents function returns control to the operating system while a loop is still executing.

NagarajanS wants to know similar functions in Java.

Qi
I'd still like to see the Java code he has for this and where it's giving problems. In Java the thread responsible for painting is different from the thread running the whole application so I (for one) am not yet fully visualizing his problem in the Java context. Thanks for the explanation of what DoEvents does.
Sep 18 '07 #6

P: 39
here is the code,
Expand|Select|Wrap|Line Numbers
  1.  private void PlayLinkActionPerformed(java.awt.event.ActionEvent evt) {                                         
  2. // TODO add your handling code here:
  3.         LicenseFrame license=LicenseFrame.getobject();
  4.        if(license.CheckLicenseKey())
  5.        {
  6.  
  7.        /*
  8.         *The following methods are used to redate the values for the next play action
  9.         */
  10.         _usersign.RepaintjTable();
  11.         currentlog.ClearCurrentLog();
  12.         comresult.RepaintjTable();
  13.         logupdate.ClearTextArea();
  14.         trace.AppendLog(GetLogTime.GetTime()+": TibMainPage"+"Started");
  15.         CreateLogDir creatdir=new CreateLogDir();
  16.         //This initialisation is for reassign the static value
  17.         TibSignOnPage.enablestoplink=1;
  18.         threadlist=new ArrayList();
  19.  
  20.       //  int sessionnumber= TreeViewDesign.Session_no;
  21.        // System.out.println("sessionnumber:"+sessionnumber);
  22.  
  23.         Runnable runnable = new Runnable() {
  24.          public void run() {
  25.          InvokeLaterMethod();
  26.              }
  27.             };
  28.  
  29.         SwingUtilities.invokeLater(runnable);
  30.        for(int usercount=1;usercount<TreeViewDesign.Totaluser+1;usercount++) {
  31.             for(int sessionid=0;sessionid<sessionnumber;sessionid++) {
  32.                 String filename="";
  33.  
  34.                filename=Double.toString((( TreeViewDesign.Totaluser-(TreeViewDesign.Totaluser%(java.lang.Math.pow(10,(Integer.toString(TreeViewDesign.Totaluser).length()-1)))))*10)+usercount);
  35.                filename=filename.substring(0,filename.length()-2);
  36.                filename=filename.substring(1,filename.length());
  37.              // System.out.println("filepath:"+TreeViewDesign.directorypath+"/"+TreeViewDesign.prefix+"_"+filename+".xml");
  38.                TibSignOnPage signon=new TibSignOnPage(TreeViewDesign.directorypath+"/"+TreeViewDesign.prefix+"_"+filename+".xml",Stop,PlayLink,PauseLink);
  39.                signon.setName(TreeViewDesign.prefix+"_"+filename);
  40.                signon.start();
  41.                threadlist.add(signon); 
  42.  
  43.  
  44.  
  45.                // _usersign.UpdateTable(TreeViewDesign.prefix+"_"+filename,"Connected",sessionnumber);
  46.                 trace.AppendLog(GetLogTime.GetTime()+": TibMainPage"+TreeViewDesign.prefix+"_"+filename+"Started");
  47.                 try
  48.                 {
  49.                 Thread.sleep(TreeViewDesign.Threadtime);
  50.                 }
  51.                 catch(Exception ex)
  52.                 {
  53.                     ex.printStackTrace();
  54.                 }
  55.             }
  56.         }
  57.  
  58.         PlayLink.setEnabled(false);
  59.         Resume.setEnabled(false);
  60.         PauseLink.setEnabled(true);
  61.         Stop.setEnabled(true);
  62.        }
  63.        else
  64.        {
  65.             System.out.println("license expired");
  66.        }
  67.     }   
  68.  
  69. i think the code is hard to understand,ok let me explain some think here where i get struck,
  70. inside  the for loop i am starting the thread class like this
  71. for()
  72. {
  73. //thread start method
  74. here i am updating the jtable for each increment!!!! 
  75. }
what will happen here is,until the for loop exits the updation will not happen.is it correct? i am want to update the table inside the for loop inself.how to do that?
Can you understand the problem?
Sep 18 '07 #7

10K+
P: 13,264
Are you sure it's not updating after adding the data?
If you're sure then you can call the resizeAndRepaint method of the JTable.
Sep 18 '07 #8

P: 39
i tried that but no use.Any other option?
ok let me know how will you update any of the control which is inside the while loop?
Regards
Nags
Sep 21 '07 #9

P: 39
Thanks all your reply.I got the answer.I used SwingWorker class which is working fine.This is the thing i want.Once again thank you very much mights
Regards,
Nags.
Sep 21 '07 #10

Post your reply

Sign in to post your reply or Sign up for a free account.