如何在另一个正在运行的JFrame上暂停 [英] How do I pause a JFrame while another is running

查看:127
本文介绍了如何在另一个正在运行的JFrame上暂停的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个带有数据库的服务器,但是当我加载主JFrame时,而当我连接到数据库时,读取用户名&我选择了.properties文件中的密码,我选择让用户知道程序正在运行,该程序在特定时间内的运行情况,并让他创建一个.properties文件(如果不存在)(首次启动). 问题是我需要创建2个jframe,1个显示启动进度,1个仅在用户需要创建.properties文件时出现:问题是我必须在第一个运行时暂停第一个,并在第二个窗口关闭时重新开始运行,执行所有操作;我有两种方法,但没有用:首先,我尝试插入一个wait()调用以打开第二个JFrame,并在关闭它的同时插入notify()调用;其次,我尝试使用线程,但是问题是我停止的线程在应有的时候没有启动……这是一些代码:

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");
    }

我想在进入捕获"部分时暂停; "this"是第一个JFrame,"jFrame1"是第二个JFrame. 一些提示/技巧?

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

推荐答案

解决方案:不要使用多个JFrame.使充当模式对话框的窗口不是第二个JFrame,而是真正的模式JDialog.

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.

这篇关于如何在另一个正在运行的JFrame上暂停的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆