setLayout(new AbsoluteLayout());
final JLabel loginLabel = new JLabel();
loginLabel.setHorizontalAlignment(SwingConstants.CENTER);
loginLabel.setText("Логин");
add(loginLabel, new AbsoluteConstraints(50, 20, 245, -1));
loginTextField = new JTextField();
loginTextField.setHorizontalAlignment(JTextField.CENTER);
add(loginTextField, new AbsoluteConstraints(50, 40, 245, -1));
final JLabel passwordLabel = new JLabel();
passwordLabel.setHorizontalAlignment(SwingConstants.CENTER);
passwordLabel.setText("Пароль");
add(passwordLabel, new AbsoluteConstraints(50, 71, 245, -1));
passwordTextField = new JPasswordField();
passwordTextField.setHorizontalAlignment(JTextField.CENTER);
add(passwordTextField, new AbsoluteConstraints(50, 91, 245, -1));
loginButton = new JButton();
loginButton.setText("Войти");
loginButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
if (state == STATE_LOGIN) {
checkAuth();
}
}
});
add(loginButton, new AbsoluteConstraints(112, 129, 125, -1));
signupButton = new JButton();
signupButton.setText("Регистрация");
signupButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
if (state == STATE_LOGIN) {
// Показываем форму регистрации
confirmPasswordTextField.setVisible(true);
loginButton.setVisible(false);
parentFrame.setTitle("Регистрация в системе");
state = STATE_SIGNUP;
} else {
// Завершаем регистрацию и переходим в режим авторизации
if (!checkSignUpCredentials()) {
return;
}
backToAuth();
}
}
});
add(signupButton, new AbsoluteConstraints(112, 158, 125, -1));
cancelButton = new JButton();
cancelButton.setText("Отмена");
cancelButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
if (state == STATE_SIGNUP) {
// Отменяем регистрацию
backToAuth();
} else {
// Закрываем окно
parentFrame.setVisible(false);
}
}
});
add(cancelButton, new AbsoluteConstraints(112, 187, 125, -1));
confirmPasswordTextField = new JPasswordField();
confirmPasswordTextField.setHorizontalAlignment(JTextField.CENTER);
add(confirmPasswordTextField, new AbsoluteConstraints(50, 120, 245, -1));
confirmPasswordTextField.setVisible(false);
}