Do I actually call the paintComponent method I make when creating a rectangle in Java?

后端 未结 3 546
滥情空心
滥情空心 2021-01-21 00:49

This is my current RectangleComponent class and I add it to a panel in my main JFrame but it never appears. I thought it wasn\'t drawing so I decided to call the paintComponent

3条回答
  •  我在风中等你
    2021-01-21 01:51

    No need to pass JPanel to the constructor of RectangleComponent just to get Graphics, and no need to manually call paintComponent. See Painting in AWT and Swing. Check out this example that demonstrates a custom component that paints a rectangle.

提交回复
热议问题