| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 596 人关注过本帖
标题:问关于线程画图的
只看楼主 加入收藏
luo007nan
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2009-4-20
结帖率:50%
收藏
 问题点数:0 回复次数:1 
问关于线程画图的
class pc1{                           //画一个矩形
    public pc1(Color c,int x,int y){
        this.c=c;this.x=x;this.y=y;
    }
    Color c;int x,y;
    public void draw(Graphics g){
        g.setColor(c);
        g.fillRect(x, y, 50, 50);
    }
}

class Producer extends Thread{          //线程
    public Producer(Graphics2D g1){
        this.g=g1;
    }
    pc1 pct=new pc1(Color.BLUE,50,50);
    Graphics2D g;
    public void run(){
        while(true){         
            try {
                pct.draw(g);            //调用pctr的draw()方法
                Thread.sleep(5000);
       }
       catch (Exception ex) {}
        }
    }
}

class contentpanel extends JPanel{
    Graphics2D g2;
    public void paintComponent(Graphics g){
        super.paintComponent(g);
        g2=(Graphics2D)g;
        pt.draw(g);
        c1.start();p1.start();
    }
    pc1 pt=new pc1(Color.BLUE,50,50);
    Producer p1=new Producer(g2);
    Cus c1=new Cus(g2);
}
---------------------------------------------
以上是一部分代码。为啥我直接调用方法以就行了..但是用个线程转了下就不行了..麻烦高手指教下
顺便问下怎么用 图形界面模拟生产消费者的问题
搜索更多相关主题的帖子: 画图 线程 
2009-11-23 12:47
haizeng
Rank: 2
来 自:xdpsj.com
等 级:等待验证会员
帖 子:61
专家分:36
注 册:2009-11-30
收藏
得分:0 
恩 gui 部分吧

[url=http://www./]石料生产线[/url]
[url=http://www.]破碎机[/url]
2009-11-30 10:33
快速回复:问关于线程画图的
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012790 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved