Javax. swing. JComponent call sequence, javax. swing
I found it useful and recorded it online.
Http://bbs.csdn.net/topics/310041707
Java swing feels complicated ............ I don't want to use it at all, but I want to use it for my job >_<;
Javax. swing. JComponent class
Repaint () calls update ()
Update () call paint ()
Paint () calls paintComponent (), paintBorder (), and paintChildren ()
Code attachment
1 package com.test; 2 import java.awt.Color; 3 import java.awt.Graphics; 4 5 import javax.swing.JFrame; 6 import javax.swing.JPanel; 7 8 public class GamePanel extends JPanel{ 9 10 private static final long serialVersionUID = 1L;11 public GamePanel(){12 13 }14 15 public void display(){ 16 System.out.println("GmaePanel - display");17 18 this.repaint();19 }20 21 @Override22 protected void paintComponent(Graphics g) {23 24 System.out.println("GamePanel - ------------paintComponent");25 26 g.setColor(new Color(0xcfcfcf)); 27 } 28 29 @Override30 public void paint(Graphics g) {31 System.out.println("GamePanel - ------------paint");32 super.paint(g);33 }34 35 @Override36 public void update(Graphics g) {37 System.out.println("GamePanel - ------------update");38 super.update(g);39 }40 41 public static void main(String[] args){42 JFrame frame = new JFrame();43 frame.setSize(300,300);44 GamePanel gp = new GamePanel();45 frame.add(gp);46 frame.setVisible(true);47 gp.display();48 }49 }