我做了一些简单的游戏,比如 cookie clicker。它可以正常工作,但问题是当点数超过 100 时我无法正确看到它们。我将在下面留下整个代码。出于某种原因,我让它变得有点复杂,但现在我遇到的唯一问题是 jLabel ...所以我希望有人能帮助我。package javaapplication17;import javax.swing.*;import java.awt.*;import java.awt.event.*;import javax.*;public class JavaApplication17 { public static void main(String[] args) { DBP prozor = new DBP(); prozor.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); prozor.setVisible(true); prozor.setLocation(600, 250); prozor.setLayout(null); }}class DBP extends JFrame{ private JLabel oznaka; private int brojac; private boolean upgraded1; private boolean upgraded2; private boolean upgraded3; private boolean isup1; private boolean isup2; private boolean isup3; public DBP(){ setTitle("Cookie Clicker"); setSize(800, 480); setLayout (new FlowLayout(FlowLayout.CENTER, 30, 20)); oznaka = new JLabel("No points!"); add(oznaka); JButton dugme = new JButton("Click"); add(dugme); JButton upgrade = new JButton("Buy first upgrade!"); upgrade.setBounds(317, 50, 150, 50); add(upgrade); upgrade.setVisible(false); JButton upgrade2 = new JButton("Buy second upgrade!"); upgrade2.setBounds(317, 100, 150, 50); add(upgrade2); upgrade2.setVisible(false); JButton upgrade3 = new JButton("Buy third upgrade!"); upgrade3.setBounds(317, 150, 150, 50); add(upgrade3); upgrade3.setVisible(false); dugme.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ brojac++; if(upgraded1){ isup1 = true; } if(upgraded2){ isup2 = true; }
1 回答
回首忆惘然
TA贡献1847条经验 获得超11个赞
要么设置一个首选尺寸:
oznaka.setPreferredSize(new Dimension(100, 20));
或者
将初始文本设置得足够大(附加空格):
oznaka = new JLabel("No points! ");
添加回答
举报
0/150
提交
取消