Solved

how to pass info from a main class to Jdialog ???

Posted on 2002-03-17
9
235 Views
Last Modified: 2010-03-31
Situation:
----------
I have a main class that call up a JDialog.
After call the JDialog, the main class should
do some calculation and pass the info to that JDialog so that it can update the TextArea inside it.

My Problem is:
--------------
   After the JDialog is showed on the screen, it is just waiting for the user interaction. The calculation part does not run until I close the JDialog.

Guys, can you help?
0
Comment
Question by:realman1
  • 7
9 Comments
 

Accepted Solution

by:
maggari earned 70 total points
Comment Utility
Write a class which extends JDialog, add a method to that class which does the calculations. Call that method in its constructor.

0
 

Author Comment

by:realman1
Comment Utility
it doesn't work.

can you give more details
0
 

Author Comment

by:realman1
Comment Utility
it doesn't work.

can you give more details
0
 
LVL 5

Expert Comment

by:LexZEUS
Comment Utility
post the code ...
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:realman1
Comment Utility
this is the code
*****************

main class
---------------
public class FileDistribute extends JDialog {
      JDialog d;

      public FileDistribute() {
     // code that  pack the dialog - d
     //a JDialog successfully showed on the screen.    

     // now I want to called another JDialog, this d parent dialog will be stayed in the background but disable.
     startDownload();
      }

      private void startDownload() {
       new FtpDownload(d);
      }
}


========================================================
sub dialog
--------------

public class FtpDownload extends JDialog implements ActionListener {
       JDialog dFtpStatus;

       public FtpDownload(JDialog dFileDistribute) {      
          dFtpStatus =  new JDialog(dFileDistribute, "Ftp Status", true);
          showDialog();

          //after showDialog(), I successfully display a sub Dialog - dFtpStatus.
          // the parent d dialog has been disable in the background

          // ***** the following part doesn't work until i close this sub dialog
          System.out.println("after show dialog");
          calculate();

       } //end constructor

        public void showDialog() {
         // code to pack this sub dialog
         //........
            Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
         int w = dFtpStatus.getSize().width;
         int h = dFtpStatus.getSize().height;
         int x = (dim.width-w)/2;
         int y = (dim.height-h)/2;
              dFtpStatus.setBounds(x, y, w, h);
            dFtpStatus.setResizable(false);
            dFtpStatus.setVisible(true);                    
            dFtpStatus.addWindowListener(new WindowAdapter() {
                 public void windowClosing(WindowEvent e) {
                       dFtpStatus.dispose();
               }
            });
     }

        private void calculate() {
          // code to do process some calculation and display on sub Dialog dFtpStatus
     }
}
0
 

Author Comment

by:realman1
Comment Utility
this is the code
*****************

main class
---------------
public class FileDistribute extends JDialog {
      JDialog d;

      public FileDistribute() {
     // code that  pack the dialog - d
     //a JDialog successfully showed on the screen.    

     // now I want to called another JDialog, this d parent dialog will be stayed in the background but disable.
     startDownload();
      }

      private void startDownload() {
       new FtpDownload(d);
      }
}


========================================================
sub dialog
--------------

public class FtpDownload extends JDialog implements ActionListener {
       JDialog dFtpStatus;

       public FtpDownload(JDialog dFileDistribute) {      
          dFtpStatus =  new JDialog(dFileDistribute, "Ftp Status", true);
          showDialog();

          //after showDialog(), I successfully display a sub Dialog - dFtpStatus.
          // the parent d dialog has been disable in the background

          // ***** the following part doesn't work until i close this sub dialog
          System.out.println("after show dialog");
          calculate();

       } //end constructor

        public void showDialog() {
         // code to pack this sub dialog
         //........
            Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
         int w = dFtpStatus.getSize().width;
         int h = dFtpStatus.getSize().height;
         int x = (dim.width-w)/2;
         int y = (dim.height-h)/2;
              dFtpStatus.setBounds(x, y, w, h);
            dFtpStatus.setResizable(false);
            dFtpStatus.setVisible(true);                    
            dFtpStatus.addWindowListener(new WindowAdapter() {
                 public void windowClosing(WindowEvent e) {
                       dFtpStatus.dispose();
               }
            });
     }

        private void calculate() {
          // code to do process some calculation and display on sub Dialog dFtpStatus
     }
}
0
 

Author Comment

by:realman1
Comment Utility
I have solve the problem by using Thread.

Thanks guys.
0
 

Author Comment

by:realman1
Comment Utility
this is the solution:-

main class
---------------
public class FileDistribute extends JDialog {
      JDialog d;

      public FileDistribute() {
     // code that  pack the dialog - d
     //a JDialog successfully showed on the screen.    

     // now I want to called another JDialog, this d parent dialog will be stayed in the background but disable.
     startDownload();
      }

      private void startDownload() {
       new FtpDownload(d);
      }
}


========================================================
sub dialog
--------------

public class FtpDownload extends Thread implements ActionListener {
       JDialog dFtpStatus;

       public FtpDownload(JDialog dFileDistribute) {      
          dFtpStatus =  new JDialog(dFileDistribute, "Ftp Status", true);
          showDialog();

          //after showDialog(), I successfully display a sub Dialog - dFtpStatus.
          // the parent d dialog has been disable in the background

          // ***** the following part doesn't work until i close this sub dialog
          System.out.println("after show dialog");
          calculate();

       } //end constructor

        public void showDialog() {
         // code to pack this sub dialog
         //........

         start();    

            Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
         int w = dFtpStatus.getSize().width;
         int h = dFtpStatus.getSize().height;
         int x = (dim.width-w)/2;
         int y = (dim.height-h)/2;
              dFtpStatus.setBounds(x, y, w, h);
            dFtpStatus.setResizable(false);
            dFtpStatus.setVisible(true);                    
            dFtpStatus.addWindowListener(new WindowAdapter() {
                 public void windowClosing(WindowEvent e) {
                       dFtpStatus.dispose();
               }
            });
     }

        private void start() {
             try
          {
               Thread.currentThread().sleep(500);              
          }
          catch (Exception e)
          {
               System.out.println("thread exception");
          }
          // code to do process some calculation and display on sub Dialog dFtpStatus
          //.....
     }
}          


                   
0
 

Author Comment

by:realman1
Comment Utility
Just want to say thank you :)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now