Possible Duplicate:
Cannot make a static reference to the non-static method
Java was my first programming class. We learned the basics of OOP, but I never had this come up in class. In my next programming language, C# we used visual studio and this problem never came up either. How do you get out of the main method to access other classes? I looked back at my java programs that I wrote in class, and it looks like all method were static. In c# I made many programs without using a single static method. Can someone show me how to make this work? I'm trying to rewrite a program in java that I wrote in C# but I can't seem to figure out how to get out of the main. Here's the first class with the main method:
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class DeluxKenoMainWindow extends JFrame
{
private Numbers gameNumbers;
public DeluxKenoMainWindow()
{
initUI();
}
public final void initUI()
{
setLayout(null);
int xCoord = 85;
int yCoord = 84;
Button[] button = new Button[80];
for(int i = 0; i<80; i++)
{
String buttonName = "button" + i;
if(i % 10 == 0)
{
xCoord = 12;
yCoord +=44;
}
if(i % 40 == 0)
yCoord += 10;
button[i] = new Button(buttonName, xCoord, yCoord, i+1);
xCoord += 42;
getContentPane().add(button[i]);
}
getContentPane().add(new Game(gameNumbers));
getContentPane().add(new AnimatedGraphics());
getContentPane().add(new BackgroundImage());
setTitle("Delux Keno");
setSize(600,600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
}
public void startGame()
{
do
{
Boolean[] pickedNumbers = gameNumbers.getNumbers();
}while (gameNumbers.numbersSet = false);
}
public static void main(String[] args)
{
startGame();
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
System.setProperty("DEBUG_UI", "true");
DeluxKenoMainWindow ex = new DeluxKenoMainWindow();
ex.setVisible(true);
}
});
}
}
and here's the class that I'm trying to access:
import java.util.Random;
public class Numbers<syncronized> {
private volatile Boolean[] computerNumbers = new Boolean[80];
private static final Object OBJ_LOCK = new Object();
public volatile Boolean numbersSet;
public void setNumbers()
{
synchronized(OBJ_LOCK)
{
int i = 0;
Random randy = new Random(System.currentTimeMillis());
do{
int testNum = randy.nextInt(80);
if(computerNumbers[testNum] = false)
{
computerNumbers[testNum] = true;
i++;
}
}while(i < 20);
numbersSet = true;
}
}
public Boolean[] getNumbers()
{
synchronized(OBJ_LOCK)
{
Boolean[] returnComputerNumbers = new Boolean[80];
for(int i = 0; i < computerNumbers.length; i++)
{
returnComputerNumbers[i] = computerNumbers[i];
computerNumbers[i] = false;
}
return returnComputerNumbers;
}
}
}
I'm sure there's a simple fix for this, but I can't seem to find it. I did look on stackoverflow and google for an answer, but none of those made sense to me. Thanks for any help!!