如何检查是否打开了jframe? [英] How to check if a jframe is opened?

查看:95
本文介绍了如何检查是否打开了jframe?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面的代码创建一个新数组,并将其发送到chat(jFrame).

My code below create a new array and sends it to chat(jFrame).

String info1[]=new String[3];
 // username , userid , userid2 are variables
 info1[0]=username4;
 info1[1]=""+userid;
 info1[2]=""+userid2;

 chat.main(info1);

但是我需要修改此代码以使其工作,如果打开了聊天jframe, 然后不要打开新的jFrame,而是在chat jframe中打开新的标签.聊天框的代码是:

But i need to modify this code to work such a way that it , if the chat jframe was opened, then dont open a new jFrame .But instead open a new tab in chat jframe . The code for chat frame is :

private void formWindowActivated(java.awt.event.WindowEvent evt) {       
  JScrollPane panel2 = new JScrollPane();
  JTextArea ta=new JTextArea("");
  ta.setColumns(30);
  ta.setRows(19);
  panel2.setViewportView(ta);
  jTabbedPane1.add("Hello", panel2);   
}

推荐答案

我不知道您是否应该使用JDialogs而不是JFrames,如果该窗口依赖于另一个窗口.

I wonder if you shouldn't be using JDialogs instead of JFrames, if the window is dependent on another window.

一种解决方案是使用类字段来保存对窗口(JFrame或JDialog)的引用,并检查它是否为null或可见,如果是,则懒惰地创建/打开窗口,

A solution is to use a class field to hold a reference to the window (JFrame or JDialog) and checking if it is null or visible, and if so, then lazily create/open the window,

public void newChat(User user) {
  if (chatWindow == null) {
    // create chatWindow in a lazy fashion
    chatWindow = new JDialog(myMainFrame, "Chat", /* modality type */);
    // ...  set up the chat window dialog
  }

  chatWindow.setVisible(true);
  addTabWithUser(user);
}

但这仅是我根据提供的信息可以说的.如果您需要更多具体帮助,则需要提供更多信息.

but that's about all I can say based on the information provided. If you need more specific help, then you will need to provide more information.

这篇关于如何检查是否打开了jframe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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