I'm doing a browser project (where I myself create the "pages" in netbeans design - All offline ) just to learn on vacation. But I have 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 type the site that they want to open and I have a button in the front that when clicked, it will open the screen of the site. (In the future I will still do without the jButton, but at the beginning I thought it best to separate so I can understand the operation of the two).
Here is an example of 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 this if above, when the user clicks on jTextFieldPesquisa
and enter , the page I created from facebook will appear inside jDesktopPane
.
It is worth mentioning that I am using jTabbedPane
to open jInternalFrame
and in that jInternalFrame the page itself is opened.
The problem: When I open a page (www.facebook.com.br), and then I type (www.google.com.br) 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.
At first my logic would be to insert a boolean public variable starting with false and every time it enters into the if, it would be true. So, I would know that this page would be open because it has the value true, I would have to close it first to open another one. So far so good (in my logic).
Dai I needed to know the value of the screen object that was open. As for each screen, I instantiated an obj1, obj2, obj3 I just created a public variable also 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 it before opening the other.
It would look like this:
public boolean page = 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 in github marciellioliveira