2013-08-03 56 views
1

嗨,我做了一个演示java框架,但编译后,我试图运行它,但框架没有打开。我没有编译ñ没有任何错误可能有人请帮我这 这是基本的代码,并请看着它ñ帮我感谢名单很多演示框架但没有工作

import javax.swing.*; 
import java.awt.*; 

class DemoFrame extends JFrame 
{ 
     JPanel pmain,pmaster; 
     JLabel lname,lclas,lyear,lroll,lemail,lphn; 
     JTextField name,clas,year,roll,email,phn; 
     JButton submit,reset; 
     JPasswordField pass; 

     void demoFrame() 
     { 
       setTitle("Registration Form"); 
       setSize(700,700); 

       lname=new JLabel("Name"); 
       lclas=new JLabel("clas"); 
       lyear=new JLabel("Year"); 
       lemail=new JLabel("Email"); 
       lphn=new JLabel("Phone"); 
       lroll=new JLabel("Roll No."); 

       name=new JTextField(10); 
       clas=new JTextField(10); 
       year=new JTextField(10); 
       email=new JTextField(10); 
       phn=new JTextField(10); 
       roll=new JTextField(10); 

       submit=new JButton("Register Now"); 
       reset=new JButton("Reset"); 

       pmain=new JPanel(new GridLayout(5,2,3,3)); 
         pmain.add(lname); 
         pmain.add(name); 

         pmain.add(lclas); 
         pmain.add(clas); 

         pmain.add(lroll); 
         pmain.add(roll); 

         pmain.add(lemail); 
         pmain.add(email); 

         pmain.add(lphn); 
         pmain.add(phn); 

       pmaster=new JPanel(); 
         pmaster.add(pmain); 
     } 

     public static void main(String args[]) 
     { 
       DemoFrame obj=new DemoFrame(); 
       obj.demoFrame(); 

     } 
} 

回答

12

demoFrame()或主要方法调用setVisible()的框架:

public static void main(String args[]) 
{ 
    DemoFrame obj=new DemoFrame(); 
    obj.demoFrame(); 
    obj.setVisible(true) 
} 

而且我注意到,你没有添加pmaster的框架,加入这一行:

pmaster.add(pmain); 
    add(pmaster,BorderLayout.CENTER);// PAGE_START , PAGE_END, LINE_START, LINE_END Also can be used 

另一件事,也加上这一行:

setTitle("Registration Form"); 
setSize(700,700); 
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//<<<