2015-12-21 108 views
0

我想創建一個專業的登錄/註冊表單,並在一分鐘我有這個代碼不工作:這將是我通過NetBeans創建的FPL論壇。FPL論壇申請

任何有關這個問題的幫助將不勝感激。

package fplforum; 

import java.awt.BorderLayout; 
import java.awt.FlowLayout; 
import java.awt.Font; 
import java.awt.event.ActionEvent; 
import java.awt.event.ActionListener; 
import java.io.IOException; 

import javax.swing.BorderFactory; 
import javax.swing.JButton; 
import javax.swing.JFrame; 
import javax.swing.JLabel; 
import javax.swing.JOptionPane; 
import javax.swing.JPanel; 

public class RegistrationForm extends JFrame implements ActionListener { 
    public RegistrationPanel panel; 
    public JButton submit, cancel; 
    public boolean done; 
    public Object UITools; 

    public RegistrationForm() { 
     JPanel main = new JPanel(); 
     main.setLayout(new BorderLayout()); 
     main.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10)); 

     JLabel label = new JLabel("Java CoG Kit Registration"); 
     label.setFont(Font.decode("Arial-bold-18")); 
     label.setBorder(BorderFactory.createEmptyBorder(5, 10, 20, 10)); 

     main.add(label, BorderLayout.NORTH); 

     panel = new RegistrationPanel(); 
     //panel.getReregister().addActionListener(this); 
     //main.add(panel, BorderLayout.CENTER); 
     setTitle("Java CoG Kit Registration Form"); 

     JPanel buttons = new JPanel(); 
     buttons.setLayout(new FlowLayout()); 

     submit = new JButton("Submit"); 
     submit.addActionListener(this); 
     buttons.add(submit); 

     //submit.setEnabled(panel.getReregister().isSelected()); 

     cancel = new JButton("Cancel"); 
     cancel.addActionListener(this); 
     buttons.add(cancel); 

     main.add(buttons, BorderLayout.SOUTH); 

     getContentPane().add(main); 
    } 

     @Override 
    public void actionPerformed(ActionEvent e) { 
     if (e.getSource() == submit) { 
      try { 
       panel.submit(false); 
       JOptionPane.showMessageDialog(this, "Thank you for registering the Java CoG Kit", 
         "Registration successful", JOptionPane.INFORMATION_MESSAGE); 
       done(); 
      } 
      catch (IOException e1) { 
       JOptionPane.showMessageDialog(this, "Could not submit registration information: " 
         + e.toString(), "Error", JOptionPane.ERROR_MESSAGE); 
      } 
     } 
     else if (e.getSource() == cancel) { 
      done(); 
     } 
     else { 
      //must be the don't send switch 
      submit.setEnabled(panel.getReregister().isSelected()); 
     } 
    } 

    private void done() { 
     done = true; 
     synchronized (this) { 
      notify(); 
     } 
    } 

    public void run() { 
     setSize(500, 380); 
     UITools.left(null, this); 
     setVisible(true); 
     try { 
      synchronized (this) { 
       while (!done) { 
        wait(); 
       } 
      } 
     } 
     catch (InterruptedException e) { 
      JOptionPane.showMessageDialog(this, "The main thread was interrupted", "Error", 
        JOptionPane.ERROR_MESSAGE); 
     } 
     setVisible(false); 
     dispose(); 
    } 

    public static void main(String[] args) { 
     //RegistrationFrame frame = new RegistrationFrame(); 
     //frame.run(); 
     //System.exit(0); 
    } 

    private static class RegistrationPanel { 

     public RegistrationPanel() { 
     } 

     private Object getReregister() { 
      throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. 
     } 

     private void submit(boolean b) { 
      throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. 
     } 
    } 
} 

它會編譯但沒有任何反應,我該如何解決它?

+0

*「我正在嘗試創建一個專業的登錄/註冊表單..」*順便說一句 - 爲此使用模式化的「JDialog」,而不是......無論代碼試圖實現哪種模式。 –

回答

1

如果它編譯並執行,那麼它的工作原理。它不工作,因爲你想它的工作,但它肯定有效。你有一個空的main方法,所以它不會做任何事情。這是你的主要方法:

public static void main(String[] args) { 
    //RegistrationFrame frame = new RegistrationFrame(); 
    //frame.run(); 
    //System.exit(0); 
} 

所有的行都被註釋掉了,所以不需要執行任何操作。在線路開始處取出//以採取一些行動。此外,據我所知,您沒有RegistrationFrameclass,您可能想要實例化RegistrationForm。另外,你爲什麼叫System.exit(0)

+0

它現在正在輸出此註釋:線程「main」中的異常java.lang.RuntimeException:不可編譯的源代碼 - 錯誤的sym類型:java.lang.Object.left \t at fplforum.RegistrationForm.run(RegistrationForm.java:89) \t at fplforum.RegistrationForm.main(RegistrationForm.java:108) Java結果:1 –

+1

*「現在是..」*請不要將此問答網站誤認爲服務檯。看起來你的第一個問題已經得到了回答,現在這已經變成了你在編譯運行代碼之前應該修復的編譯錯誤。但是還有一個單獨的問題。請[接受這個答案](http://meta.stackexchange.com/a/5235/155831)如果它幫助解決這個問題(然後問另一個問題的另一個問題)。 –