I feel like I went through everything I needed to do:
- Make a graphics class that has a void called paintComponent and extends JComponent
- Have that paintComponent void have Graphics g as a parameter, then do Graphics2D g2d = (Graphics2D) g;
- Add the Graphics class to my JFrame
I can't find anything wrong with this, so I'm a little confused.
My code is here:
public static void main(String[] args) {
DragonEscape game = new DragonEscape();
frame.setTitle(title);
frame.setSize(1000, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.add(new Graphicsa());
frame.add(game);
}
and
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JComponent;
public class Graphicsa extends JComponent {
private static final long serialVersionUID = 1L;
public Graphics g;
protected void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g.fillRect(0, 0, 1000, 500);
g.setColor(Color.gray);
g.fillRect(0, 0, 100, 100);
}
}