I want to paint Graphics on JPanel. Right now, what I am doing is, I use the paintComponent method to define the drawing:
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.BLACK);
g.fillRect(10,10,100,100);
}
Then I call repaint() wherever I want to put the graphics.
But I wonder if there is a way to add Graphics to JPanel just like adding components without using this paintComponent method: panel.add(myComponent). I saw that Graphics type cannot be initiated, but maybe there might be another type to let me do that.
I'm pretty sure lots of GUIs such as FANG Engine have this option, but all the examples I saw with Swing was using this method. Any suggestions to do without this? Because it is messing up with the overall design of my program sometimes.
Thanks in advance.