I am currently working on a project which involves a dice game where you click "roll" and the dice generates the number and lists it on a JTextArea and adds to the total number below.
When the user gets a 3, the total number turns to 0.
My problem is that when pressing "roll" the total number doesn't add the rolled number each time instead it shows the current rolled number.
JButton roll=new JButton("Roll");
roll.setBounds(900,750,75,30);
roll.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String command = e.getActionCommand();
if (command.equals ("Roll")){
int player1score = 0;
int player2score = 0;
int total = 0;
int total2 = 0;
Integer dice=(int)(Math.random()*6+1);
if (dice==1 || dice==2 || dice==4 || dice==5 || dice==6) {
area1.append(String.valueOf(dice + "\n"));
} else if(dice==3) {
dice = 0;
total = 0;
area1.setText(String.valueOf(total + "\n"));
totalbox1.setText(String.valueOf(total + "\n"));
}
total = total + dice;
totalbox1.setText(String.valueOf(total2));
}
}
});