帮忙!请给我看看出问题在哪里?编译没有问题,就是不能画图.
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编辑过]