I am new to java (and generally programming), and I try to make my first program. I was stuck in the same problem for about 5 hours, so I decided to ask for help.
Basically, I'm trying to create a program (2d game) that has about 20 positions on the board. Each position is either blue (owned by player1), or red (owned by player2), or black (not owned by anyone).
As I do this, basically I put in a method that calls the gameโs settings, and then a method that plays the game. I am working on an installation game, basically all it does is make an object of the Background class (extends JPanel and overrides paintComponent() ) and 20 objects of the Position class (extends JPanel and overrides paintComponent() ).
So far, I'm stuck with placing these Position objects on top of the Background object.
When I do this:
Background background= new Background(); frame.getContentPane().add(background); Position position1= new Position; frame.getContentPane().add(position1); frame.setVisible(true);
it shows only the circle and background, as I had hoped, if I add the position first and then the background, I only have the background and the circle.
In any case, I am new to java and still have problems finding solutions, but I tried to find solutions and I found many different solutions to this problem (for example, adding a position to the background first and then adding the background to the frame and etc.), but I could not get them to work.
I know that the way that I add both of them to a frame is (very likely) completely wrong, but I wrote it in such a way that you (hopefully) are sure that what I wrote really shows you that my the code for each of these classes draws something on the screen.
PS: I did not copy my code here, since most of the variable names and methods are not written in English, so it is quite difficult to read, but if you still think it is necessary, I will add This. In addition, I regret my probably stupid question, but Iโm kind of on the wall here, and I donโt know what else to try.