0

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

ksodari
  • 67
  • 8
  • 1
    Which part of this do you need help with? Post code please – BoDidely Aug 13 '15 at 14:03
  • 1
    http://stackoverflow.com/questions/9554636/the-use-of-multiple-jframes-good-bad-practice – Reimeus Aug 13 '15 at 14:04
  • 1
    This use case sounds like an abuse of JFrame. A separate JFrame just for your login progress bar? – BoDidely Aug 13 '15 at 14:11
  • yeah that is, but I too dont want to do it that way. If you have another option for showing progress bar while login is valid and then redirect it to main page... then please help me. – ksodari Aug 13 '15 at 14:17
  • Check out the link that Reimeus posted. The answers there talk in depth about why you should only ever have ONE JFrame, and better ways to handle multiple pages. – BoDidely Aug 13 '15 at 14:23

1 Answers1

1

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.

Bukk94
  • 419
  • 1
  • 6
  • 23
  • but I want to use progress bar as separate pop up above Login page while login is successful. If we have some ideas doing it another way from same Login page then please I would be grateful to use that concept. and please note that I am a beginner. :D :) and I have mentioned code in my question above – ksodari Aug 13 '15 at 14:21
  • I'm not an expert, I'm pretty much beginner too. I would use `dispose()` method to closing both your JFrames. I don't know how they're called (you're closing progressbar frame via `this.dispose();` which should be right. But you're making it very complicated when you're using 3 different JFrames. I would move progressBar to your first JFrame. – Bukk94 Aug 13 '15 at 14:41
  • I want to do exactly the same. moving progress bar to the same Login JFrame but want it look like a different popup frame above login page and then redirect to Mainpage. is there any way we can do that ?? – ksodari Aug 13 '15 at 14:45
  • You can put progress bar on the login JFrame and after inicialization set it to invisible `progressBar.setVisible(false);` and then, when you want to "pop up" only set it to `setVisible(true);` and it will look like pop up. If i get your idea right :P – Bukk94 Aug 13 '15 at 14:47
  • do you mean this if(rs.next()){ pb.setVisible(true); t = new Timer(30, (ActionEvent e) -> { count++; pb.setValue(count); if(pb.getValue()<100){ pb.setValue(pb.getValue() + 1); } if(pb.getValue()== 100){ t.stop(); this.dispose(); Mainpage mp=new Mainpage(user); mp.setVisible(true); } }); t.start();*/ I have done this way, but it looks little odd. may be I am feeling like that :) – ksodari Aug 13 '15 at 14:50
  • Yeah, pretty much like this. There's another way to do it, but it doesn't look like pop up. You can only **disable** the progressbar. That means, after inicialization, you'll set `pb.setEnabled(false);` and when you want to show it you'll switch to `pb.setEnabled(true);`. Before enabling it will be gray. But I guess that's not what you want. – Bukk94 Aug 13 '15 at 14:58