我目前正在进行Connect Four游戏,我将非常感谢您添加和移动游戏部分的任何帮助。 因此,我将游戏片段制作成图像,并希望将其添加到游戏板上,这是一张JLabel图片,然后将游戏块移动到Y轴上。
这是我的代码:
import javax.swing.*;
import java.awt.*;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Dimension;
import java.awt.Graphics;
public class GraphicsConnectFour extends JPanel
{
public static void main(String[] args)throws Exception
{
JFrame frame = new JFrame("ConnectFour");
frame.setPreferredSize (new Dimension (970, 700));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GraphicsConnectFour connectFour = new GraphicsConnectFour();
frame.add(connectFour);
frame.add(new gameArea());
frame.pack();
frame.setVisible(true);
}
}
class gameArea extends JPanel
{
Graphics g;
Image redPiece;
ImageIcon red;
JPanel gamePanel = new JPanel();
JLabel gameBackground = new JLabel(new ImageIcon("gameBackground.png"));
public void gamePanel (Graphics g, int xPos, int yPos)
{
gamePanel.setLayout(new OverlayLayout(gamePanel));
gamePanel.add(gameBackground);
add(gamePanel);
}
public void GraphicsConnectFour ()
{
red= new ImageIcon("red.png");
redPiece=red.getImage();
}
public void paintComponent(Graphics g)
{
repaint();
super.paintComponent(g);
GraphicsConnectFour();
gamePanel(g, 200, 200);
}
}
这就是gameBoard图片
这是对于gamePiece:
再次感谢任何可以帮助我的人! :)