Hallo miteinander...
Habe folgendes Problem. In meinem Frame kann ich per MenueItem ein JDialog erstellen.
In diesem JDialog habe ich ein Formular zur Eingabe von Infos in die Datenbank.
Da ist auch ein Exit Button... Irgendwie schaffe ich es nicht, den Dialog zu schliessen um zu meinem MainFrame zurückzukehren...
Alle anderen Funktionen habe ich erstmal raus genommen und nur den ActionListener für den Exit Button drin gelassen.
Erst mal mein Code:
Vielen Dank im Voraus
Habe folgendes Problem. In meinem Frame kann ich per MenueItem ein JDialog erstellen.
In diesem JDialog habe ich ein Formular zur Eingabe von Infos in die Datenbank.
Da ist auch ein Exit Button... Irgendwie schaffe ich es nicht, den Dialog zu schliessen um zu meinem MainFrame zurückzukehren...
Alle anderen Funktionen habe ich erstmal raus genommen und nur den ActionListener für den Exit Button drin gelassen.
Erst mal mein Code:
Java:
public class AddCocktails extends JDialog implements ActionListener
{
/**
* author Dinler Deniz
*/
JButton addButtonRecipe = new JButton("Hinzufügen");
JButton exitButton = new JButton("Beenden");
private static final long serialVersionUID = 1L;
AddCocktails() throws SQLException
{
JDialog addDialog = new JDialog();
addDialog.setTitle("Cocktails hinzufügen");
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
addDialog.setLocation(d.width/3, d.height/8);
addDialog.setSize(d.width/3, d.height/2);
addDialog.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.NONE;
/**
* Create the Layout (GridBagLayout) and add the Components into the Layout
*/
// JLabel Cocktail
c = makeC(0, 0, 2, 1);
c.insets = new Insets(20, 20, 0, 10);
addDialog.add(new JLabel("Cocktail"), c);
// LTextArea (with a titled Border) to write the recipe how to mix a cocktail
c.gridwidth = GridBagConstraints.REMAINDER;
JTextArea ta = new JTextArea();
ta.setPreferredSize(new Dimension(300, 100));
ta.setRows(21);
TitledBorder title;
title = BorderFactory.createTitledBorder("Cocktail-Rezept");
title.setTitleJustification(TitledBorder.CENTER);
ta.setBorder(title);
c = makeC(2, 0, 4, 12);
c.insets = new Insets(20, 10, 5, 20);
addDialog.add(ta, c);
//Button to save the recipe as a textfile
c = makeC(4, 12, 1, 1);
c.insets = new Insets(5, 10, 20, 5);
addButtonRecipe.addActionListener(this);
addDialog.add(addButtonRecipe, c);
// Exit Button
c.gridwidth = GridBagConstraints.REMAINDER;
c = makeC(5, 12, 1, 1);
c.insets = new Insets(5, 5, 20, 20);
c.anchor = GridBagConstraints.SOUTHEAST;
addDialog.add(exitButton, c);
this.exitButton.addActionListener(this);
// JTextField to write the cocktail name
c = makeC(0, 1, 2, 1);
c.fill=GridBagConstraints.HORIZONTAL;
c.insets = new Insets(5, 20, 5, 10);
JTextField tfCocktail = new JTextField("");
addDialog.add(tfCocktail, c);
// JLabel glass nr
c = makeC(0, 2, 2, 1);
c.insets = new Insets(0, 20, 0, 10);
addDialog.add(new JLabel("Glas"), c);
// JTextField to write the glass nr
c = makeC(0, 3, 2, 1);
c.fill=GridBagConstraints.HORIZONTAL;
c.insets = new Insets(5, 20, 5, 10);
JTextField tfGlassNr = new JTextField("");
addDialog.add(tfGlassNr, c);
// JButton Add Cocktail into table cocktails
c = makeC(0, 4, 1, 1);
c.insets = new Insets(5, 20, 5, 5);
JButton addButtonCocktail = new JButton("Hinzufügen");
addDialog.add(addButtonCocktail, c);
// JButton Delete Cocktail from table cocktails
c = makeC(1, 4, 1, 1);
c.insets = new Insets(5, 5, 5, 10);
JButton deleteButtonCocktail = new JButton("Löschen");
addDialog.add(deleteButtonCocktail, c);
// JLabel Ingredient
c = makeC(0, 5, 2, 1);
c.insets = new Insets(15, 20, 0, 10);
addDialog.add(new JLabel("Zutat"), c);
// JTextField to write the ingredient name
c = makeC(0, 6, 2, 1);
c.fill=GridBagConstraints.HORIZONTAL;
c.insets = new Insets(5, 20, 5, 10);
JTextField tfIngredient = new JTextField("");
addDialog.add(tfIngredient, c);
// JButton Add Ingredient into the tabel ingredients
c = makeC(0, 7, 1, 1);
c.insets = new Insets(5, 20, 5, 5);
JButton addButtonIngredient = new JButton("Hinzufügen");
addDialog.add(addButtonIngredient, c);
// JButton Delete Ingredient from the table ingredients
c = makeC(1, 7, 1, 1);
c.insets = new Insets(5, 5, 5, 10);
JButton deleteButtonIngredient = new JButton("Löschen");
addDialog.add(deleteButtonIngredient, c);
// JLabel Allocation
c = makeC(0, 8, 2, 1);
c.insets = new Insets(15, 20, 0, 10);
addDialog.add(new JLabel("Zuordnen"), c);
//JComboBox list of cocktails
c = makeC(0, 9, 2, 1);
c.fill=GridBagConstraints.HORIZONTAL;
c.insets = new Insets(5, 20, 5, 10);
CBXCocktails cbxCocktails = new CBXCocktails();
addDialog.add(cbxCocktails, c);
//JComboBox list of ingredients
c = makeC(0, 10, 2, 1);
c.fill=GridBagConstraints.HORIZONTAL;
c.insets = new Insets(5, 20, 5, 10);
IngredientsCBX cbxIngredients = new IngredientsCBX();
addDialog.add(cbxIngredients, c);
//JComboBox list of amounts
c = makeC(0, 11, 2, 1);
c.fill=GridBagConstraints.HORIZONTAL;
c.insets = new Insets(5, 20, 5, 10);
CBXAmounts cbxAmounts = new CBXAmounts();
addDialog.add(cbxAmounts, c);
// JButton Add the contain of the cbxs into the table ingredient_allocation
c = makeC(0, 12, 1, 1);
c.insets = new Insets(5, 20, 20, 5);
JButton addButtonAllocation = new JButton("Hinzufügen");
addDialog.add(addButtonAllocation, c);
// JButton Delete the contain of the cbxs from the table ingredient_allocation
c = makeC(1, 12, 1, 1);
c.insets = new Insets(5, 5, 20, 10);
JButton deleteButtonAllocation = new JButton("Löschen");
addDialog.add(deleteButtonAllocation, c);
addDialog.setVisible(true);
addDialog.pack();
}
private GridBagConstraints makeC(int x, int y, int width, int height)
{
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = x;
gbc.gridy = y;
gbc.gridwidth = width;
gbc.gridheight = height;
return gbc;
}
public void actionPerformed(ActionEvent ae)
{
if (ae.getSource() == exitButton)
{
this.dispose();
this.setVisible(false);
}
}
}
Vielen Dank im Voraus