Hallo,
ich habe ein JFrame welches bei Klick des OK Buttons ein JDialog öffnen soll, jedoch wird nur der Leere JDialog angezeigt ohne die beeinhaltenden JLabels .
Das ist das JFrame
Der JDialog
und der ActionListener in der Main Klasse
Vielen Dank schon mal im Vorraus!
ich habe ein JFrame welches bei Klick des OK Buttons ein JDialog öffnen soll, jedoch wird nur der Leere JDialog angezeigt ohne die beeinhaltenden JLabels .
Das ist das JFrame
Java:
public class Eingabe extends JFrame {
JTextField vonField = new JTextField();
JTextField bisField = new JTextField();
JLabel vonLabel = new JLabel("VON");
JLabel bisLabel = new JLabel("BIS");
JButton ok = new JButton("OK");
JButton fromPickerButton = new JButton(new ImageIcon(getClass().getResource("/resources/calendar-month.png")));
JButton toPickerButton = new JButton(new ImageIcon(getClass().getResource("/resources/calendar-month.png")));
public Eingabe() {
//Hier wird der Eingabe Dialog erstellt
JPanel content = new JPanel();
//Panel wird erstellt und dem Dialog hinzugefügt
this.add(content);
//Panel werden Elemente hinzugefügt
content.setLayout(new TableLayout(new double[][]{{0.4, 0.4, 0.2}, {0.25, 0.25, 0.25,}}));
content.add(vonLabel, "0,0");
content.add(bisLabel, "0,1");
content.add(vonField, "1,0");
content.add(bisField, "1,1");
content.add(fromPickerButton, "2,0");
content.add(toPickerButton, "2,1");
//Bei Klick auf den von Kalender wird folgendes ausgeführt
fromPickerButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
try {
pickerJDialog pjd = new pickerJDialog(vonField, Eingabe.this.fromPickerButton, null, null);
pjd.setVisible(true);
} catch (RemoteException ex) {
Logger.getLogger(Eingabe.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
//Bei Klick auf den bis Kalender wird folgendes ausgeführt
toPickerButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
try {
pickerJDialog pjd = new pickerJDialog(bisField, Eingabe.this.toPickerButton, null, null);
pjd.setVisible(true);
} catch (RemoteException ex) {
Logger.getLogger(Eingabe.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
//Eigenschaften des Dialogs werden gesetzt
this.setSize(300, 150);
this.setResizable(false);
centerDialog();
content.add(ok, "1,2");
content.setVisible(true);
this.setTitle("Eingabe");
//Wenn das Fenster geschlossen wird schließt auch das Programm
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getRootPane().setDefaultButton(ok);
}
//Funktionen
//Gibt den von Datum zurück
public String returnvon() {
return vonField.getText();
}
//gibt das bis Datum zurück
public String returnbis() {
return bisField.getText();
}
//zentrier den Dialog auf dem Bildschirm
private void centerDialog() {
Dimension dim = getToolkit().getScreenSize();
Rectangle abounds = getBounds();
setLocation((dim.width - abounds.width) / 2,
(dim.height - abounds.height) / 2);
}
}
Java:
public class bitteWarten extends JDialog {
public bitteWarten() throws InterruptedException {
JPanel panel = new JPanel();
this.add(panel);
JLabel label = new JLabel("Bitte warten...");
panel.setLayout(new TableLayout(new double[][]{{TableLayout.FILL}, {TableLayout.FILL}}));
panel.add(label,"0,0");
this.pack();
centerDialog();
setVisible(true);
Thread.sleep(5000);
}
private void centerDialog() {
Dimension dim = getToolkit().getScreenSize();
Rectangle abounds = getBounds();
setLocation((dim.width - abounds.width) / 2,
(dim.height - abounds.height) / 2);
}
}
und der ActionListener in der Main Klasse
Java:
final Eingabe ei = new Eingabe();
ei.setVisible(true);
//Folgender Code wird ausgeführt wenn der OK Button gedrückt wird
ei.ok.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
try {
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
ex.ExcelExp(2, con, sdf.parse(ei.returnvon()), sdf.parse(ei.returnbis()));
ex.ExcelExp(3, con, sdf.parse(ei.returnvon()), sdf.parse(ei.returnbis()));
con.close();
mail mail= new mail();
//mail.sendMail(to, to2, to3, to4, from, host, filename, filename2, msgText1, subject);
bitteWarten bwa = new bitteWarten();
//openDat("Montage");
//openDat("Produktion");
ei.setVisible(false);
} catch (Exception e) {
e.printStackTrace();
}
}
});
Vielen Dank schon mal im Vorraus!