import java.awt.*;
public class LoginFrame extends Frame
{
     public LoginFrame()
     {
          super("UserLogin");
          this.setSize(280,120);
          this.setBackground(Color.lightGray);
          this.setLocation(300,240);
          this.setLayout(new FlowLayout());
          this.add(new Lable("userid"));
          this.add(new TextField("user1",20));
          this.add(new Lable("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 LoginFrame();
     }
}
这个代码为什么不能运行出现窗口!

解决方案 »

  1.   

    把一楼说的哪个  LABEL 改了就可以了~
    你那代码我运行了  是可以用的~
      

  2.   

    最好把setVisible(true)放在对实例的调用里
      

  3.   

    import   java.awt.*;
    public   class   LoginFrame   extends   Frame
    {
              public   LoginFrame()
              {
                        super( "UserLogin ");
                        this.setSize(280,120);
                        this.setBackground(Color.lightGray);
                        this.setLocation(300,240);
                        this.setLayout(new   FlowLayout());
                        this.add(new   Lable( "userid "));//Label写错了
                        this.add(new   TextField( "user1 ",20));
                        this.add(new   Lable( "password "));//Label写错了
                        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   LoginFrame();
              }

      

  4.   


    package zhao;
    import java.awt.*; import javax.swing.JFrame;
    public class Test extends JFrame //建议用JFrame

         public Test() 
         { 
              super("UserLogin"); 
              this.setSize(280,120); 
              
              this.setBackground(Color.lightGray); 
              this.setLocation(300,240); 
              this.setLayout(new FlowLayout()); 
              this.add(new Label("userid")); //Label写错了,应该在编译期间出错的!
              this.add(new TextField("user1",20)); 
              this.add(new Label("password")); 
              this.add(new TextField(20)); 
              this.add(new Button("OK")); 
              this.add(new Button("Cancel")); 
              
              //加上这语句!
              this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
               
              this.setVisible(true); 
         } 
         public static void main(String args[]) 
         { 
              new Test(); 
         }