How to move two circles together in a JFrame from two different classes

前端 未结 2 1555
孤独总比滥情好
孤独总比滥情好 2020-12-21 19:25

I am trying to display the two circles moving together on a single frame through two different classes. But only one is shown moving at a time,even though value of \"

2条回答
  •  太阳男子
    2020-12-21 19:43

    When two components are added to a single constraint of a BorderLayout (the default layout for a JFrame), only one is displayed.

    The typical way to do this is not to design the custom painting in a JComponent (like JPanel) but instead to have them as simple classes which can paint(Graphics) or draw(Graphics) when requested to do so.

    Then extend a single JComponent that iterates a list of the drawable components and paints each one.

提交回复
热议问题