我一直试图让它工作很长时间,我被困住了。我有一个"有效"的评分系统(在玩家收集硬币时的分数将会增加),但是我不能让我的一生能在屏幕左上显示分数(或获得得分)它根本显示)。我尝试使用这样的jlabel:
JLabel scoreLabel = new JLabel("Score: 0");
public void someoneScored()
{
Score++;
scoreLabel.setBounds(5, 5, WIDTH, HEIGHT);
scoreLabel.setText("Score: " + Score);
}
您需要将label
放入panel
,就像此示例:
JLabel scoreLabel = new JLabel("Score: 0");
add(scoreLabel);/// assuming you have Jpanel class
public void someoneScored()
{
Score++;
scoreLabel.setBounds(5, 5, WIDTH, HEIGHT);
scoreLabel.setText("Score: " + Score);
}