Basically, I'm trying to do a test on my GUI to make sure it will paint. Here are my classes: Game
public class Game {
private static GUI gui = new GUI();
private static int[][] pixels = new int[10][10];
public static void main(String[] args) {
}
public void startGame() {
System.out.print("start");
gui.setGameFrame();
}
public static GUI getGUI() {
return gui;
}
public static int[][] getGraphics() {
return pixels;
}
}
GUI
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class GUI extends JPanel {
private static Game game = new Game();
private static JPanel panel = new JPanel();
private static JFrame frame = new JFrame();
final private static int FRAME_HEIGHT = 500;
final private static int FRAME_WIDTH = 500;
//Board size 25x25px
final private static int PIXEL_SIZE = 20;
public GUI () {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
setAttributes();
makeMenu();
}
});
}
public static void setAttributes() {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("");
frame.setBackground(Color.black);
frame.setVisible(true);
}
private static void makeMenu() {
JButton start = new JButton("Start");
start.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
game.startGame();
}
});
panel.add(start);
frame.add(panel);
frame.pack();
}
public void setGameFrame() {
panel.removeAll();
frame.getContentPane().add(Game.getGUI());
frame.setTitle("Snake v0.1");
frame.setSize(getPreferredSize());
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.white);
g.fillRect(5, 5, 10, 10);
}
@Override
public Dimension getPreferredSize() {
return new Dimension(FRAME_WIDTH, FRAME_HEIGHT);
}
public void paintGraphics() {
int[][] pixels = Game.getGraphics();
}
}
I've attempted to debug it, but cannot trace why it isn't functioning.
I believe it's something to do with:
frame.getContentPane().add(Game.getGUI());
But I'm not certain.