S
Stephen Marjoribanks
I am getting two compiler errors saying that I cannot reference a
non-static method from a static context. I think the problem arises from
me not entirely understanding the static keyword. My code is too long to
post, but here is an idea of the problem:
public class GMLV
{
public static void main(String[] args)
{
Application app = new Application();
}
}
class Application
{
public JPanel treePanel = new JPanel();
public JPanel sketchPanel = new JPanel();
public Jpanel mainPanel = new JPanel();
//other variables here
// constructor
Application()
{
//initialize GUI here
mainPanel.add(treePanel);
mainPanel.add(sketchPanel);
}
//other methods here including one which creates an instance of
//XMLParser
public void addComponents(JComponent tree, JComponent sketch)
{
treePanel.add(tree);
sketchPanel.add(sketch);
this.validate();
this.repaint();
}
}
class XMLParser()
{
SlopeGraphicsPanel sketch = new SlopeGraphicsPanel();
XMLTreeViewer tree = new XMLTreeViewer();
//parsing code here
Application.addComponents(tree, sketch); <<<<<<<
}
class SlopeGraphicsPanel extends JComponent
{
// graphics code here
}
class XMLTreeViewer
{
// JTree code here
}
At the moment I am getting an error pointing to where I have indicated
with <'s and it says that I cannot reference the non-static method
addComponents from a static context.
Why is this happening, and why is the context static even though I
haven't declared it to be?
Any help would be much appreciated!
Steve
non-static method from a static context. I think the problem arises from
me not entirely understanding the static keyword. My code is too long to
post, but here is an idea of the problem:
public class GMLV
{
public static void main(String[] args)
{
Application app = new Application();
}
}
class Application
{
public JPanel treePanel = new JPanel();
public JPanel sketchPanel = new JPanel();
public Jpanel mainPanel = new JPanel();
//other variables here
// constructor
Application()
{
//initialize GUI here
mainPanel.add(treePanel);
mainPanel.add(sketchPanel);
}
//other methods here including one which creates an instance of
//XMLParser
public void addComponents(JComponent tree, JComponent sketch)
{
treePanel.add(tree);
sketchPanel.add(sketch);
this.validate();
this.repaint();
}
}
class XMLParser()
{
SlopeGraphicsPanel sketch = new SlopeGraphicsPanel();
XMLTreeViewer tree = new XMLTreeViewer();
//parsing code here
Application.addComponents(tree, sketch); <<<<<<<
}
class SlopeGraphicsPanel extends JComponent
{
// graphics code here
}
class XMLTreeViewer
{
// JTree code here
}
At the moment I am getting an error pointing to where I have indicated
with <'s and it says that I cannot reference the non-static method
addComponents from a static context.
Why is this happening, and why is the context static even though I
haven't declared it to be?
Any help would be much appreciated!
Steve