   [java] Jlabel update problem
  I am making a dice game and I use JLabel to display score.The score display according to constructor but the score doesn't update.NEED HELP!public class roll extends JPanel {    //======================================================= instance variables    private mydice MYleftDie;// component for one dieprivate JLabel myscore;    //============================================================== constructor  roll() {   //... Create the dice   MYleftDie  = new mydice(Color.WHITE,Color.BLACK); //this.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10));   //...Create the button to roll the dice   JButton rollButton = new JButton("New Roll");   rollButton.setFont(new Font("Sansserif", Font.PLAIN, 24)); //... Add listener.   rollButton.addActionListener(new RollListener());JLabel myscore = new JLabel(""+outcome(),JLabel.CENTER);   myscore.setFont(new Font("Sansserif", Font.PLAIN, 24));   //... Layout components    this.setLayout(new GridLayout(2, 4));    this.add(MYleftDie);   this.add(myscore);  }   //========================================================== method setScore public int outcome(){int total; total = MYleftDie.getValue();  return total; }////////////////////////////////////////// inner listener class RollListener    private class RollListener implements ActionListener {   public void actionPerformed(ActionEvent e) {  MYleftDie.roll();    myscore.repaint();   }    }}
Quote:Original post by fantasymeI am making a dice game and I use JLabel to display score.The score display according to constructor but the score doesn't update.NEED HELP!*** Source Snippet Removed ***You need to update the label text when you update the value to display, e.g.:int val = 123;mylabel.setText(Integer.toString(val));