java.awt 程序
import javax.swing.*;
import java.awt.*;
public class Led{
private static int w = 250;
public static void main(String[] args){
JFrame j1 = new JFrame("LED Test");
j1.setSize(w,w);
Container c = j1.getContentPane();
c.setLayout(new FlowLayout());
LED1 grafic = new LED1(0);
j1.add(grafic);
}
}
class LED1 extends JLabel{
private int value;
private static final Icon images[]={
new ImageIcon("a0.gif"),
new ImageIcon("a1.gif"),
new ImageIcon("a2.gif"),
new ImageIcon("a3.gif")
};
LED1(int i){
setValue(i);
}
public int getValue(){
return value;
}
public void setValue(int i){
value=i;
setIcon(images[i]);
}
}
为什么运行是总是说Exception in thread "main" java.lang.NoClassDefFoundError: Led
参考答案:估计又是环境变量的问题.
代码不要setVisible吗?
就这样编译运行的话什么也不会有的.