编译没有问题,但是运行出现一对异常,希望高手能帮忙看看
代码如下:
import java.awt.*;
class Test extends Frame
{
public Test()
{
 super("User Login");
 this.setLocation(300,240);
 this.setSize(280,120);
 this.setBackground(Color.lightGray);
 this.add(new Label("userid"));
 this.add(new TextField(20));
 this.add(new Label("password"));
 this.add(new TextField(20));
 this.add(new Button ("OK"));
 this.add(new Button("Cancel"));

this.setVisible(true);
}
}
public class TestFrame
{
public static void main(String[] args)
{
new Test();
}
}

解决方案 »

  1.   

    Color.lightGray  这里你看看是不是大写的
    一般控件都是窗体的成员。你这样写把他们设为局部变量。执行完构造函数控件就消失了
      

  2.   

    没有问题啊!!!???
    我是这样运行的:
    package Package13;import java.awt.Button;
    import java.awt.Color;
    import java.awt.Label;
    import java.awt.TextField;import javax.swing.JFrame;public class MyTest3 extends JFrame{

    public MyTest3() 

    super("User Login"); 
    this.setLocation(300,240); 
    this.setSize(280,120); 
    this.setBackground(Color.lightGray); 
    this.add(new Label("userid")); 
    this.add(new TextField(20)); 
    this.add(new Label("password")); 
    this.add(new TextField(20)); 
    this.add(new Button ("OK")); 
    this.add(new Button("Cancel"));  this.setVisible(true); 
    }   
    public static void main(String[] args) 

    new MyTest3(); 

    }
      

  3.   

    Color.LIGHTGRAY或Color.lightgray都可以,偏偏就你写的那个不可以,注意这个字段是常量。
    建议你多用一下IDE的联想功能,让它联想出所需方法、字段,这样有助于提高准确率。
      

  4.   

    运行没问题,估计是你的JDK版本问题,1.4和1.5有语法差异。请注意JDK版本