static help
I know that there are a lot of posts with this same error but as i was running through thier code i could fix my own. This is a simple program for my java class but we are on break right now. Im getting the error when i try to get a boolean value from another class. Thank in advance for all the help.
So here is the error:
non-static variable rolledYet cannot be referenced from a static context
Here is the code:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
publicclass Diceextends Appletimplements ActionListener{
private Button roll =new Button("Roll");
private Die die1 =new Die(100);
private Die die2 =new Die(120);
publicboolean rolledYet =false;
publicvoid init(){
roll.addActionListener(this);
add(roll);
}
publicvoid actionPerformed(ActionEvent event){
if(event.getSource() == roll){
die1.roll();
die2.roll();
}
rolledYet =true;
repaint();
}
publicvoid paint(Graphics g){
die1.display(g);
die2.display(g);
}
}
class Die{
privateint dieValue, yCoord;
public Die(int initialYCoord){
yCoord = initialYCoord;
}
publicvoid roll(){
dieValue = (int) (Math.random() * 6 + 1);
}
publicvoid display(Graphics g){
if (Dice.rolledYet)
g.drawString("Die Value: " + dieValue, 100, yCoord);
}
}

