Cannot make a static reference to the non-static method
So I have this Japplet which represents a bunch of Jpanels. I first say to the Japplet that it has to display the first Jpanel. In this JPanel is a button which has an actionlistener connected to it. When you click on it the method ChangePanel is called from the container (the Japplet) which changes the Jpanel that is displayed (from present to future)
Here's the code:
Code:
import java.awt.Image;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JApplet;
import javax.swing.JPanel;
public class menu extends JApplet {
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel[] GamePanels = {new FirstPanel(), new SecondPanel()};
Image BackgroundImage;
public static void ChangePanel(int present,int future)
{
remove(GamePanels[present]); [COLOR="red"]Point A[/COLOR]
add(GamePanels[future]); [COLOR="red"]Point B[/COLOR]
}
public void init()
{
this.setSize(200,300);
this.add(GamePanels[0]);
GamePanels[0].setVisible(true);
}
}
So I try to run this code and it says at point A and B:
Quote:
Cannot make a static reference to the non-static field GamePanels
And it gives a fast solution: Quote:
Change modifier GamePanels to static
I do this (Which I shouldn't because I actually want the Jpanel to be a instance method and not a static one)
and in return get the following error messages:
Quote:
Exception in thread "AWT-EventQueue-1" java.lang.Error: Unresolved compilation problems:
Cannot make a static reference to the non-static method remove(Component) from the type JApplet
Cannot make a static reference to the non-static method add(Component) from the type Container
What am I doing wrong? Or how do I get this to work?
PS: I doubt there's anything wrong with my panels