0

First of all, I have two class' GameGUI and paintCircle

In paintCircle I'm drawing my circle on top of my JPanel image from GameGUI, but with the standard grey-ish background

  • I only want the circle to show, what am I missing? I've been through all the different settings without any luck.

The same goes for when I've tried to put in a new image of a triangle (.PNG-file), how do I only make the triangle visible or even change its size?

public void paintComponent(Graphics g){
        Graphics2D g2d = (Graphics2D) g;

        Ellipse2D.Double e = new Ellipse2D.Double(200,200,200,200);
        g2d.setColor(Color.red);
        g2d.fill(e);
        }
Narj
  • 39
  • 5
  • Generally, don't use multiple components for this. Use a single rendering surface (ie `JPanel`). Render the image and then render any graphics you want over it – MadProgrammer May 13 '22 at 15:03
  • Could you explain why not to use multiple components? - Regarding your answer, it is what I'm doing without success. – Narj May 13 '22 at 15:13
  • Because you have problems like the one you have now, it's also a "heavy" load, as apposed to rendering primitive graphics. If you need something a little more complex or layered, consider devising a "paintable" concept which can take a reference of `Graphics2D` and perform it's painting operations. Remember, components also have a concept of position and size, and painting it done at the components position offset (0x0 is the components top/left position) – MadProgrammer May 13 '22 at 15:30
  • Okay, thank you I will have that in mind. It worked perfectly, TY. Do you know of any setting where I can change the size of an image/drawing (PNG-file). – Narj May 13 '22 at 16:04
  • [Java: maintaining aspect ratio of JPanel background image](https://stackoverflow.com/questions/11959758/java-maintaining-aspect-ratio-of-jpanel-background-image/11959928#11959928) – MadProgrammer May 13 '22 at 16:09
  • That is way to complicated for me at this point, but thank you. – Narj May 13 '22 at 17:08

0 Answers0