Using paintComponent() to draw rectangle in JFrame

前端 未结 2 484
一整个雨季
一整个雨季 2021-01-18 22:02

I\'m trying to create a program that draws shapes (a rectangle on the example below) using JPanel\'s paintComponent(), but I can\'t get it to work and can\'t spot what is wr

2条回答
  •  借酒劲吻你
    2021-01-18 23:04

    you're never actually adding the panel to the frame, so it is never visible. you need something like

    frame.getContentPane().add( panel );
    

    why are you defining the drawpanel class inside the main method? that's rather odd.

提交回复
热议问题