forked from IF-LK-2020/mymail
login GUI + abmelde button funktioniert
This commit is contained in:
parent
c035137020
commit
bc2fa40bcd
|
@ -34,6 +34,7 @@ public class LoginGUI extends JDialog implements ActionListener {
|
|||
setBounds(100, 100, 251, 220);
|
||||
setLocationRelativeTo(null);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||
contentPanel.setLayout(null);
|
||||
|
@ -90,9 +91,8 @@ public class LoginGUI extends JDialog implements ActionListener {
|
|||
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");
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
26
MyMail.java
26
MyMail.java
|
@ -1,3 +1,4 @@
|
|||
import javax.swing.JOptionPane;
|
||||
|
||||
public class MyMail {
|
||||
|
||||
|
@ -27,20 +28,33 @@ public class MyMail {
|
|||
|
||||
private String lastError;
|
||||
|
||||
private LoginGUI loginGUI;
|
||||
private LoginGUI login;
|
||||
|
||||
/**
|
||||
* Verbindet zu einem lokalen POP3-Server.
|
||||
*/
|
||||
public MyMail() {
|
||||
loginGUI = new LoginGUI(this);
|
||||
login = new LoginGUI(this);
|
||||
}
|
||||
|
||||
public void start(String pIP, int pPort, String pUser, String pPassword) {
|
||||
|
||||
ip = pIP;
|
||||
port = pPort;
|
||||
user = pUser;
|
||||
password = pPassword;
|
||||
|
||||
if (!connectToServer()) {
|
||||
JOptionPane.showMessageDialog(null, lastError, "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
if (!login()) {
|
||||
JOptionPane.showMessageDialog(null, lastError, "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
con.send("QUIT");
|
||||
con.close();
|
||||
login.dispose();
|
||||
|
||||
// GUI erstellen und Status setzen.
|
||||
gui = new MyMailGUI(this);
|
||||
|
@ -108,14 +122,14 @@ public class MyMail {
|
|||
con.send("USER " + user);
|
||||
mes = con.receive();
|
||||
if (mes == null || mes.startsWith("-ERR")) {
|
||||
lastError = "Ungueltiger Benutzername!";
|
||||
lastError = "Ungültiger Benutzername!";
|
||||
return false;
|
||||
}
|
||||
// PASS Kommando senden und Antwort prüfen
|
||||
con.send("PASS " + password);
|
||||
mes = con.receive();
|
||||
if (mes == null || mes.startsWith("-ERR")) {
|
||||
lastError = "Ungueltiges Passwort!";
|
||||
lastError = "Ungültiges Passwort!";
|
||||
return false;
|
||||
}
|
||||
// Anmeldung war erfolgreich
|
||||
|
@ -326,4 +340,8 @@ public class MyMail {
|
|||
gui.removeMailFromList(pMail);
|
||||
}
|
||||
|
||||
public void switchUser() {
|
||||
login = new LoginGUI(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public class MyMailGUI extends JFrame implements ActionListener, ListSelectionLi
|
|||
|
||||
private JLabel jlStatusText;
|
||||
|
||||
private JButton jbReload, jbDelete, jbNew, jbReply, jbSettings;
|
||||
private JButton jbReload, jbDelete, jbNew, jbReply, jbSettings, jbSwitchUser;
|
||||
|
||||
private JTable jtMaillist;
|
||||
|
||||
|
@ -100,6 +100,9 @@ public class MyMailGUI extends JFrame implements ActionListener, ListSelectionLi
|
|||
app.getAllMails();
|
||||
} else if( e.getActionCommand().equals("delete") ) {
|
||||
app.deleteMail(mails.get(jtMaillist.getSelectedRow()));
|
||||
} else if (e.getActionCommand().equals("switchUser")) {
|
||||
app.switchUser();
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,6 +147,11 @@ public class MyMailGUI extends JFrame implements ActionListener, ListSelectionLi
|
|||
jbDelete.addActionListener(this);
|
||||
jbDelete.setIcon(loadImageIcon("email_delete.png"));
|
||||
jpSidebar.add(jbDelete);
|
||||
|
||||
jbSwitchUser = new JButton("Abmelden");
|
||||
jbSwitchUser.setActionCommand("switchUser");
|
||||
jbSwitchUser.addActionListener(this);
|
||||
jpSidebar.add(jbSwitchUser);
|
||||
|
||||
jbSettings = new JButton("Einstellungen");
|
||||
jbSettings.setActionCommand("settings");
|
||||
|
|
Loading…
Reference in New Issue