/**
* Erstellt die Benutzeroberflaeche mit den Steuerelementen.
*/
private void setGUI() {
this.getContentPane().setLayout(new GridBagLayout());
// Klassen lesen
klassenLesen();
// Schaltflaeche: Speichern
btnSpeichern = new JButton("Speichern");
btnSpeichern.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
noteSpeichern();
}
});
// Schaltflaeche: Abbrechen
btnAbbrechen = new JButton("Abbrechen");
btnAbbrechen.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
closeDialog();
}
});
// Schaltflaechen mit einheitlicher Groesse
btnSpeichern.setPreferredSize(btnAbbrechen.getPreferredSize());
// Hauptpanel des Editors fuer umlaufenden Rahmen
JPanel jPanelEditor = new JPanel(new GridBagLayout());
// JPanel fuer das linke und rechte JPanel
//JPanel panelEditor = new JPanel(new GridLayout(1, 2));
//panelEditor.setBackground(Color.CYAN);
// JPanel fuer den linken Bereich
//JPanel panelEditorLinks = new JPanel(new GridBagLayout());
//panelEditorLinks.setBackground(Color.BLUE);
// JPanel fuer den rechten Bereich
//JPanel panelEditorRechts = new JPanel(new GridBagLayout());
//panelEditorRechts.setBackground(Color.YELLOW);
// linkes und rechtes JPanel dem Editor-Panel hinzufuegen
//panelEditor.add(panelEditorLinks);
//panelEditor.add(panelEditorRechts);
jPanelEditor.add(new JLabel("Klasse: "),
new GridBagConstraints(0, 0, 1, 1, 0.10, 0.0,
GridBagConstraints.WEST,
GridBagConstraints.NONE,
new Insets(0, 0, 0, 0), 0, 0));
cboKlassen = new JComboBox<Klasse>(vecKlassenvektor);
cboKlassen.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
aktualisiereAuswahlElemente();
}
});
jPanelEditor.add(cboKlassen,
new GridBagConstraints(1, 0, 1, 1, 0.40, 0.0,
GridBagConstraints.WEST,
GridBagConstraints.HORIZONTAL,
new Insets(0, 0, 0, 0), 0, 0));
// Faecher der Klasse lesen
klassefaecherLesen();
// Schueler der Klasse lesen
klasseschuelerLesen();
jPanelEditor.add(new JLabel("Fach: "),
new GridBagConstraints(2, 0, 1, 1, 0.10, 0.0,
GridBagConstraints.WEST,
GridBagConstraints.NONE,
new Insets(0, 10, 0, 0), 0, 0));
cboFaecher = new JComboBox<Fach>(vecFachvektor);
cboFaecher.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
aktualisiereNotenElemente();
}
});
jPanelEditor.add(
cboFaecher,
new GridBagConstraints(3, 0, 1, 1, 0.40, 0.0,
GridBagConstraints.WEST,
GridBagConstraints.HORIZONTAL,
new Insets(0, 0, 0, 0), 0, 0));
lstSchueler = new JList<Schueler>(vecSchuelervektor);
lstSchueler.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
/*
lstSchueler.setPreferredSize( new Dimension(200, 150));
lstSchueler.setMinimumSize(new Dimension(200, 150));
*/
lstSchueler.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
aktualisiereNotenElemente();
}
});
// die Scrollbar der Schuelerliste
JScrollPane scrollerSchueler = new JScrollPane(lstSchueler);
// immer sichtbar
scrollerSchueler.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jPanelEditor.add(
new JLabel("Schülerliste: "),
new GridBagConstraints(0, 1, 2, 1, 0.50, 0.0,
GridBagConstraints.WEST,
GridBagConstraints.HORIZONTAL,
new Insets(5, 0, 0, 0), 0, 0));
jPanelEditor.add(
new JLabel(""),
new GridBagConstraints(2, 1, 2, 1, 0.50, 0.0,
GridBagConstraints.WEST,
GridBagConstraints.HORIZONTAL,
new Insets(5, 10, 0, 0), 0, 0));
jPanelEditor.add(
scrollerSchueler,
new GridBagConstraints(0, 2, 2, 6, 0.50, 1.0,
GridBagConstraints.WEST,
GridBagConstraints.BOTH,
new Insets(0, 0, 0, 0), 0, 0));
jPanelEditor.add(
new JLabel("Noten: "),
new GridBagConstraints(2, 2, 1, 1, 0.10, 0.0,
GridBagConstraints.WEST,
GridBagConstraints.NONE,
new Insets(0, 10, 0, 0), 0, 0));
txtNoten = new JTextArea("");
txtNoten.setEnabled(false);
txtNoten.setLineWrap(true);
txtNoten.setWrapStyleWord(true);
JScrollPane scrollerNoten = new JScrollPane(txtNoten);
// immer sichtbar
scrollerNoten.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
//scrollerNoten.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
jPanelEditor.add(
scrollerNoten,
new GridBagConstraints(3, 2, 1, 3, 0.40, 1.0,
GridBagConstraints.WEST,
GridBagConstraints.BOTH,
new Insets(0, 0, 0, 0), 0, 0));
jPanelEditor.add(
new JLabel("Durchschnitt: "),
new GridBagConstraints(2, 5, 1, 1, 0.10, 0.0,
GridBagConstraints.WEST,
GridBagConstraints.NONE,
new Insets(5, 10, 0, 0), 0, 0));
txtNotendurchschnitt = new JTextField("");
txtNotendurchschnitt.setEnabled(false);
txtNotendurchschnitt.setBorder(BorderFactory.createLineBorder(Color.GRAY));
jPanelEditor.add(
txtNotendurchschnitt,
new GridBagConstraints(3, 5, 1, 1, 0.40, 0.0,
GridBagConstraints.WEST,
GridBagConstraints.HORIZONTAL,
new Insets(5, 0, 0, 0), 0, 0));
// ActionListener fuer JRadioButtons
ActionListener al = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String strNote = e.getActionCommand();
try {
iNote = Integer.parseInt(strNote);
} catch (NumberFormatException e1) {
//e1.printStackTrace();
iNote = 0;
}
}
};
// JRadioButtons fuer Notenvergabe
// Note: 1
btnEins.setMnemonic(KeyEvent.VK_1);
btnEins.setActionCommand("1");
btnEins.setSelected(true);
btnEins.addActionListener(al);
// Note: 2
btnZwei.setMnemonic(KeyEvent.VK_2);
btnZwei.setActionCommand("2");
btnZwei.addActionListener(al);
// Note: 3
btnDrei.setMnemonic(KeyEvent.VK_3);
btnDrei.setActionCommand("3");
btnDrei.addActionListener(al);
// Note: 4
btnVier.setMnemonic(KeyEvent.VK_4);
btnVier.setActionCommand("4");
btnVier.addActionListener(al);
// Note: 5
btnFuenf.setMnemonic(KeyEvent.VK_5);
btnFuenf.setActionCommand("5");
btnFuenf.addActionListener(al);
// Note: 6
btnSechs.setMnemonic(KeyEvent.VK_6);
btnSechs.setActionCommand("6");
btnSechs.addActionListener(al);
// Radio Buttons gruppieren
notenGruppe.add(btnEins);
notenGruppe.add(btnZwei);
notenGruppe.add(btnDrei);
notenGruppe.add(btnVier);
notenGruppe.add(btnFuenf);
notenGruppe.add(btnSechs);
JPanel notenPanel = new JPanel(new GridLayout(0, 1));
notenPanel.add(btnEins);
notenPanel.add(btnZwei);
notenPanel.add(btnDrei);
notenPanel.add(btnVier);
notenPanel.add(btnFuenf);
notenPanel.add(btnSechs);
jPanelEditor.add(notenPanel,
new GridBagConstraints(3, 6, 1, 2, 0.40, 1.0,
GridBagConstraints.WEST,
GridBagConstraints.BOTH,
new Insets(5, 0, 0, 0), 0, 0));
// JPanel fuer Schaltflaechen im unteren Bereich des Dialogfensters
JPanel panelUnten = new JPanel(new FlowLayout());
//panelUnten.setBackground(Color.GREEN);
panelUnten.add(btnAbbrechen);
panelUnten.add(btnSpeichern);
// Editor-Panel dem Dialogfenster hinzufuegen
this.getContentPane().add(jPanelEditor,
new GridBagConstraints( 0, 0, 1, 1, 1.0, 1.0,
GridBagConstraints.WEST,
GridBagConstraints.BOTH,
new Insets( 5, 10, 5, 10), 0, 0));
// JPanel mit den Schaltfaechen dem Dialogfenster hinzufuegen
this.getContentPane().add(panelUnten,
new GridBagConstraints(0, 1, 4, 1, 1.0, 0.0,
GridBagConstraints.SOUTH,
GridBagConstraints.HORIZONTAL,
new Insets(0, 0, 0, 0), 0, 0));
} // setUI