Hi
I'm new to java, and I'm trying to make a very basic game.
The problem is that i have 3 classes that cooperates and I can't get one of the values from class "Board.java" to "gp1.java".
In Board i have a button that "rolls the dice" x2 and adds the values.
In gp1 i make a picture move around (game marker or whatever it's called), but I want it to move depending on the dice.
Some of the code of "Board":
public class Board extends JPanel implements ActionListener {
private int dice;
JButton button;
TextField text = new TextField(26);
private String str;
public int no1, no2;
public Board(){
...
button = new JButton("Roll the dice");
button.addActionListener(new MyAction());
add(button);
...
}
public class MyAction implements ActionListener {
public void actionPerformed(ActionEvent ae) {
str = ae.getActionCommand();
if(str.equals("Roll the dice")) {
no1 = (int)(Math.random()*6) + 1;
no2 = (int)(Math.random()*6) + 1;
dice = no1 + no2;
text.setText("You rolled " + no1 + " and " + no2 + " which equals: " + dice);
text.disable();
}
}
}
public int getDice() {
return dice;
}
}
I get the textfield to work, and it shows the dice numbers
Some of the code of gp1:
public class gp1 {
public int dajs;
...
public void dajsen() {
Board dajse = new Board();
dajs = dajse.getDice();
}
...
}
I just want "dajs" in gp1 to contain the "dice" value from Board
I know that I'm doing it totally wrong, but i need help :/