I’m laying the groundwork for an applet, but for now I’m testing it out as an application. Anyway, I originally had it such that I called repaint() at the standard 60 times a second. But I found that this flickered a lot and was not very good. I looked into it and found that I should be using “paintComponent()” to paint on a contentPane() instead of overriding the regular paint method.
So I have an class called “GamePanel” which extends a JPanel, and here is it’s paint component method:
@Override
public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
Rectangle rect = new Rectangle(100, 100, 100, 100);
g2d.fill(rect);
}
All it does is draw a black square
And here’s how I set the panel up at the start of the program:
GamePanel gamePanel = new GamePanel();
GameComponent gameComponenet = new GameComponent();
JFrame frame = new JFrame("Video Game");
gamePanel.add(gameComponenet, BorderLayout.CENTER);
frame.setContentPane(gamePanel);
Now I’m just kinda confused… How do I access the “paintComponent()” method in the GamePanel class WITHOUT putting it in the overridden paint() method? I found that when I did the following in conjunction with the 60fps repaint(), It just flickered anyway, so that can’t be the answer
@Override
public void paint(Graphics g) {
gamePanel.paintComponent(g);
}
Thanks