码迷,mamicode.com
首页 > 编程语言 > 详细

javax.swing.JComponent 调用顺序

时间:2016-01-12 22:59:29      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:

网上截取的,感觉挺有用,记录下来。

http://bbs.csdn.net/topics/310041707

java swing 感觉好复杂啊…………一点都不想用但是作业要用到 >_<;

javax.swing.JComponent类中
repaint()调用update() 
update()调用paint() 
paint()调用paintComponent(),paintBorder(),及paintChildren()

 

附代码

 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     @Override
22     protected void paintComponent(Graphics g) {
23         
24         System.out.println("GamePanel - ------------paintComponent");
25         
26         g.setColor(new Color(0xcfcfcf));    
27     }    
28     
29     @Override
30     public void paint(Graphics g) {
31         System.out.println("GamePanel - ------------paint");
32         super.paint(g);
33     }
34 
35     @Override
36     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 }

 

javax.swing.JComponent 调用顺序

标签:

原文地址:http://www.cnblogs.com/night-ride-depart/p/5125839.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!