SMH.XAMPP & Netbeans 10 - PullRequest
       2

SMH.XAMPP & Netbeans 10

0 голосов
/ 06 марта 2019

Я создаю систему управления Java, которая использует базу данных MySQL (XAMPP & Netbeans 10). Все было хорошо, пока я не запустил "LoginForm" класс. Там написано:

У класса LoginForm нет метода Main.

Я удивлен, потому что я работал над другим классом, когда я увидел ошибки в своем классе, но вчера все работало вполне нормально с нулевыми ошибками. Я также могу видеть основной класс там. Что я могу сделать, чтобы это исправить?

`

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.*;
import java.sql.ResultSet;
import javax.swing.JFrame;
import java.awt.*;




public class LoginForm extends javax.swing.JFrame {

    private String sql;

    /**
     * Creates new form LoginForm
     */
    public LoginForm() {
        initComponents();
        username_error_lbl.setVisible(false);
        password_error_lbl.setVisible(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        login_panel = new javax.swing.JPanel();
        title_label = new javax.swing.JLabel();
        username_label = new javax.swing.JLabel();
        password_label = new javax.swing.JLabel();
        password_textfield = new javax.swing.JPasswordField();
        username_textfield = new javax.swing.JTextField();
        login_button = new javax.swing.JButton();
        cancel_button = new javax.swing.JButton();
        username_error_lbl = new javax.swing.JLabel();
        password_error_lbl = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        login_panel.setBackground(new java.awt.Color(153, 255, 204));
        login_panel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        title_label.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N
        title_label.setForeground(new java.awt.Color(0, 0, 0));
        title_label.setText("LoginForm");

        username_label.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
        username_label.setForeground(new java.awt.Color(0, 0, 0));
        username_label.setText("Username");

        password_label.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
        password_label.setForeground(new java.awt.Color(0, 0, 0));
        password_label.setText("Password");

        login_button.setText("Login");
        login_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                login_buttonActionPerformed(evt);
            }
        });

        cancel_button.setText("Cancel");
        cancel_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancel_buttonActionPerformed(evt);
            }
        });

        username_error_lbl.setForeground(new java.awt.Color(204, 0, 0));
        username_error_lbl.setText("*");

        password_error_lbl.setForeground(new java.awt.Color(255, 51, 51));
        password_error_lbl.setText("*");

        javax.swing.GroupLayout login_panelLayout = new javax.swing.GroupLayout(login_panel);
        login_panel.setLayout(login_panelLayout);
        login_panelLayout.setHorizontalGroup(
            login_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(login_panelLayout.createSequentialGroup()
                .addGroup(login_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(login_panelLayout.createSequentialGroup()
                        .addGap(128, 128, 128)
                        .addComponent(title_label, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, login_panelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(login_button)
                        .addGap(88, 88, 88)
                        .addComponent(cancel_button, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(login_panelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(login_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(password_label, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(username_label, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(login_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(username_textfield)
                            .addComponent(password_textfield))))
                .addGap(18, 18, 18)
                .addGroup(login_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(username_error_lbl)
                    .addComponent(password_error_lbl))
                .addContainerGap(38, Short.MAX_VALUE))
        );
        login_panelLayout.setVerticalGroup(
            login_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(login_panelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(title_label)
                .addGap(50, 50, 50)
                .addGroup(login_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(username_label)
                    .addComponent(username_textfield, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(username_error_lbl))
                .addGap(33, 33, 33)
                .addGroup(login_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(password_label)
                    .addComponent(password_textfield, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(password_error_lbl))
                .addGap(44, 44, 44)
                .addGroup(login_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cancel_button)
                    .addComponent(login_button))
                .addContainerGap(56, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(login_panel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(login_panel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>                        

    private void login_buttonActionPerformed(java.awt.event.ActionEvent evt) {                                             
        username_error_lbl.setVisible(false);
        password_error_lbl.setVisible(false);

        if(username_textfield.getText().equals("")){

            username_error_lbl.setVisible(true);

        }if(String.valueOf(password_textfield.getPassword()).equals("")){
        password_error_lbl.setVisible(true);
        }else{

         Connection conn = MyConnection.getConnection();
        PreparedStatement ps;
        try {
            ps=conn.prepareStatement("SELECT * FROM users WHERE username = ? AND password = ?");
            ps.setString(1, username_textfield.getText());
            ps.setString(2, String.valueOf(password_textfield.getPassword()));
           ResultSet rs = ps.executeQuery();

           if(rs.next()){

               MainForm mf = new MainForm();
               mf.setVisible(true);
               mf.pack();
               mf.setLocationRelativeTo(null);
               mf.setExtendedState(JFrame.MAXIMIZED_BOTH);
               MainForm.welcome_label.setText("Welcome *" +username_textfield.getText()+" *");
               MainForm.student_count_label.setText("Student Count=" +Integer.toString(MyFunction.countData("users")));
                MainForm.courses_count_label.setText("Course Count=" +Integer.toString(MyFunction.countData("courses")));
               this.dispose();

           }else{

           System.out.println("NO");
           }

        } catch (Exception e) {
        }

    }                                            

    private void cancel_buttonActionPerformed(java.awt.event.ActionEvent evt) {                                              
        System.exit(0);
    }                                             
    }
    /**
     * @param args the command line arguments
     */


}
}
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(LoginForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(LoginForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(LoginForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(LoginForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

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

    // Variables declaration - do not modify                     
    private javax.swing.JButton cancel_button;
    private javax.swing.JButton login_button;
    public static javax.swing.JPanel login_panel;
    private javax.swing.JLabel password_error_lbl;
    private javax.swing.JLabel password_label;
    private javax.swing.JPasswordField password_textfield;
    private javax.swing.JLabel title_label;
    private javax.swing.JLabel username_error_lbl;
    private javax.swing.JLabel username_label;
    private javax.swing.JTextField username_textfield;
    // End of variables declaration                   
}

`

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...