Javax. swing. JComponent call sequence, javax. swing

Source: Internet
Author: User

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 }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.