Hallo zusammen 
Ich möchte folgendes Umsetzen: Wenn man auf einen Button clickt, soll der Counter um 1 hochgehen.
Dies soll auf einen JLabel sichtbar gemacht werden.
mein aktueller Code:
Das Problem:
Der Score wird mit System.out.print "geupdatet" jedoch nicht auf dem JLabel an sich.
ich habs auch schon mit OtherClass.score++ o.ä. versucht.
VLG
Ich möchte folgendes Umsetzen: Wenn man auf einen Button clickt, soll der Counter um 1 hochgehen.
Dies soll auf einen JLabel sichtbar gemacht werden.
mein aktueller Code:
Java:
public class myPanel extends JPanel implements something {
JCheckBox checkBx;
JButton plusButton;
JButton minusButton;
JLabel myLabel;
public UpperPanel(List<Something> something) {
checkBx = new JCheckBox("ShowMore");
add(checkBx);
plusButton = new JButton("+");
add(plusButton);
minusButton = new JButton("-");
add(minusButton);
myLabel = new JLabel("Score: " + OtherClass.score);
plusButton.setVisible(false);
minusButton.setVisible(false);
checkBx.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(!checkBx.isSelected()) {
plusButton.setVisible(false);
minusButton.setVisible(false);
myLabel.setVisible(false);
}
else if(checkBx.isSelected()) {
plusButton.setVisible(true);
minusButton.setVisible(true);
myLabel.setVisible(true);
}
}
});
//HIER WIRDS WICHTIG:
plusButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
myLabel = new JLabel("Score: " + OtherClass.score + 1);
add(myLabel);
}
});
add(myLabel);
}
}
Das Problem:
Der Score wird mit System.out.print "geupdatet" jedoch nicht auf dem JLabel an sich.
ich habs auch schon mit OtherClass.score++ o.ä. versucht.
VLG