I am new in Java and I am currently creating a game with graphics. I have this class that extends from JFrame
. In this class, I have many JPanel
s that needs an image as background. As I know, to be able to paint images in the JPanel, I need to have a separate class that extends from JPanel and that class's paintComponent
method will do the work. But I don't want to make separate classes for each JPanel
, I have too many of them; and with the fact that I am only concerned with the background. How can I do this? is it with an anonymous inner class? How?
For better understanding I provided some code:
public GUI extends JFrame {
private JPanel x;
...
public GUI() {
x = new JPanel();
// put an image background to x
}