package com.verwaltungsgui;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.GroupLayout.Alignment;
public class DialogMitarbeiterEifuegen extends JDialog implements ActionListener{
/**
*
*/
private static final long serialVersionUID = 1L;
MitarbeiterGuiModel mitGuiModel;
MitarbeiterGui mitGui;
private JLabel nachname, vorname, wohnort, alter, verheiratet;
private JCheckBox verheiratetBox;
public JTextField t_nachname, t_vorname, t_wohnort, t_alter;
private Container container;
private JButton buttonOK, buttonAbbrechen;
Mitarbeiter mitarbeiter;
public DialogMitarbeiterEifuegen()
{
init();
}
private void init() {
container = this.getContentPane();
JPanel panel = new JPanel();
GroupLayout layout = new GroupLayout(panel);
//JPanel panelUnten = new JPanel();
panel.setLayout(layout);
this.pack();
nachname=new JLabel("Nachname:");
vorname=new JLabel("Vorname:");
wohnort=new JLabel("Wohnort:");
alter=new JLabel("Alter:");
verheiratet=new JLabel("Verheiratet:");
t_nachname = new JTextField();
t_vorname = new JTextField();
t_wohnort = new JTextField();
t_alter = new JTextField();
verheiratetBox=new JCheckBox();
panel.add(nachname);
panel.add(t_nachname);
panel.add(vorname);
panel.add(t_vorname);
panel.add(wohnort);
panel.add(t_wohnort);
panel.add(alter);
panel.add(t_alter);
panel.add(verheiratet);
panel.add(verheiratetBox);
buttonOK= new JButton("Einfügen");
buttonAbbrechen = new JButton("Abbrechen");
/**
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
/***********************************************************************
* Turn on automatically adding gaps between components
**********************************************************************/
layout.setAutoCreateGaps(true);
/**
* Turn on automatically creating gaps between components that touch the
* edge of the container and the container.
*/
layout.setAutoCreateContainerGaps(true);
/**
* Create a sequential group for the horizontal axis.
*/
GroupLayout.SequentialGroup hGroup = layout.createSequentialGroup();
/**
* The sequential group in turn contains two parallel groups. One
* parallel group contains the labels, the other the text fields.
* Putting the labels in a parallel group along the horizontal axis
* positions them at the same x location. Variable indentation is used
* to reinforce the level of grouping.
*/
hGroup.addGroup(layout.createParallelGroup().addComponent(nachname)
.addComponent(vorname).addComponent(wohnort).addComponent(
alter).addComponent(verheiratet).addComponent(buttonOK));
hGroup.addGroup(layout.createParallelGroup().addComponent(t_nachname)
.addComponent(t_vorname).addComponent(t_wohnort)
.addComponent(t_alter).addComponent(verheiratetBox).addComponent(buttonAbbrechen));
layout.setHorizontalGroup(hGroup);
/***********************************************************************
* Create a sequential group for the vertical axis.
**********************************************************************/
GroupLayout.SequentialGroup vGroup = layout.createSequentialGroup();
/***********************************************************************
* The sequential group contains two parallel groups that align the
* contents along the baseline. The first parallel group contains the
* first label and text field, and the second parallel group contains
* the second label and text field. By using a sequential group the
* labels and text fields are positioned vertically after one another.
**********************************************************************/
vGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE)
.addComponent(nachname).addComponent(t_nachname));
vGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE)
.addComponent(vorname).addComponent(t_vorname));
vGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE)
.addComponent(wohnort).addComponent(t_wohnort));
vGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE)
.addComponent(alter).addComponent(t_alter));
vGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE)
.addComponent(verheiratet).addComponent(verheiratetBox));
vGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE)
.addComponent(buttonOK).addComponent(buttonAbbrechen));
layout.setVerticalGroup(vGroup);
/**
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
container.add(panel);
this.pack();
this.setLocationRelativeTo(null);
this.setModal(true);
buttonOK.addActionListener(this);
buttonAbbrechen.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent arg0) {
if(arg0.getSource() == buttonOK)
{
ArrayList<Mitarbeiter> mitArrayList = new ArrayList<Mitarbeiter>();
ArrayList<Mitarbeiter> mitArrayList1 = new ArrayList<Mitarbeiter>();
String name = t_nachname.getText();
String vorname = t_vorname.getText();
String wohnort = t_wohnort.getText();
int alter=0;
try {
alter = Integer.parseInt(t_alter.getText());
} catch (Exception e) {
JOptionPane.showMessageDialog(buttonOK, "Das Alter ist falsch");
}
boolean verheiratet;
if(verheiratetBox.isSelected())
verheiratet = true;
else verheiratet = false;
mitarbeiter = new Mitarbeiter(name, vorname, wohnort, alter, verheiratet);
mitArrayList.add(mitarbeiter);
System.out.println("********: "+mitArrayList.size());
mitGui = new MitarbeiterGui(mitarbeiter);
mitGui.datenEinfuegen(mitArrayList);
System.out.println("Hallo "+mitarbeiter.getName()+ " Verheiratet: "+mitarbeiter.isVerheiratet()+ mitarbeiter.getAlter());
setVisible(false);
}
else this.setVisible(false);
}
}