Concerns about the function of JPanel: paintcomponent()

前端 未结 3 399
长发绾君心
长发绾君心 2020-11-28 07:49

hello I\'m new in java programming, and i need someone explaining me these lines of code:

 public class drawpanel extends JPanel
 {
     public void paintCom         


        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 08:03

    paintComponent() is a method originally defined in abstract class JComponent. Components that extend JComponent directly indirectly (if exposed) have the option to override paintComponent(). the call to super.paintComponent(g) calls the super class's implementation of paintComponent() (in your case it's JPanel's). You would want to override paintComponent() if you want to do other stuff with Graphics g besides what JPanel already does.

提交回复
热议问题