Я пытаюсь запустить проект Java с некоторыми Swing JFrames в качестве интерфейса.
Сборка прошла успешно
Мой метод Main:
public static void main(String[] args) {
new LoginFrame().setVisible(true);
}
Когда я запускаю проект, рамка открывается на несколько секунд, но это пустое окно (без текстовых полей, меток, кнопок и т. Д. c.), И затем я получаю следующую ошибку: Java возвращено: -1073740771 BUILD FAILED (общее время: 3 секунды).
Я использую Netbeans 8.2 в качестве IDE, а LoginFrame. java выглядит следующим образом:
package view;
import controller.AccountController;
import java.util.List;
import javax.swing.JOptionPane;
import model.Account;
public class LoginFrame extends javax.swing.JFrame {
private Account foundAccount;
public LoginFrame() {
initComponents();
setLocationRelativeTo(null);
setVisible(true);
refresh();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
usernameField = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
passwordField = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
loginButton = new javax.swing.JButton();
registerButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("username:");
jLabel2.setText("parola:");
loginButton.setText("Login");
loginButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
loginButtonMouseClicked(evt);
}
});
registerButton.setText("Inregistrare");
registerButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
registerButtonMouseClicked(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel1)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(passwordField, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE)
.addComponent(usernameField))
.addGap(142, 142, 142))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(199, 199, 199)
.addComponent(loginButton))
.addGroup(layout.createSequentialGroup()
.addGap(183, 183, 183)
.addComponent(registerButton)))
.addContainerGap(188, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(76, 76, 76)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(usernameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(passwordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addGap(18, 18, 18)
.addComponent(loginButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(registerButton)
.addContainerGap(89, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void loginButtonMouseClicked(java.awt.event.MouseEvent evt) {
String username = usernameField.getText();
String password = usernameField.getText();
List<Account> accounts = AccountController.getInstance().getAllAccounts();
boolean accountExists = false;
for (Account account : accounts){
if(account.getUsername() == username && account.getPassword() == password){
accountExists = true;
foundAccount = AccountController.getInstance().getAccountByIndex(account.getId());
break;
}
}
if(accountExists){
new MainFrame(foundAccount);
}else{
JOptionPane.showMessageDialog(this, "Username-ul sau parola nu sunt bine introduse!");
refresh();
}
}
private void refresh(){
usernameField.setText("");
passwordField.setText("");
}
private void registerButtonMouseClicked(java.awt.event.MouseEvent evt) {
new RegisterFrame();
}
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JButton loginButton;
private javax.swing.JTextField passwordField;
private javax.swing.JButton registerButton;
private javax.swing.JTextField usernameField;
// End of variables declaration
}
Пожалуйста, объясните мне, что именно я делаю неправильно.
Спасибо!