A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 轻松过关 中级黑马   /  2012-12-19 10:15  /  1116 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

public class aa extends JFrame {
        public aa() {
                this.setBounds(100, 100, 400, 400);
                this.setLayout(null);
                this.setVisible(true);

                bb l = new bb();
                l.setBounds(20, 20, 15, 15);

                this.add(l);

        }

        public static void main(String[] args) {
                new aa();

        }

}
class bb extends JLabel{
        public bb() {
                setSize(new Dimension( 10, 10));
                setPreferredSize(new Dimension( 10, 10));
        }
        @Override
        protected void paintComponent(final Graphics arg0) {
                /*ScheduledExecutorService timer=Executors.newScheduledThreadPool(1);
                timer.scheduleAtFixedRate(
                                new Runnable(){
                                        @Override
                                        public void run() {
                                                //画不出图来
                                                Graphics g=arg0;
                                                //获得这个画图笔就能画出图来
                                                //Graphics g=bb.this.getGraphics();
                                                g.fillOval(0, 0, 15, 15);
                                                System.out.println(new Date(System.currentTimeMillis()));
                                        }
                                },
                                2,
                                3,
                                TimeUnit.SECONDS);*/
                //这里也能画出图来
                //arg0.fillOval(0, 0, 15, 15);
                //这个也画不出图来?
                this.getGraphics().fillOval(0, 0, 15, 15);
                //new cc(arg0);
        }

}上面所得的画笔为什么有的能画出图来?有的画不出来?求解!!!

评分

参与人数 1技术分 +1 收起 理由
刘芮铭 + 1

查看全部评分

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马