
-----------------------------------
gg1992gg
Tue Dec 22, 2009 3:47 pm

Final Project Help-- how to set a fram invisable
-----------------------------------
Hello,
I am doing my final project for our grade 12 computers class. I am having trouble setting a frame back to invisable... code is posted below... I have bolded the error

//PIZZAMAIN .... MAIN CLASS
import java.awt.*;
import javax.swing.*;

public class PizzaMain
{
	public JFrame MainFrame;
	
		
	public static void main(StringMainFrame.setVisible(false);//error is commented below
				/*
				  cannot find symbol
                                                                 symbol  : variable MainFrame
                                                                  location: class MainPagePanel
                                                                  MainFrame.setVisible(false);        
                                                                  ^
                                                                  1 error*/		
				PlayGamePanel PlayGame = new PlayGamePanel();
				PlayGame.setPreferredSize(new Dimension(800,600));
				
				PlayFrame.getContentPane().add(PlayGame);
				PlayFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
	     		PlayFrame.setBounds(0,0,805,630);
	      		PlayFrame.setResizable(false);
	      		PlayFrame.setVisible(true);
	      		playopen= true;
      		}
      		else if (playopen==true)
      		{
      			PlayFrame.setVisible(true);
      			
      		}	
		}
		else if (e.getSource()==btnHelp)
		{
			
		}
		else if (e.getSource()==btnQuit)
		{		
		System.exit(0);
		}		
	}
	
}


I realize I cannot do what I am trying but I would like to know how I can access the MainFrame object in the main class, I would like it to be set invisable when the other frame opens.
Thanks in advance for any help!

-----------------------------------
chrisbrown
Tue Dec 22, 2009 4:46 pm

Re: Final Project Help-- how to set a fram invisable
-----------------------------------
First of all, it is very important that you follow proper naming conventions, i.e. variables should start with a lower-case letter. 
It improves readability and gives you more useful information. For example, Java coders reading your program would expect to find classes called MainFrame and MainScreen, not variables as you are using them.

To the point, though:

You want to be able to call a method of one object - a JFrame - from another - MainPagePanel. All you need is for MainPagePanel to be able to access mainFrame (note the capitalization).

What that means is that in MainPagePanel, you want to make a new JFrame variable - let's call it parent - that will store the same thing as mainFrame.
JFrame parent;
Then to get mainFrame into MainPagePanel, its constructor should take one argument, a JPanel. Set parent to the argument value you will pass in the constructor.
public MainPagePanel(JFrame p) {
    parent = p;
    ...
}
Then in your main program you can call:
MainPagePanel mainScreen = new MainPagePanel(mainFrame);

Now you can call methods on parent, and since it is the same object as mainFrame, you can now control the frame as you need to.

-----------------------------------
gg1992gg
Tue Dec 22, 2009 5:20 pm

Re: Final Project Help-- how to set a fram invisable
-----------------------------------
THANK YOU!
It worked! I will pay attention to naming conventions as well thanks for the help!
