使用 SWING 在 java 中显示多个图像,并将它们分别放置在同一个 window 中
Display multiple images in java with SWING and and place them separately in the same window
嗨,我想在同一个 window 中显示一个图像并在旧图像上显示另一个图像,而不用擦除它以使用 JFrame
叠加它们
这里是更新后的代码,我可以显示多张图片,但无法在旧图片上显示新图片,而且我无法在 X 列和 Y 行中显示
希望你能帮助我
package morpion;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class GUI extends JFrame
{
private static final long serialVersionUID = -6398802531018487402L;
public GUI(char [][]array,int taille)
{
ImageIcon board = new ImageIcon(this.getClass().getResource("tictactoe.jpg"));
ImageIcon x = new ImageIcon(this.getClass().getResource("X.PNG"));
ImageIcon o = new ImageIcon(this.getClass().getResource("O.PNG"));
JLabel board1 = new JLabel(board);
JLabel x1 = new JLabel(x);
JLabel o1 = new JLabel(o);
GridLayout grid = new GridLayout(3,3);
setResizable(false);
setTitle("TicTacToe(Morpion)");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(535,560);
setLocation(200,0);
setVisible(true);
JPanel panel = new JPanel();
setContentPane(panel);
panel.setLayout(grid);
panel.add(x1);
panel.add(o1);
panel.add(board1);
FlowLayout game = new FlowLayout(FlowLayout.CENTER,10,10);
getContentPane().setLayout(game);
}
}
解决只需要将棋盘与X或O融合,并将结果与下一个token融合
嗨,我想在同一个 window 中显示一个图像并在旧图像上显示另一个图像,而不用擦除它以使用 JFrame
叠加它们这里是更新后的代码,我可以显示多张图片,但无法在旧图片上显示新图片,而且我无法在 X 列和 Y 行中显示
希望你能帮助我
package morpion;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class GUI extends JFrame
{
private static final long serialVersionUID = -6398802531018487402L;
public GUI(char [][]array,int taille)
{
ImageIcon board = new ImageIcon(this.getClass().getResource("tictactoe.jpg"));
ImageIcon x = new ImageIcon(this.getClass().getResource("X.PNG"));
ImageIcon o = new ImageIcon(this.getClass().getResource("O.PNG"));
JLabel board1 = new JLabel(board);
JLabel x1 = new JLabel(x);
JLabel o1 = new JLabel(o);
GridLayout grid = new GridLayout(3,3);
setResizable(false);
setTitle("TicTacToe(Morpion)");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(535,560);
setLocation(200,0);
setVisible(true);
JPanel panel = new JPanel();
setContentPane(panel);
panel.setLayout(grid);
panel.add(x1);
panel.add(o1);
panel.add(board1);
FlowLayout game = new FlowLayout(FlowLayout.CENTER,10,10);
getContentPane().setLayout(game);
}
}
解决只需要将棋盘与X或O融合,并将结果与下一个token融合