Strange JFrame Behavior

前端 未结 3 484
长情又很酷
长情又很酷 2020-12-12 02:00

I have the following program which has some very strange and unwanted behavior when it runs. Its supposed to have two buttons, \"Start\" and \"Stop, but when I click \"Start

3条回答
  •  执念已碎
    2020-12-12 02:37

    I wish I could offer a solution, but as of yet I haven't found one. I can tell you the root of the "problem" here lies in the way you are drawing the Center section of your BorderLayout. You are overriding the whole paintComponent() function for this program and having whatever it creates put into the Center of your BoarderLayout. In this case, each time you click a button, the program calls the repaint to draw the image of a clicked button, but since you have also added ANY of the drawn objects to the Center panel, it also is drawn there. Since this specific repaint doesn't specify a location, it goes in the upper left corner.

提交回复
热议问题