package se;
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
import java.io.OptionalDataException;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Vector;
public class StudentGUI extends Frame implements ActionListener, WindowListener {
private Button neu;
private Button weiter;
private Button zurueck;
private Label labMatNr;
private Label labVor;
private Label labNach;
private TextField txtMatNr;
private TextField txtVor;
private TextField txtNach;
private int index = 1;
public StudentGUI(String s) {
super(s);
}
public void init() throws HeadlessException, OptionalDataException,
ClassNotFoundException, IOException {
StudentenVerwaltung recoveredClass = StudentenVerwaltung
.fromFile("studenten.dat");
Student student = (Student) recoveredClass.list.get(index);
setLayout(new FlowLayout());
labMatNr = new Label("Mat.Nr.: " + student.matrikelnummer);
txtMatNr = new TextField(6);
labVor = new Label("Vorname: " + student.vorname);
txtVor = new TextField(20);
labNach = new Label("Nachname: " + student.nachname);
txtNach = new TextField(20);
neu = new Button("Neu");
neu.addActionListener(this);
weiter = new Button("Weiter");
weiter.addActionListener(this);
zurueck = new Button("Zurück");
zurueck.addActionListener(this);
add(labMatNr);
add(txtMatNr);
add(labVor);
add(txtVor);
add(labNach);
add(txtNach);
add(neu);
add(zurueck);
add(weiter);
addWindowListener(this);
setSize(200, 300); // or: pack();
setVisible(true);
}
public static void main(String[] args) throws HeadlessException,
OptionalDataException, ClassNotFoundException, IOException {
StudentGUI f = new StudentGUI("Test");
f.init();
}
public void actionPerformed(ActionEvent e) {
try {
StudentenVerwaltung recoveredClass = StudentenVerwaltung
.fromFile("studenten.dat");
if (e.getSource().equals(neu)) {
String neuMatNr = txtMatNr.getText();
String neuVor = txtVor.getText();
String neuNach = txtNach.getText();
recoveredClass
.addStudent(new Student(neuMatNr, neuVor, neuNach));
Student student = (Student) recoveredClass.list.lastElement();
System.out.println(student.matrikelnummer);
txtMatNr.setText("");
txtVor.setText("");
txtNach.setText("");
labMatNr = new Label("Mat.Nr.: " + student.matrikelnummer);
labMatNr = new Label("Mat.Nr.: " + student.matrikelnummer);
labVor = new Label("Vorname: " + student.vorname);
labNach = new Label("Nachname: " + student.nachname);
} else if (e.getSource().equals(zurueck)) {
//Student vorigerStudent = (Student) recoveredClass.list.get(0);
index--;
dispose();
init();
//labMatNr = new Label("Mat.Nr.: " + vorigerStudent.matrikelnummer);
//labVor = new Label("Vorname: " + vorigerStudent.vorname);
//labNach = new Label("Nachname: " + vorigerStudent.nachname);
//add(labMatNr);
//add(labVor);
//add(labNach);
}
} catch (OptionalDataException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
public void windowClosed(WindowEvent e) {
}
public void windowOpened(WindowEvent e) {
}
public void windowIconified(WindowEvent e) {
}
public void windowDeiconified(WindowEvent e) {
}
public void windowActivated(WindowEvent e) {
}
public void windowDeactivated(WindowEvent e) {
}