implement RegisterWindow & EasymailWindow
parent
d7b5b91d6d
commit
956035612e
|
@ -26,6 +26,8 @@ public class UserManager {
|
|||
|| passwordConfirmation.length == 0) {
|
||||
throw new IllegalArgumentException("All fields are required!");
|
||||
}
|
||||
if (password.length < 5)
|
||||
throw new IllegalArgumentException("Password should be stronger!");
|
||||
|
||||
if (!Arrays.equals(password, passwordConfirmation))
|
||||
throw new IllegalArgumentException("Passwords do not match!");
|
||||
|
@ -123,32 +125,19 @@ public class UserManager {
|
|||
|
||||
private int getMonthNumber(String txtMonth) {
|
||||
switch (txtMonth.toLowerCase()) {
|
||||
case "januar":
|
||||
return 1;
|
||||
case "februar":
|
||||
return 2;
|
||||
case "märz":
|
||||
return 3;
|
||||
case "april":
|
||||
return 4;
|
||||
case "mai":
|
||||
return 5;
|
||||
case "juni":
|
||||
return 6;
|
||||
case "juli":
|
||||
return 7;
|
||||
case "august":
|
||||
return 8;
|
||||
case "september":
|
||||
return 9;
|
||||
case "oktober":
|
||||
return 10;
|
||||
case "november":
|
||||
return 11;
|
||||
case "dezember":
|
||||
return 12;
|
||||
default:
|
||||
return 0;
|
||||
case "januar":return 1;
|
||||
case "februar":return 2;
|
||||
case "märz":return 3;
|
||||
case "april":return 4;
|
||||
case "mai":return 5;
|
||||
case "juni":return 6;
|
||||
case "juli":return 7;
|
||||
case "august":return 8;
|
||||
case "september":return 9;
|
||||
case "oktober":return 10;
|
||||
case "november":return 11;
|
||||
case "dezember":return 12;
|
||||
default:return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,116 @@
|
|||
package gui;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class EasyMailWindow extends JFrame {
|
||||
|
||||
private JTable inboxTable;
|
||||
private DefaultTableModel inboxTableModel;
|
||||
|
||||
public EasyMailWindow() {
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 905, 702);
|
||||
setLocationRelativeTo(null);
|
||||
|
||||
JPanel contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
// Profile Panel
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBackground(new Color(230, 230, 230));
|
||||
panel.setBorder(new LineBorder(new Color(0, 0, 0), 2));
|
||||
panel.setBounds(10, 273, 223, 379);
|
||||
contentPane.add(panel);
|
||||
panel.setLayout(null);
|
||||
|
||||
JLabel sentEmails = new JLabel("Sent");
|
||||
sentEmails.setForeground(new Color(0, 0, 255));
|
||||
sentEmails.setFont(new Font("Times New Roman", Font.PLAIN, 22));
|
||||
sentEmails.setBounds(10, 11, 165, 39);
|
||||
panel.add(sentEmails);
|
||||
|
||||
JLabel trash = new JLabel("Trash");
|
||||
trash.setForeground(new Color(0, 0, 255));
|
||||
trash.setFont(new Font("Times New Roman", Font.PLAIN, 22));
|
||||
trash.setBounds(10, 61, 165, 39);
|
||||
panel.add(trash);
|
||||
|
||||
JPanel panel_1 = new JPanel();
|
||||
panel_1.setBackground(new Color(230, 230, 230));
|
||||
panel_1.setBorder(new LineBorder(new Color(0, 0, 0), 2));
|
||||
panel_1.setBounds(10, 11, 223, 239);
|
||||
contentPane.add(panel_1);
|
||||
panel_1.setLayout(null);
|
||||
|
||||
JLabel profile = new JLabel("Profile");
|
||||
profile.setFont(new Font("Times New Roman", Font.BOLD, 30));
|
||||
profile.setBounds(10, 11, 203, 41);
|
||||
panel_1.add(profile);
|
||||
|
||||
JLabel name = new JLabel("Full Name: ");
|
||||
name.setFont(new Font("Times New Roman", Font.PLAIN, 20));
|
||||
name.setBounds(10, 63, 203, 41);
|
||||
panel_1.add(name);
|
||||
|
||||
JLabel username = new JLabel("Email: ");
|
||||
username.setFont(new Font("Times New Roman", Font.PLAIN, 20));
|
||||
username.setBounds(10, 106, 203, 39);
|
||||
panel_1.add(username);
|
||||
|
||||
JLabel editProfile = new JLabel("Edit profile");
|
||||
editProfile.setForeground(Color.BLUE);
|
||||
editProfile.setFont(new Font("Times New Roman", Font.PLAIN, 22));
|
||||
editProfile.setBounds(10, 189, 165, 39);
|
||||
panel_1.add(editProfile);
|
||||
|
||||
JPanel panel_2 = new JPanel();
|
||||
panel_2.setBorder(new LineBorder(new Color(0, 0, 0), 2));
|
||||
panel_2.setBackground(new Color(230, 230, 230));
|
||||
panel_2.setBounds(255, 11, 624, 86);
|
||||
contentPane.add(panel_2);
|
||||
panel_2.setLayout(null);
|
||||
|
||||
JLabel writeEmail = new JLabel("New Email");
|
||||
writeEmail.setForeground(Color.BLUE);
|
||||
writeEmail.setFont(new Font("Times New Roman", Font.PLAIN, 22));
|
||||
writeEmail.setBounds(10, 11, 121, 64);
|
||||
panel_2.add(writeEmail);
|
||||
|
||||
// ==== NEU: Inbox Panel mit JTable ====
|
||||
JPanel panel_3 = new JPanel();
|
||||
panel_3.setBorder(new LineBorder(new Color(0, 0, 0)));
|
||||
panel_3.setBounds(255, 112, 624, 540);
|
||||
panel_3.setLayout(new BorderLayout());
|
||||
contentPane.add(panel_3);
|
||||
|
||||
// NUR Spaltennamen, KEINE Daten
|
||||
String[] columnNames = { "From", "Subject", "Date" };
|
||||
inboxTableModel = new DefaultTableModel(columnNames, 0); // 0 bedeutet: keine Start-Daten
|
||||
|
||||
inboxTable = new JTable(inboxTableModel);
|
||||
inboxTable.setFont(new Font("Times New Roman", Font.PLAIN, 16));
|
||||
inboxTable.setRowHeight(24);
|
||||
inboxTable.setDefaultEditor(Object.class, null); // nicht editierbar
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane(inboxTable);
|
||||
panel_3.add(scrollPane, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
public void showWindow() {
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
public void closeWindow() {
|
||||
this.dispose();
|
||||
}
|
||||
|
||||
public void showError(String error) {
|
||||
JOptionPane.showMessageDialog(this, "Error", error, JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,176 @@
|
|||
package gui;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.border.LineBorder;
|
||||
|
||||
import domain.EasyMail;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class RegisterWindow extends JFrame {
|
||||
|
||||
private EasyMail fassade;
|
||||
private JTextField firstNameField, lastNameField, usernameField;
|
||||
private JPasswordField passwordField, confirmPasswordField;
|
||||
private JComboBox<Integer> dayComboBox, yearComboBox;
|
||||
private JComboBox<String> monthComboBox;
|
||||
private EasyMailWindow easyMail;
|
||||
|
||||
public RegisterWindow() {
|
||||
this.fassade = new EasyMail();
|
||||
|
||||
setTitle("RegisterWindow - EasyMail");
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 754, 893);
|
||||
setLocationRelativeTo(null);
|
||||
|
||||
JPanel contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
contentPane.setLayout(null);
|
||||
|
||||
setContentPane(contentPane);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBackground(new Color(230, 230, 230));
|
||||
panel.setBorder(new LineBorder(new Color(0, 0, 0), 2));
|
||||
panel.setBounds(81, 80, 573, 709);
|
||||
panel.setLayout(null);
|
||||
contentPane.add(panel);
|
||||
|
||||
JLabel titleLabel = new JLabel("RegisterWindow - EasyMail");
|
||||
titleLabel.setFont(new Font("Times New Roman", Font.BOLD, 30));
|
||||
titleLabel.setBounds(85, 11, 387, 53);
|
||||
panel.add(titleLabel);
|
||||
|
||||
// First Name
|
||||
panel.add(createLabel("First Name:", 10, 87));
|
||||
firstNameField = createTextField(284, 96);
|
||||
panel.add(firstNameField);
|
||||
|
||||
// Last Name
|
||||
panel.add(createLabel("Last Name:", 10, 150));
|
||||
lastNameField = createTextField(284, 150);
|
||||
panel.add(lastNameField);
|
||||
|
||||
// Birthdate
|
||||
panel.add(createLabel("Birthdate:", 10, 229));
|
||||
|
||||
Integer[] days = IntStream.rangeClosed(1, 31).boxed().toArray(Integer[]::new);
|
||||
dayComboBox = new JComboBox<>(days);
|
||||
dayComboBox.setFont(new Font("Times New Roman", Font.PLAIN, 20));
|
||||
dayComboBox.setBounds(284, 229, 50, 29);
|
||||
panel.add(dayComboBox);
|
||||
|
||||
String[] months = {
|
||||
"Januar", "Februar", "März", "April", "Mai", "Juni",
|
||||
"Juli", "August", "September", "Oktober", "November", "Dezember"
|
||||
};
|
||||
monthComboBox = new JComboBox<>(months);
|
||||
monthComboBox.setFont(new Font("Times New Roman", Font.PLAIN, 20));
|
||||
monthComboBox.setBounds(344, 229, 110, 29);
|
||||
panel.add(monthComboBox);
|
||||
|
||||
Integer[] years = IntStream.rangeClosed(1900, java.time.LocalDate.now().getYear())
|
||||
.boxed().toArray(Integer[]::new);
|
||||
yearComboBox = new JComboBox<>(years);
|
||||
yearComboBox.setFont(new Font("Times New Roman", Font.PLAIN, 20));
|
||||
yearComboBox.setBounds(464, 229, 80, 29);
|
||||
yearComboBox.setSelectedItem(2000); // default year
|
||||
panel.add(yearComboBox);
|
||||
|
||||
// Username
|
||||
panel.add(createLabel("Username:", 10, 317));
|
||||
usernameField = createTextField(284, 323);
|
||||
panel.add(usernameField);
|
||||
|
||||
// Password
|
||||
panel.add(createLabel("Password:", 10, 405));
|
||||
passwordField = createPasswordField(284, 411);
|
||||
panel.add(passwordField);
|
||||
|
||||
// Confirm Password
|
||||
panel.add(createLabel("Confirm Password:", 10, 485));
|
||||
confirmPasswordField = createPasswordField(284, 491);
|
||||
panel.add(confirmPasswordField);
|
||||
|
||||
// RegisterWindow Button
|
||||
JButton registerButton = new JButton("Register");
|
||||
registerButton.setFont(new Font("Tahoma", Font.PLAIN, 18));
|
||||
registerButton.setBounds(10, 565, 159, 43);
|
||||
panel.add(registerButton);
|
||||
registerButton.addActionListener(e -> handleRegister());
|
||||
|
||||
// Link to Login
|
||||
JLabel loginLabel = new JLabel("Login");
|
||||
loginLabel.setForeground(new Color(0, 0, 160));
|
||||
loginLabel.setFont(new Font("Times New Roman", Font.BOLD, 25));
|
||||
loginLabel.setBounds(406, 566, 117, 29);
|
||||
panel.add(loginLabel);
|
||||
showWindow();
|
||||
}
|
||||
|
||||
private JLabel createLabel(String text, int x, int y) {
|
||||
JLabel label = new JLabel(text);
|
||||
label.setFont(new Font("Times New Roman", Font.PLAIN, 25));
|
||||
label.setBounds(x, y, 200, 30);
|
||||
return label;
|
||||
}
|
||||
|
||||
private JTextField createTextField(int x, int y) {
|
||||
JTextField textField = new JTextField();
|
||||
textField.setFont(new Font("Times New Roman", Font.PLAIN, 20));
|
||||
textField.setBounds(x, y, 239, 29);
|
||||
return textField;
|
||||
}
|
||||
|
||||
private JPasswordField createPasswordField(int x, int y) {
|
||||
JPasswordField passwordField = new JPasswordField();
|
||||
passwordField.setFont(new Font("Times New Roman", Font.PLAIN, 20));
|
||||
passwordField.setBounds(x, y, 239, 29);
|
||||
return passwordField;
|
||||
}
|
||||
|
||||
private void handleRegister() {
|
||||
try {
|
||||
String firstName = firstNameField.getText();
|
||||
String lastName = lastNameField.getText();
|
||||
String userName = usernameField.getText();
|
||||
char[] password = passwordField.getPassword();
|
||||
char[] passwordConfirmation = confirmPasswordField.getPassword();
|
||||
int day = (int) dayComboBox.getSelectedItem();
|
||||
int year = (int) yearComboBox.getSelectedItem();
|
||||
String month = (String) monthComboBox.getSelectedItem();
|
||||
fassade.userRegister(firstName, lastName, userName, year, day, month, password, passwordConfirmation);
|
||||
Arrays.fill(password, ' ');
|
||||
Arrays.fill(passwordConfirmation, ' ');
|
||||
restInputs();
|
||||
this.closeWindow();
|
||||
this.easyMail = new EasyMailWindow();
|
||||
this.easyMail.showWindow();
|
||||
} catch (Exception e) {
|
||||
showError(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void showWindow() {
|
||||
this.setVisible(true);
|
||||
}
|
||||
public void closeWindow() {
|
||||
this.dispose();
|
||||
}
|
||||
public void showError(String error) {
|
||||
JOptionPane.showMessageDialog(this, error, "Error" , JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
public void restInputs() {
|
||||
this.firstNameField.setText("");
|
||||
this.lastNameField.setText("");
|
||||
this.usernameField.setText("");
|
||||
this.passwordField.setText("");
|
||||
this.passwordField.setText("");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package main;
|
||||
|
||||
import gui.RegisterWindow;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new RegisterWindow();
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue