| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 619 人关注过本帖
标题:帮忙!请给我看看出问题在哪里?编译没有问题,就是不能画图.
只看楼主 加入收藏
baixiaotian
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2005-4-9
收藏
 问题点数:0 回复次数:1 
帮忙!请给我看看出问题在哪里?编译没有问题,就是不能画图.
import java.awt.*;
import javax.swing.*;
import java.awt.GridLayout;

public class traffiLinght extends JFrame {


public traffiLinght() {
super("traffiLinght");
setSize(120,380);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pane = new JPanel();
GridLayout lay = new GridLayout(1,1);
Linght linght = new Linght();
pane.add(linght);
setContentPane(pane);
show();


}

public static void main(String[] args) {

traffiLinght frame = new traffiLinght();
}

}

class Linght extends JPanel implements Runnable {

Thread runner;
int y = 150;
Color[] color = {Color.red,Color.yellow,Color.green,Color.black};
Color col;
int i=0;
public Linght() {

if(runner==null){
runner = new Thread(this);
runner.start();
}
}

public void run() {

while(true) {
col = color[i];
i++;
y += 105;
if(y>360)
y = 150;
repaint();
try{
Thread.sleep(10000);
}catch(Exception e){}
if(i>2){
i = 0;
}

}


}

public void paintComponent(Graphics comp) {

Graphics2D comp2D = (Graphics2D)comp;
comp2D.setColor(Color.black);
comp2D.fillRect(0,0,120,400);
comp2D.setColor(col);
comp2D.fillRoundRect(5,y,100,100,100,100);

}
}

[此贴子已经被作者于2005-4-29 19:10:02编辑过]


搜索更多相关主题的帖子: 编译 画图 
2005-04-29 19:07
zhouyao_14
Rank: 1
等 级:新手上路
帖 子:196
专家分:0
注 册:2006-2-15
收藏
得分:0 
import java.awt.*;
import javax.swing.*;
import java.awt.GridLayout;
public class traffiLinght extends JFrame {
public traffiLinght() {
super("traffiLinght");
setSize(120,380);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pane = new JPanel();
GridLayout lay = new GridLayout(1,1);
Linght linght = new Linght();
pane.setLayout(lay);//少了这句很关键的啊
pane.add(linght);
setContentPane(pane);
show();
}
public static void main(String[] args) {
traffiLinght frame = new traffiLinght();
}
}
class Linght extends JPanel implements Runnable {
Thread runner;
int y = 150;
Color[] color = {Color.red,Color.yellow,Color.green,Color.black};
Color col;
int i=0;
public Linght() {
if(runner==null){
runner = new Thread(this);
runner.start();
} }
public void run() {
while(true) {
col = color[i];
i++;
y += 105;
if(y>360)
y = 150;
repaint();
try{
Thread.sleep(10000);
}catch(Exception e){}
if(i>2){
i = 0;
}
}
}
public void paintComponent(Graphics comp) {
Graphics2D comp2D = (Graphics2D)comp;
comp2D.setColor(Color.black);
comp2D.fillRect(0,0,120,400);
comp2D.setColor(col);
comp2D.fillRoundRect(5,y,100,100,100,100);
}
}

2006-03-03 22:28
快速回复:帮忙!请给我看看出问题在哪里?编译没有问题,就是不能画图.
数据加载中...
 
   



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

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