JComponent size issue

前端 未结 2 1848
轮回少年
轮回少年 2021-01-22 13:24

I have a JComponent subclass that I am using to draw shapes onto my screen. In the constructor, I am trying to set ballX and ballY to half

2条回答
  •  萌比男神i
    2021-01-22 13:52

    I agree with trashgod's answer. (+1)

    Move the ballX and ballY in the paintComponent(g) like this

    if (ballX==0 && ballY==0) {
        ballX = getWidth()/2;
        ballY = getHeight()/2;
    }
    

提交回复
热议问题