diff --git a/LoginGUI.java b/LoginGUI.java new file mode 100644 index 0000000..78cf915 --- /dev/null +++ b/LoginGUI.java @@ -0,0 +1,98 @@ +import java.awt.BorderLayout; +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JPanel; +import javax.swing.border.EmptyBorder; +import javax.swing.JTextField; +import javax.swing.BoxLayout; +import javax.swing.JLabel; +import javax.swing.JPasswordField; + +public class LoginGUI extends JDialog implements ActionListener { + + private MyMail app; + + private final JPanel contentPanel = new JPanel(); + private JTextField address; + private JTextField user; + private JPasswordField pw; + + /** + * Launch the application. + */ + + /** + * Create the dialog. + */ + public LoginGUI(MyMail app) { + this.app = app; + setTitle("Login"); + setBounds(100, 100, 251, 220); + setLocationRelativeTo(null); + getContentPane().setLayout(new BorderLayout()); + contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); + getContentPane().add(contentPanel, BorderLayout.CENTER); + contentPanel.setLayout(null); + { + address = new JTextField(); + address.setBounds(10, 26, 215, 20); + contentPanel.add(address); + address.setColumns(10); + } + { + user = new JTextField(); + user.setBounds(10, 72, 215, 20); + contentPanel.add(user); + user.setColumns(10); + } + + JLabel lblNewLabel = new JLabel("Server Address"); + lblNewLabel.setBounds(10, 11, 414, 14); + contentPanel.add(lblNewLabel); + + JLabel lblNewLabel_1 = new JLabel("Username"); + lblNewLabel_1.setBounds(10, 57, 414, 14); + contentPanel.add(lblNewLabel_1); + + JLabel lblNewLabel_2 = new JLabel("Password"); + lblNewLabel_2.setBounds(10, 103, 414, 14); + contentPanel.add(lblNewLabel_2); + + pw = new JPasswordField(); + pw.setBounds(10, 118, 215, 20); + contentPanel.add(pw); + { + JPanel buttonPane = new JPanel(); + buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); + getContentPane().add(buttonPane, BorderLayout.SOUTH); + { + JButton okButton = new JButton("OK"); + okButton.setActionCommand("OK"); + okButton.addActionListener(this); + buttonPane.add(okButton); + getRootPane().setDefaultButton(okButton); + } + { + JButton cancelButton = new JButton("Cancel"); + cancelButton.setActionCommand("Cancel"); + cancelButton.addActionListener(this); + buttonPane.add(cancelButton); + } + } + setVisible(true); + } + + @Override + public void actionPerformed(ActionEvent e) { + if (e.getActionCommand().equals("OK")) { + app.start(address.getText(), 110, user.getText(), new String(pw.getPassword())); + dispose(); + } else if (e.getActionCommand().equals("Cancel")) { + System.out.println("Cancel"); + } + } +} diff --git a/MyMail.java b/MyMail.java index e2fc86e..455f3b8 100644 --- a/MyMail.java +++ b/MyMail.java @@ -1,13 +1,13 @@ public class MyMail { - public static final String POP3_SERVER = "pop3.neugebauer.cc"; - - public static final int POP3_PORT = 110; - - public static final String POP3_USER = "informatik@neugebauer.cc"; - - public static final String POP3_PASS = "ifq2_user1"; +// public static final String POP3_SERVER = "pop3.neugebauer.cc"; +// +// public static final int POP3_PORT = 110; +// +// public static final String POP3_USER = "informatik@neugebauer.cc"; +// +// public static final String POP3_PASS = "ifq2_user1"; public static void main(String[] args) { new MyMail(); @@ -26,19 +26,17 @@ public class MyMail { private String password; private String lastError; + + private LoginGUI loginGUI; /** * Verbindet zu einem lokalen POP3-Server. */ public MyMail() { - this(POP3_SERVER, POP3_PORT, POP3_USER, POP3_PASS); + loginGUI = new LoginGUI(this); } - public MyMail(String pIP, String pUser, String pPassword) { - this(pIP, 110, pUser, pPassword); - } - - public MyMail(String pIP, int pPort, String pUser, String pPassword) { + public void start(String pIP, int pPort, String pUser, String pPassword) { ip = pIP; port = pPort; user = pUser;