简体   繁体   English

在Java中打开第三个jframe时,从另一个jframe控制一个JFrame

[英]Controlling one JFrame from another jframe while opening third jframe in java

I have 3 different JFrames. 我有3个不同的JFrame。 One Jframe is a login page another has progressbar and the third one is main page. 一个Jframe是登录页面,另一个具有progressbar栏,第三个是主页。 Now what i want is that when we login in I want to show progressbar above login page and on completing progress to 100% I want to close both frames and open third Jframe which is main page. 现在我想要的是,当我们登录时,我想在登录页面上方显示progressbar ,并在完成进度到100%时关闭两个框架并打开Jframe主页的第三个Jframe please kindly help me get this done. 请帮助我完成此任务。 Thanks //here is the code part. 谢谢//这里是代码部分。

rs=pstmt.executeQuery();
    if(rs.next()){
    progressbar prb=new progressbar(user);
    prb.setVisible(true);

}// this open my 2nd JFrame of progress bar } //这将打开我的第二个JFrame进度栏

//next in Progressbar page i have this code // Progressbar页面中的下一个我有此代码

`public progressbar(String user) {
    initComponents();
    setLocationRelativeTo(null);
    t = new Timer(35, (ActionEvent e) -> {
        count++;
        pb.setValue(count);
        if(pb.getValue()<100){
            pb.setValue(pb.getValue() + 1); // it makes bar progress
        }
// after progress is 100%
        if(pb.getValue()== 100){
            t.stop();
            this.dispose(); 
            Mainpage mp=new Mainpage(user);
            mp.setVisible(true); // this opens my Mainpage
        }
    });
    t.start();
}

// Now what I want is after progress bar completes, I want to dispose both the login page and progress bar page opening Main page only //现在,我想要的是进度条完成后的内容,我想同时处理登录页面和进度条页面的打开。

For closing JFrames use command yourFrame.dispose(); 要关闭JFrame,请使用命令yourFrame.dispose(); Setting progressBar to 100% is easy via yourBar.setValue(yourBar.getMaximum()); 通过yourBar.setValue(yourBar.getMaximum());可以很容易地将progressBar设置为100% yourBar.setValue(yourBar.getMaximum()); To hide/show components use name.setVisible(true); 要隐藏/显示组件,请使用name.setVisible(true); I won't use separate JFrame only for progress bar by the way. 顺便说一下,我不会仅将JFrame用于进度栏。

I can recommend you reading some doc about JFrame . 我建议您阅读一些有关JFrame的文档 If you want more specific answer, please post your code here. 如果您想要更具体的答案,请在此处发布您的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM