0

I'm making a Server with a database inside, but while I'm loading the main JFrame and while I'm connecting to the database reading username & password from a .properties file I chosed to let the user know that the program is running, what the program is doing in that specific moment, and also let him create a .properties file if it not exists (first launch). The problem is that I need to create 2 jframes, 1 that shows the launch progress, and 1 that appears only when user needs to create a .properties file: the problem is that I have to pause the first one while the second is running, and restart running the first while the second is closed performing all actions; I made it in two ways, but it didn't work: first, I tried inserting a wait() call opening the second JFrame and a notify() call while closing it; second, I tried using threads, but the problem is that the thread that I stop doesn't start when it should... here's some code:

jFrame1.setBounds(0,0,500,500);
    this.setVisible(true);
    jProgressBar2.setValue(0);
    prop = new Properties();
    jTextArea1.setText(jTextArea1.getText()+"Searching file config.properties... \n");
    try {
        FileReader fr = new FileReader("config.properties");
        jProgressBar2.setValue(33);
        jLabel3.setText("33");
        jTextArea1.setText(jTextArea1.getText()+"File config.properties found... \n");
    } catch (FileNotFoundException ex) {
        jFrame1.setVisible(true);
        jTextArea1.setText(jTextArea1.getText()+"File config.properties not found... \n");
    }

I want to pause while I ented the "catch" section; "this" is the first JFrame, "jFrame1" is the second one. Some hints/tips?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
tenik
  • 250
  • 1
  • 4
  • 20

1 Answers1

5

Solution: don't use multiple JFrames. Make the window that's acting as a modal dialog not a second JFrame, but rather a real modal JDialog.

We should probably close this question as a duplicate as this exact same question gets asked again and again.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
  • I know a lot of people asks for this thing, but the problem is that the answers I found doesn't work: using common methods as threads or wait it doesn't work. I'll look for JDialog, but I'd rather prefer 2 different JFrames for internal management. – tenik May 03 '13 at 21:48
  • @user2346235: I'm confused. What is your objection towards use of a JDialog? What do you mean by "internal management"? – Hovercraft Full Of Eels May 03 '13 at 21:52
  • Easiest way is just to pass some content pane in `JOptionPane.showMessageDialog(null, contentPaneName,"Title here",JOptionPane.PLAIN_MESSAGE);` and voila! It must work! – Branislav Lazic May 03 '13 at 21:53
  • @brano88: that could work, but don't make the first parameter null; rather it should be the root JFrame, the one that must be paused. – Hovercraft Full Of Eels May 03 '13 at 21:54
  • My excuses. I didn't know JDialog; just looked for em in the documentation, and I found out that they can be a valid solution. – tenik May 03 '13 at 21:57
  • @user2346235: good deal. Actually they are more than **a** valid solution; they are ***the*** valid solution. Best of luck with them! – Hovercraft Full Of Eels May 03 '13 at 22:04