Drawing a Label Containing an Icon Showing a Circle

前端 未结 1 649
迷失自我
迷失自我 2021-01-22 06:14

So I am trying to draw a label which contains an icon showing a circle. The circle will initially be filled red, and then depending on which of the 3 buttons I press, it will ei

相关标签:
1条回答
  • 2021-01-22 06:26
    Ellipse2D.Double circle = new Ellipse2D.Double(50, 50, 10, 10);
    

    The size of the icon is (10, 10). 50, is outside the bounds of the Icon. Painting is done relative to the icon so the ellipse should be:

    Ellipse2D.Double circle = new Ellipse2D.Double(0, 0, 10, 10);
    

    it will either change to green, blue, or red using repaint.

    Your ColorChanger class will need a setColor(Color color) method so that you can dynamically change the color to be painted. The paintIcon() method should then use this color.

    0 讨论(0)
提交回复
热议问题