开发者

Only one active new jframe

开发者 https://www.devze.com 2023-02-09 12:34 出处:网络
I have two forms : f_main and f_recruitment. I put a label in f_main with this 开发者_StackOverflowcode :

I have two forms : f_main and f_recruitment. I put a label in f_main with this 开发者_StackOverflowcode :

....
private void jLabel2MouseClicked(java.awt.event.MouseEvent evt) {                                     
    JOptionPane.showMessageDialog (null, "Recruitment Icon has been Clicked");
    new F_Recruitment().setVisible(true);
}                                    
 // to display f_recruitment

Question is how can I have just one active f_recruitment open?

Update:

Thanks, what I mean is, how can I prevent user from re-click jLabel2 and another f_recruitment are open..? ( I let f_main form keep visible on purpose, while the new form f_recruitment is open)


I agree completely with glowcoder (1+), that more information would be helpful and perhaps essential to competently answering this question, but another option is to use lazy initiation -- to create an F_Recruitment variable field that's null, and instantiate it in the listener if it's null, but regardless of whether it was initially null or not, at the bottom of the listener display the field.

public class MyClass {

  private F_Recruitment fRecruitment = null;

  // ... more code goes here

  private void jLabel2MouseClicked(java.awt.event.MouseEvent evt) {
    JOptionPane.showMessageDialog (null, "Recruitment Icon has been Clicked"); 
    if (fRecruitment == null) {
      fRecruitment = new F_Recruitment();
    }
    fRecruitment.setVsible(true);
  }


I really don't think there is enough information here to really answer your question.

You say you want just one active f_recruitment, but that implies there are more than one f_recruitment.

You could consider a toggle method:

private void toggleRecruitmentOn() {
    f_main.setVisible(false);
    f_recruitment.setVisible(true);
}

private void toggleMainOn() {
    f_recruitment.setVisible(false);
    f_main.setVisible(true);
}

I'll update this if more information gets posted about the issue at hand :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号