小编Mig*_*elo的帖子

刷新JFrame Java而不做新的JFrame

我正在开发一款游戏,您可以在商店中升级您的统计数据.当你买东西它应该刷新显示你的硬币的JLabel

有没有办法在不做新的JFrame的情况下做到这一点?

public void actionPerformed(ActionEvent e) {
        user.setCoin(user.getCoin() - 5);
        user.setMaxJump(5);
        EpixController.getInstance().coinsUpdate(user, -5);
        SwingUtilities.updateComponentTreeUI(epix);
        epix.revalidate();
        epix.repaint();
    }
Run Code Online (Sandbox Code Playgroud)

这是我要刷新JFrame epix的ActionListener的代码

这是View的代码

public EpixView(User user) {


        this.setUser(user);

        JFrame epix = new JFrame();
        System.out.println(user.getMaxJump());
        epix.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        epix.setResizable(false);
        epix.setBounds(100, 100, 801, 523);
        epix.setLocationRelativeTo(null);
        epix.getContentPane().removeAll();


        /*
         * menuCard
         */
        menuCard.setLayout(null);

        //coin
        menuCardCoinImage.setBounds(0, 10, 64, 64);
        menuCard.add(menuCardCoinImage);        
        menuCardCoinImage.setIcon(new ImageIcon(coinSpinPath));             
        menuCardCoinLabel = new JLabel("" + getUser().getCoin());
        menuCardCoinLabel.setFont(new Font("Modern No. 20", Font.PLAIN, 26));
        menuCardCoinLabel.setBounds(67, 10, 56, 64);
        menuCard.add(menuCardCoinLabel);

        //player
        menuCardPlayerLabel = new JLabel("Willkommen zurück, " + getUser().getUsername());
        menuCardPlayerLabel.setBounds(598, 18, …
Run Code Online (Sandbox Code Playgroud)

java jlabel jframe

5
推荐指数
1
解决办法
89
查看次数

标签 统计

java ×1

jframe ×1

jlabel ×1