lordjbs
lordjbs

Reputation: 13

Reload the JFrame or JLabel

Im developing an little "clicker" but, if i press the button, and i should get 1+ Score, it dont work! Is there any way to reload or anything else? Heres my code: (ClickEvent)

public class event implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
    System.out.println("PRESS");
    game.timesClicked.add(1);
    points.setText(game.seePoints);
}

}

And there is my JFrame:

public class game extends JFrame
{
public static JButton buttonStart;
JButton buttonCredits;
JButton buttonBack;
JButton buttonLeave;

public static JFrame panel = new game();

public static ArrayList<Integer> timesClicked = new ArrayList<Integer>();

public static JLabel label1;
public static JLabel points;
public static String seePoints = "Deine Knöpfe: " + timesClicked.size();
public game()
{

    setLayout(null);
    label1 = new JLabel("ButtonClicker");
    points = new JLabel(seePoints);

    points.setFont(new Font("Tahoma", Font.BOLD, 15));
    points.setBounds(0, 0, 200, 200);

    label1.setFont(new Font("Tahoma", Font.BOLD, 50));
    label1.setBounds(315, 50, 500, 200);

    event e1 = new event();

    JButton b = new JButton("KNOPF");
    b.setBackground(new Color(96, 140, 247));
    b.setForeground(Color.WHITE);
    b.setFocusPainted(false);
    b.setFont(new Font("Tahoma", Font.BOLD, 15));
    b.setBounds( 402, 380, 180, 50 );


    b.addActionListener(e1);

    add(b);
    add(label1);
    add(points);

}
}

(Sorry For My Bad English)

Upvotes: 1

Views: 39

Answers (1)

Joe C
Joe C

Reputation: 15684

public static String seePoints = "Deine Knöpfe: " + timesClicked.size();

This is only being called once at the start of your program. When you add to timesClicked, it does not recalculate seePoints.

You will need to set this variable to the correct value every time you click.

Upvotes: 1

Related Questions