Close a jInternalFrame before Open another

Asked

Viewed 852 times

0

I’m doing a browser project (where I create the "pages" myself in the netbeans design - All offline) just to learn on vacation. However I am with a doubt, I believe it is simple but as I am starting I am still trying to understand the logic.

I have a jTextFieldPesquisa and in it the person will enter the site that she wants to open and have a button in front that when clicked, it will open the screen of the site. (In the future I will still do without jButton, but at first I thought it best to separate so I understand the functioning of the two).

Follow an example from my jButtonEnterActionPerformed:

    if((jTextFieldPesquisa.getText().equals("www.facebook.com.br")) || (jTextFieldPesquisa.getText().equals("facebook.com.br")) || (jTextFieldPesquisa.getText().equals("31.13.85.36"))) {

        Facebook obj1=new Facebook();
        jDesktopPaneBG.add(obj1);
        try{
            obj1.setMaximum(true);
            obj1.setVisible(true);
            obj1.setPosicao();

        } catch (PropertyVetoException e) {
            JOptionPane.showMessageDialog(rootPane, e);
        }

    }

In that if above, when the user clicks on jTextFieldPesquisa and of enter, the page I created from facebook will appear inside the jDesktopPane. It’s worth pointing out I’m wearing one jTabbedPane to open a jInternalFrame and in that jInternalFrame is opened the page itself.

The problem: When I open a page (www.facebook.com.br), and then type (www.google.com) that was another page that I drew in jInternalFrame. The google page is on top of the facebook page. I would like to hide the facebook page before opening the google page.

In the beginning my logic would be to insert a boolean public variable starting with false and every time I entered inside the if, it would be true. So, I would know that this page would be open because it has the true value, I would have to close it first to open another one. So far so good (in my logic).

So I needed to know the value of the object on the screen that was open. As for each screen, I instated an obj1, obj2, obj3 I just created a public variable also integer started with 0. Each time I entered that if, this variable would save the "object value" and then I would know which instance of the object was open and could close itI was there before I opened the other.

Would look like this:

public Boolean pagina = false; public int numObject = 0;

    if((jTextFieldPesquisa.getText().equals("www.facebook.com.br")) || (jTextFieldPesquisa.getText().equals("facebook.com.br")) || (jTextFieldPesquisa.getText().equals("31.13.85.36"))) {

        Facebook obj1=new Facebook();
        jDesktopPaneBG.add(obj1);
        try{
            obj1.setMaximum(true);
            obj1.setVisible(true);
            obj1.setPosicao();

            pagina = true;  //pagina esta aberta
            numObjeto = 1; //igual obj1
        } catch (PropertyVetoException e) {
            JOptionPane.showMessageDialog(rootPane, e);
        }

    }

If anyone wants to see the project, it’s on github marciellioliveira

  • Can’t reuse the same screen with the new page? Maybe it’s easier.

  • So, but how would I do this with jTabbedPane? Because the intention would be to open the same as Chrome, for example. :/

  • Already tried to add a new tab in tabbedpane? seutabbedPane.add("aqui você adiciona um painel")

  • Yes, but let’s assume that the person is using facebook, no longer want to use, click on the textfield of the same page that facebook is and type google. Dai wanted to "imitate" this, you know? Because then when she gives the enter will disappear facebook and open google.

  • And then when the person clicks on the new tab, so yes I can add the new tab, I believe...

1 answer

2


I managed to resolve... // jInternalFrame is to be displayed inside a Jdesktoppane mine is called Desktop.. // I created a method to close the screen that is currently active...

private void disposeOnClosed() {

JInternalFrame tela = Desktop.getSelectedFrame();
if (tela==null){}
else{
Desktop.getSelectedFrame().dispose();
}   
}

//in the event calling the screen I put the event calling the method:

private void jMenu1MousePressed(java.awt.Event.Mouseevent evt) {

disposeOnClosed();
TelaGerencia gerencia = new TelaGerencia();
gerencia.setVisible(true);
Desktop.add(gerencia);

}

worked perfectly, hope to have helped!!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.