如何在不使用Windowbuilder创建新框架的情况下更新框架的内容?

问题描述

我以前从未使用过WindowBuilder,所以这可能是一个愚蠢的问题。如何在不弹出新窗口的情况下更新JFrame的内容?我知道弹出一个新窗口的原因是由于“ frame = new JFrame(“ Chess”);“,但是我不知道如何用其他方式绘制它。

public void draw() {
    frame = new JFrame("Chess");
    frame.setBounds(100,100,805,829);
    frame.setDefaultCloSEOperation(JFrame.EXIT_ON_CLOSE);
    frame.setBackground(Color.LIGHT_GRAY);
    frame.getContentPane().setLayout(null);
    frame.setResizable(false);

    
    for(byte y = 0; y < 8; y++) {
        for(byte x = 0; x < 8; x++) {
            if(game.board[y][x].type != Type.EMPTY) {
                JLabel label = new JLabel("");
                label.setIcon(new ImageIcon(getimageFromPiece(game.board[y][x])));
                label.setBounds(x*100 + 30,y*100,100);
                frame.getContentPane().add(label);
            }
        }
    }
    
    drawBoard();
    JButton button = new JButton("");
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
        }
    });
    button.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent arg0) {
            Point clickLoc = MouseInfo.getPointerInfo().getLocation();
            int clickY = (clickLoc.y - (clickLoc.y - 29)%100 - 100);
            int clickX = (clickLoc.x - (clickLoc.x - 5)%100 - 100);
            doClick(clickY,clickX);
        }
    });
    button.setopaque(false);
    button.setContentAreaFilled(false);
    button.setBorderPainted(false);
    button.setBounds(0,800,800);
    frame.getContentPane().add(button);
    frame.setVisible(true);
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)