How do I pause a JFrame while another is running [duplicate]

两盒软妹~` 提交于 2019-12-11 21:02:22

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/16367968/how-do-i-pause-a-jframe-while-another-is-running

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!