简体   繁体   中英

Controlling one JFrame from another jframe while opening third jframe in java

I have 3 different JFrames. One Jframe is a login page another has progressbar and the third one is main page. 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. 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

//next in Progressbar page i have this code

`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(); Setting progressBar to 100% is easy via yourBar.setValue(yourBar.getMaximum()); To hide/show components use name.setVisible(true); I won't use separate JFrame only for progress bar by the way.

I can recommend you reading some doc about JFrame . If you want more specific answer, please post your code here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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