When I clicked on my txtField, it sets a boolean true, second click it sets the boolean false.
When it is false, the int shouldn't change, when it is true, it should be changed. The boolean is often changed. But it doesn't work this.wat When I clicked the JTaxtFields, the color changed to red and in the Console it prints the right thing when it should be true, it it true. When it is Red, it is false. When it is false, it shouldn't change the int. But it changed the int when it is false. What is wrong?
private JTextField zahl1;
private JTextField zahl2;
private boolean rnd1 = false;
private boolean rnd2 = false;
//JtxtField
zahl1 = new JTextField();
zahl1.setEnabled(false);
zahl1.setEditable(false);
zahl1.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
if ( rnd1 == false)
{
rnd = true;
zahl1.setBackground(SystemColor.RED);
}
else if ( rnd == true)
{
rnd = false;
zahl1.setBackground(SystemColor.menu);
}
}
});
// Button to change
JButton btnNewButton = new JButton("W\u00FCrfeln");
btnNewButton.setBounds(720, 583, 141, 41);
panel.add(btnNewButton);
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (rnd1 = true)
{
setzahl1(logic.Randoms());
}
if(rnd2 = true)
{
setzahl2(logic.Randoms());
}
}
});
// create the randoms
public int Randoms()
{
rnd = NumGenerator(1,6);
return rnd;
}
public static int NumGenerator(int min, int max)
{
Random rnd = new Random();
int randomNumber = rnd.nextInt((max - min) + 1) + min;
return randomNumber;
}
Aucun commentaire:
Enregistrer un commentaire