import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.Vector;
import java.util.regex.*;
public class EingabeFI2 extends Frame {
// Anfang Variablen
private Label lblTitel = new Label();
private Label lblName = new Label();
private TextField txtName = new TextField();
private Label lblVorname = new Label();
private TextField txtVorname = new TextField();
private Label lblStrasse = new Label();
private TextField txtStrasse = new TextField();
private Label lblOrt = new Label();
private TextField txtPlz = new TextField();
private TextField txtOrt = new TextField();
private CheckboxGroup geschlecht = new CheckboxGroup();
private Checkbox rbM = new Checkbox("männlich", geschlecht, true);
private Checkbox rbW = new Checkbox("weiblich", geschlecht, false);
private Label lblKenntnisse = new Label();
private Checkbox ckProg = new Checkbox();
private Checkbox ckBetr = new Checkbox();
private Checkbox ckNet = new Checkbox();
private Label lblWeitere = new Label();
private TextArea textArea = new TextArea("", 1, 1,
TextArea.SCROLLBARS_VERTICAL_ONLY);
private Button btnUebernehmen = new Button();
private Button btnLoeschen = new Button();
private Speichern save = new Speichern();
private DlgNochmal dlg = new DlgNochmal(this, "nochmal?", true);
private Button btnLetzter= new Button();
private Button btnVorwaerts = new Button();
private Button btnZurueck = new Button();
private Button btnErster = new Button();
private Vector<SplitDatenhalter> datenhalter = new Vector<SplitDatenhalter>();
// Ende Variablen
public EingabeFI2(String title) {
// Frame-Initialisierung
super(title);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
System.exit(0);
}
});
int frameWidth = 557;
int frameHeight = 300;
setSize(frameWidth, frameHeight);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int x = (d.width - getSize().width) / 2;
int y = (d.height - getSize().height) / 2;
setLocation(x, y);
Panel cp = new Panel(null);
add(cp);
cp.setBackground(Color.YELLOW);
// Anfang Komponenten
lblTitel.setBounds(16, 8, 400, 20);
lblTitel.setText("Eingabeformular");
lblTitel.setFont(new Font("MS Sans Serif", Font.BOLD, 15));
cp.add(lblTitel);
lblName.setBounds(16, 40, 37, 16);
lblName.setText("Name");
lblName.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
cp.add(lblName);
txtName.setBounds(80, 40, 193, 24);
txtName.setText("");
cp.add(txtName);
lblVorname.setBounds(16, 72, 55, 16);
lblVorname.setText("Vorname");
lblVorname.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
cp.add(lblVorname);
txtVorname.setBounds(80, 72, 193, 24);
txtVorname.setText("");
cp.add(txtVorname);
lblStrasse.setBounds(16, 104, 46, 16);
lblStrasse.setText("Strasse");
lblStrasse.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
cp.add(lblStrasse);
txtStrasse.setBounds(80, 104, 193, 24);
txtStrasse.setText("");
cp.add(txtStrasse);
lblOrt.setBounds(16, 136, 45, 16);
lblOrt.setText("PLZ/Ort");
lblOrt.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
cp.add(lblOrt);
txtPlz.setBounds(80, 136, 57, 24);
txtPlz.setText("");
cp.add(txtPlz);
txtOrt.setBounds(144, 136, 129, 24);
txtOrt.setText("");
cp.add(txtOrt);
rbM.setBounds(80, 176, 89, 25);
cp.add(rbM);
rbW.setBounds(176, 176, 97, 25);
cp.add(rbW);
lblKenntnisse.setBounds(288, 40, 104, 16);
lblKenntnisse.setText("Kenntnisse:");
lblKenntnisse.setFont(new Font("MS Sans Serif", Font.BOLD, 13));
cp.add(lblKenntnisse);
ckProg.setBounds(288, 72, 121, 25);
ckProg.setLabel("Programmieren");
cp.add(ckProg);
ckBetr.setBounds(288, 104, 121, 25);
ckBetr.setLabel("Betriebssysteme");
cp.add(ckBetr);
ckNet.setBounds(288, 136, 129, 25);
ckNet.setLabel("Netzwerke");
cp.add(ckNet);
lblWeitere.setBounds(288, 168, 46, 16);
lblWeitere.setText("weitere:");
lblWeitere.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
cp.add(lblWeitere);
textArea.setBounds(288, 192, 241, 65);
textArea.setText("\n");
cp.add(textArea);
btnUebernehmen.setBounds(24, 232, 121, 25);
btnUebernehmen.setLabel("Übernehmen");
btnUebernehmen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
btnUebernehmen_ActionPerformed(evt);
}
});
cp.add(btnUebernehmen);
btnLoeschen.setBounds(160, 232, 113, 25);
btnLoeschen.setLabel("Löschen");
btnLoeschen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
btnLoeschen_ActionPerformed(evt);
}
});
cp.add(btnLoeschen);
btnErster.setBounds(24, 200, 27, 25);
btnErster.setLabel("<");
btnErster.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
btnErster_ActionPerformed(evt);
}
});
cp.add(btnErster);
btnLetzter.setBounds(152, 200, 27, 25);
btnLetzter.setLabel(">");
btnLetzter.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
btnLetzter_ActionPerformed(evt);
}
});
cp.add(btnLetzter);
btnZurueck.setBounds(64, 200, 27, 25);
btnZurueck.setLabel("<<");
btnZurueck.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
btnZurueck_ActionPerformed(evt);
}
});
cp.add(btnZurueck);
btnVorwaerts.setBounds(112, 200, 27, 25);
btnVorwaerts.setLabel(">>");
btnVorwaerts.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
btnVorwaerts_ActionPerformed(evt);
}
});
cp.add(btnVorwaerts);
// Ende Komponenten
setResizable(false);
setVisible(true);
try{
/** Einlesen der Datei **/
File f = new File("meineDatei.csv");
BufferedReader bf = new BufferedReader(new FileReader(f));
String line = "";
while((line = bf.readLine())!=null){
String[] splittedLine = line.split(",");
datenhalter.add(new datenhalter.add(new
SplitDatenhalter(splittedLine[0],splittedLine[1],splittedLine[2],Integer.parseInt(splittedLine[3]),splittedLine[4
],splittedLine[5],splittedLine[6],splittedLine[7],splittedLine[8],splittedLine[9]));
}
}catch(Exception e){
e.printStackTrace();
}
}
// Daten:
String name = this.txtName.getText();
String vorname = this.txtVorname.getText();
String plz = this.txtPlz.getText();
String ort = this.txtOrt.getText();
String strasse = this.txtStrasse.getText();
String geschl = "";
String prog = "";
String betr = "";
String net = "";
String weitere = "";
// Anfang Ereignisprozeduren
public String getSelectedRadioButton(CheckboxGroup cg) {
return cg.getSelectedCheckbox().getLabel();
}
public void btnUebernehmen_ActionPerformed(ActionEvent evt) {
// Daten ermitteln:
name = this.txtName.getText();
vorname = this.txtVorname.getText();
plz = this.txtPlz.getText();
ort = this.txtOrt.getText();
strasse = this.txtStrasse.getText();
geschl = getSelectedRadioButton(this.geschlecht);
if (this.ckProg.getState()) {
this.prog = "Programmiertechnik";
}
if (this.ckBetr.getState()) {
this.betr = "Betriebssysteme";
}
if (this.ckNet.getState()) {
this.net = "Netzwerktechnik";
}
weitere = this.textArea.getText();
// Daten prüfen:
// 1. PLZ:
Pattern p = Pattern.compile("^[0-9][1-9][0-9]{3}$");
Matcher m = p.matcher(this.plz);
boolean plzOk = m.matches();
if (!plzOk) {
this.txtPlz.setBackground(Color.RED);
this.txtPlz.setText("");
this.txtPlz.requestFocus();
} else {
this.txtPlz.setBackground(Color.WHITE);
}
// 2. sonstige Daten:
boolean datenOk = (!name.equals("")) && (!vorname.equals("")) &&
(!plz.equals("")) && (!ort.equals("")) &&
(!strasse.equals(""));
if (!datenOk) {
this.lblTitel.setForeground(Color.RED);
this.lblTitel.setText("Bitte alle Felder ausfüllen");
} else {
this.lblTitel.setForeground(Color.BLACK);
this.lblTitel.setText("Eingabeformular");
}
// Daten speichern:
try {
this.speichern();
}catch(IOException e) {
System.out.println("Fehler in speichern()");
}
// Dialog, weiteren Datensatz eingeben:
if((datenOk) && (plzOk)) {
this.nochmal();
}
}
public void btnLoeschen_ActionPerformed(ActionEvent evt) {
this.loeschen();
}
public void btnErster_ActionPerformed(ActionEvent evt) {
}
public void btnLetzter_ActionPerformed(ActionEvent evt) {
}
public void btnVorwaerts_ActionPerformed(ActionEvent evt) {
}
public void btnZurueck_ActionPerformed(ActionEvent evt) {
}
// Ende Ereignisprozeduren
// eigene Methoden:
private void speichern() throws IOException {
this.save.makeDir("csv");
this.save.makeFile("Daten.csv");
this.save.schreibeCsvZeile(this.name, this.vorname, this.plz, this.ort,
this.strasse, this.geschl, this.prog, this.betr,
this.net, this.weitere, ';');
}
private void loeschen() {
this.txtName.setText("");
this.txtVorname.setText("");
this.txtPlz.setText("");
this.txtOrt.setText("");
this.txtStrasse.setText("");
this.rbM.setState(true);
this.rbW.setState(false);
this.ckProg.setState(false);
this.ckBetr.setState(false);
this.ckNet.setState(false);
this.textArea.setText("");
// Fehlermeldungen löschen:
this.lblTitel.setForeground(Color.BLACK);
this.lblTitel.setText("Eingabeformular");
this.txtPlz.setBackground(Color.WHITE);
}
private void nochmal() {
this.dlg.setVisible(true);
// Antwort auswerten:
if(this.dlg.getAntwort()) this.loeschen();
System.exit(0);
}
/* private void readFile()
{
try{
BufferedReader reader = new BufferedReader(new FileReader("C:/Dokumente und Einstellungen/tgrahl/Eigene
Dateien/workspaces/Test/Project/csv/Daten.csv"));
String strLine;
while ( (strLine = reader.readLine()) != null )
{
String[] items = strLine.split(";");
System.out.println(items[5]);
}
}
catch(FileNotFoundException e) {}
catch(IOException e) {
}
}
*/
/** aktuelle Seite **/
private int current_page = 0;
private void pageForward(){
if(datenhalter.size()>=(current_page+1)){
current_page++;
txtName.setText(datenhalter.get(current_page).getName());
}
}
private void pageBackward(){
if((current_page-1)>0){
current_page--;
txtName.setText(datenhalter.get(current_page).getName());
}
}
public static void main(String[] args) {
new EingabeFI2("EingabeFI2");
}
}