At the moment my program is just supposed to make a black square, however a window appears with a white canvas with nothing in it:
public static void main(String[] args) {
//basic window stuff
JFrame mainWindow = new JFrame("Moving Square");
mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainWindow.setVisible(true);
mainWindow.setSize(800,600);
mainWindow.setLocationRelativeTo(null);
Canvas mainCanvas = new Canvas();
mainWindow.add(mainCanvas);
//making graphics context for the canvas.
Graphics g = mainCanvas.getGraphics();
g.setColor(Color.black);
g.fillRect(250, 250, 250, 250);
}
What's the issue here? Have I misunderstood the usage of Graphics? (And before anyone suggests, I have already looked at docs and haven't been able to figure out the issue)