Eclipse:JAVAW终止了

时间:2015-11-22 08:07:41

标签: java eclipse javaw

也许我误解了一些东西,我的java应用程序不会运行。我已经完成了以下Login Form并按f12来运行我的java应用程序。

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;

import javax.swing.*;


public class Cl_Login extends JFrame {

    Cl_Register registerform = new Cl_Register();
    Command cmd = new Command();
    Validate val = new Validate();
    public static Cl_Login logform = null;
    static private String form_name = "Gamestops Login";
    static private String lbl_judul = "GameStops";
    static private String lbl_username = "Username";
    static private String lbl_password = "Password";
    static private String lbl_buttonlogin = "Login";
    static private String lbl_buttonreset = "Reset";
    static private String lbl_buttonregister = "Register";          

    public void addComponentsToPane(Container pane) {                       
        JButton buttonlogin,buttonregister,buttonreset; 
        JLabel labelatas,labelbawah,labelusername,labelpassword;
        JPanel panelbawah,paneltengah,panelkiri,panelkanan;
        final JTextField textusername;
        final JPasswordField textpassword;

        labelatas = new JLabel(lbl_judul,SwingConstants.CENTER);        
        pane.add(labelatas, BorderLayout.PAGE_START);


        paneltengah= new JPanel(new GridLayout(2,2));

        labelusername = new JLabel(lbl_username,SwingConstants.CENTER);                                                         
        paneltengah.add(labelusername);

        labelpassword = new JLabel(lbl_password,SwingConstants.CENTER);
        paneltengah.add(labelpassword);

        textusername = new JTextField(20);
        textpassword = new JPasswordField(20);
        paneltengah.add(textusername);
        paneltengah.add(textpassword);
        pane.add(paneltengah, BorderLayout.LINE_START);         

        panelbawah = new JPanel(new FlowLayout(FlowLayout.CENTER)); 
        buttonlogin = new JButton(new AbstractAction(lbl_buttonlogin) {

            @Override
            public void actionPerformed(ActionEvent e) {

                String inusernamenya = textusername.getText();
                String inpassword = textpassword.getText();

                if(val.isEmpty(inusernamenya) || val.isEmpty(inpassword))
                {
                    cmd.printError("Username or Password must be filled !", form_name);
                }
                else
                {
                    cmd.printSuccess("Login Success !", form_name);
                    Cl_Main mainform = new Cl_Main();
                    mainform.showFormAdmin(true);
//                  cmd.printSuccess(System.getProperty("sun.arch.data.model"), form_name);
//                  ConnectAccess ca = new ConnectAccess();
//                  ResultSet resultnya = ca.getData("Select * from MsUser where Username = '"+inusernamenya+"' and password = '"+inpassword+"'");
//                  try {
//                      if(resultnya.next())
//                      {
//                          
//                          cmd.printSuccess(inusernamenya+" dan "+inpassword+" berhasil login", form_name);                            
//                          Cl_Main mainform = new Cl_Main();                           
//                      }
//                      else
//                      {
//                          cmd.printError("Invalid username or password !", form_name);
//                      }
//                  } catch (SQLException e) {
//                      // TODO Auto-generated catch block
//                      e.printStackTrace();
//                  }

                    //if user role admin blabla user blabla             
                    //show MDI

                }
            }
        });         
        buttonreset = new JButton(lbl_buttonreset);
        buttonreset.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent arg0) { 
                textusername.setText("");
                textpassword.setText("");
            }
        });
        buttonregister = new JButton(lbl_buttonregister);       
                buttonregister.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent arg0) {
                // TODO Auto-generated method stub
//              new Cl_Register().setVisible(true);
                registerform.showRegister();
                setVisible(false);
            }
        });
        panelbawah.add(buttonlogin);
        panelbawah.add(buttonreset);        
        panelbawah.add(buttonregister);
        pane.add(panelbawah, BorderLayout.PAGE_END);

    }   

    public Cl_Login() {
        setVisible(true);       
        this.setTitle(form_name);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setResizable(false);        
        addComponentsToPane(this.getContentPane());
        pack();
        setLocationRelativeTo(null);

    }

    /**
     * @param args
     */
    public static void main(String[] args) {        
        Cl_Login login = new Cl_Login();
    }

}

然后,eclipse显示以下错误 enter image description here

我不知道发生了什么,因为在过去的几个小时里一切都很好。我相信我错误地点了些什么或者在我的日食中激活了一些东西。

为什么我的登录表单没有显示?

如果下面的图片与我的登录表单问题有关,请输入idk enter image description here

解决了,问题来自以下代码

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;


public class Cl_Register{

//  Cl_Login loginform = new Cl_Login(); << done by markin as comment, still not understand why does this line causing the problem
    Command cmd = new Command();
    Validate val = new Validate();
    static private String form_name = "Register Form";
    static private String lbl_judul = "Register";
    static private String lbl_name = "Name";
    static private String lbl_username = "Username";
    static private String lbl_password = "Password";
    static private String lbl_gender = "Gender";
    static private String lbl_email = "Email";
    static private String lbl_hobby = "Hobby";
    static private String lbl_role = "Role";
    static private String lbl_buttonlogin = "Login";
    static private String lbl_buttonreset = "Reset";
    static private String lbl_buttonregister = "Register";  




    public void showRegister() {        

        JFrame frame = new JFrame(form_name);
        JButton buttonlogin,buttonregister,buttonreset; 
        JLabel labelatas,labeljudul,labelname,labelusername,labelpassword,labelgender,labelemail,labelhobby,labelrole;
        JPanel panelbawah,paneltengah,panelkiri,panelkanan,panelgender;
        final JTextField textname,textusername,textemail;
        final JPasswordField textpassword;
        JRadioButton radiobuttonmale,radiobuttonfemale;
        JComboBox comboboxhobby,comboboxrole;

        String[]listhobby = {"Coding", "Swimming", "Racing", "Playing Football", "Playing Basketball", "Painting", "Drawing"};
        String[]listrole={"Admin","User"};
        labelatas = new JLabel(lbl_judul,SwingConstants.CENTER);

        frame.add(labelatas,BorderLayout.PAGE_START);

        panelkiri = new JPanel(new GridLayout(7,1));        
        labelname = new JLabel(lbl_name,SwingConstants.LEFT);       
        labelusername = new JLabel(lbl_username,SwingConstants.LEFT);                                                                           
        labelpassword = new JLabel(lbl_password,SwingConstants.LEFT);               
        labelgender = new JLabel(lbl_gender,SwingConstants.LEFT);               
        labelemail = new JLabel(lbl_email,SwingConstants.LEFT);         
        labelhobby = new JLabel(lbl_hobby,SwingConstants.LEFT);             
        labelrole = new JLabel(lbl_role,SwingConstants.LEFT);               
        panelkiri.add(labelname);
        panelkiri.add(labelusername);
        panelkiri.add(labelpassword);       
        panelkiri.add(labelemail);  
        panelkiri.add(labelgender);
        panelkiri.add(labelhobby);
        panelkiri.add(labelrole);
        frame.add(panelkiri, BorderLayout.LINE_START);  

        panelkanan = new JPanel(new GridLayout(7,1));   
        panelgender = new JPanel(new FlowLayout(FlowLayout.CENTER));
        textname = new JTextField(5);       
        textusername = new JTextField(20);
        textpassword = new JPasswordField(20);
        textemail = new JTextField(20);
        comboboxhobby = new JComboBox(listhobby);
        comboboxrole = new JComboBox(listrole);


        radiobuttonmale = new JRadioButton("Male");
        radiobuttonfemale = new JRadioButton("Female");
        panelgender.add(radiobuttonmale);
        panelgender.add(radiobuttonfemale);

        comboboxhobby.setSelectedIndex(0);
        comboboxrole.setSelectedIndex(0);
        radiobuttonmale.setSelected(true);


        panelkanan.add(textname);       
        panelkanan.add(textusername);
        panelkanan.add(textpassword);
        panelkanan.add(textemail);
        panelkanan.add(panelgender);        
        panelkanan.add(comboboxhobby);
        panelkanan.add(comboboxrole);

        frame.add(panelkanan, BorderLayout.LINE_END);
        panelbawah = new JPanel(new FlowLayout(FlowLayout.CENTER)); 
        buttonlogin = new JButton(lbl_buttonlogin);     
        buttonlogin.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent arg0) {         

            }
        });
        buttonreset = new JButton(lbl_buttonreset);
        buttonreset.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent arg0) {
                textname.setText("");
                textusername.setText("");
                textpassword.setText("");
                textemail.setText("");
            }
        });
        buttonregister = new JButton(lbl_buttonregister);
        buttonregister.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent arg0) {
                // TODO Auto-generated method stub


            }
        });
        panelbawah.add(buttonlogin);
        panelbawah.add(buttonreset);        
        panelbawah.add(buttonregister);
        frame.add(panelbawah, BorderLayout.PAGE_END);
        frame.pack();
        frame.setVisible(true);     
        frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
        frame.setResizable(false);                      
        frame.setLocationRelativeTo(null);

    }   


    public Cl_Register() {              

    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub                  
    }

    public void actionPerformed(ActionEvent arg0) {
        // TODO Auto-generated method stub

    }

}

我仍然不明白错误来自Cl_Register

2 个答案:

答案 0 :(得分:1)

正如gamliela所指出的,你的主要是空的。它不可能是它早些时候工作。如果您做了一些更改,请查看您当地的历史记录。

答案 1 :(得分:-1)

更改main()调用Cl_Login构造函数,如下所示:

public static void main(String[] args) {
    Cl_Login login = new Cl_Login();       
}