2013-08-02 1 views
0

현재 내가 만든 2 JFrame S, 로그인 인증 다른 하나씩 JFrame메인 메뉴이다. 문제는 프로그램을 컴파일하고 실행할 때 출력이 없으면 화면이 그냥 비어있는 것입니다. NetBeans 컴파일러는 실행 중이지만 아무 것도 표시되지 않음을 보여줍니다.프로그램 컴파일하여 실행되지만 아무 출력

내가 한 일은 다음과 같습니다. 이것은 로그인 프레임 코드입니다.

public class Login_screen extends javax.swing.JFrame { 

    /** 
    * Creates new form Login_screen 
    */ 
    public Login_screen() { 
     initComponents(); 
     this.getContentPane().setBackground(new Color(0,176,80)); //changed the background colour of the frame 
    } 

    JFrame frame=new JFrame(); 

    Main_Menu_screen openscreen=new Main_Menu_screen(); 
    createLogin_class createAccount=new createLogin_class(); 

    private void btnloginActionPerformed(java.awt.event.ActionEvent evt) {           
     try{ 
      libraryLogin_class loginObject=new libraryLogin_class(); 
      createAccount.login(); 
      String username=txtusername.getText(); 
      String password=new String(txtpassword.getPassword()); 

      FileInputStream file=new FileInputStream("login.txt"); 
      ObjectInputStream readFile=new ObjectInputStream(file); 

      loginObject=(libraryLogin_class)readFile.readObject(); 

      readFile.close(); 
      if(loginObject.getUsername().equals(username) && 
        loginObject.getPassword().equals(password)){ 

       JOptionPane.showMessageDialog(frame,"Login Successful"); 
       this.setVisible(false); 
       openscreen.setVisible(true); 
      } 
      else 
      { 
       JOptionPane.showMessageDialog(frame,"Username/Password Incorrect!"); 
      } 
     }catch(Exception e){} 
    } 

    public static void main(String args[]) { 
     java.awt.EventQueue.invokeLater(new Runnable() { 
      public void run() { 
       new Login_screen().setVisible(true); 
      } 
     }); 
    } 
} 

이들은 로그인 프레임과 관련된 두 개의 별도 클래스입니다.

public class createLogin_class { 

    /** 
    * Below method creates a login with the given 
    * username and password and passes them to createLogin method 
    */ 

    public void login(){ 

     String username="shehan"; 
     String password="123"; 

     createLogin_class user=new createLogin_class(); 
     user.createLogin(username, password); 
    } 

    /** 
    * This method calls the constructor of libraryLogin class 
    * and pass the parameters to create an object, 
    * after the object is created it is written in to a file. 
    * @param username 
    * @param password 
    */ 
    public void createLogin(String username,String password){ 

     libraryLogin_class logins=new libraryLogin_class(username,password); 

     try{ 
      FileOutputStream write=new FileOutputStream("login.txt"); 
      ObjectOutputStream writeTofile=new ObjectOutputStream(write); 

      writeTofile.writeObject(logins); 
      writeTofile.flush(); 
      writeTofile.close(); 
     }catch(Exception e){} 
    } 
} 

다른 클래스 :

public class libraryLogin_class implements Serializable { 

    private String username; 
    private String password; 

    public libraryLogin_class(){} 

    public libraryLogin_class(String username, String password) { 
     this.username = username; 
     this.password = password; 
    } 

    public String getUsername() { 
     return username; 
    } 

    public String getPassword() { 
     return password; 
    } 
} 
+0

Runnable 인터페이스를 사용하여 새 스레드를 만들었습니다. 그러나 당신은 스레드를 어디에서 시작 했습니까? 스레드가 작동하게하려면 스레드를 시작해야합니다. –

+0

왜 새로운 Login_screen(). setVisible (true);가 다른 스레드에 있습니까? – Lai

+6

Java 명명 규칙을 사용해보십시오. –

답변

0

나는 문제 나 자신을 발견 할 수 있었다. 문제는 재귀 때문에 발생했습니다. 생성자가 스스로를 호출하여 변경하고 프로그램이 작동하기 시작했습니다.