RmiClient  1.0
 Alle Klassen Namensbereiche Dateien Funktionen Variablen
LoginFrame.java
gehe zur Dokumentation dieser Datei
1 package view;
2 
3 import java.awt.BorderLayout;
4 import java.awt.Container;
5 import java.rmi.RemoteException;
6 
7 import javax.swing.BoxLayout;
8 import javax.swing.JComboBox;
9 import javax.swing.JFrame;
10 import javax.swing.JLabel;
11 import javax.swing.JOptionPane;
12 import javax.swing.JPanel;
13 
14 import main.UserRole;
15 
16 import controller.ClientInterfaceImpl;
17 import controller.Controller;
18 
25 @SuppressWarnings("serial")
26 public class LoginFrame extends AbstractFrame {
27  private JComboBox selectionComboBox = null;
28 
32  public LoginFrame(final Controller controller) throws RemoteException {
33  super(controller, "Login-Fenster");
34 
39  JPanel selectionPanel = new JPanel();
40  selectionPanel
41  .setLayout(new BoxLayout(selectionPanel, BoxLayout.Y_AXIS));
42  JLabel selectionLabel = new JLabel(
43  "Mit welcher Rolle möchten Sie sich anmelden?");
44  selectionComboBox = new JComboBox();
45  for (Object sta : UserRole.values()) {
46  selectionComboBox.addItem(sta.toString());
47  }
48 
49  selectionPanel.add(selectionLabel);
50  selectionPanel.add(selectionComboBox);
51 
55  if (JOptionPane.showConfirmDialog(null, selectionPanel,
56  "Rollenauswahl", JOptionPane.OK_CANCEL_OPTION,
57  JOptionPane.PLAIN_MESSAGE) == 0) {
58 
59  if (selectionComboBox.getSelectedItem().toString()
60  .equals(UserRole.Student.toString())) {
61  login(UserRole.Student);
62  } else {
63  login(UserRole.Dozent);
64  }
65  } else {
66  System.exit(0);
67  }
68  }
69 
76  private void login(UserRole role) throws RemoteException {
83 
87  AbstractFrame viewMF = null;
88 
93  viewMF = controller.getFrame(MainFrame.class);
94 
100  if (viewMF == null) {
101  viewMF = new MainFrame(controller, role);
102 
106  controller.addObserver(viewMF);
107 
111  controller.addFrame(viewMF);
112  }
113 
114  viewMF.setSize(800, 300);
115  // viewMF.pack();
116  // positionieren des Fensters: mittig
117  viewMF.setLocationRelativeTo(null);
118  viewMF.setVisible(true);
119  }
120 }