Hi,
I am brand new to Java programming, I am trying to implement an actionlistener to a button on a JDialog that closes that same JDialog on a click event.
Below you can find my code so far. My question is: how to close the JDialog frame with a buttonclick, the button is defined in the JPanel.
public class JAddCustomer extends JDialog { /** * */ private static final long serialVersionUID = 1L; public JAddCustomer() { JPanel cp = new customerPanel(); this.setSize(300, 300); this.setTitle("Add Customer"); this.setContentPane(cp); } } class customerPanel extends JPanel { /** * */ private static final long serialVersionUID = 1L; private JLabel lblName, lblSurname, lblStreet, lblNr, lblPc, lblCity; private JTextField txtName, txtSurname, txtStreet, txtNr, txtPc, txtCity; private JButton btnAdd; public customerPanel() { setLayout(null); Add a = new Add(); lblName = new JLabel("Voornaam: "); lblName.setBounds(20, 20, 100, 20); lblName.setHorizontalAlignment(JLabel.RIGHT); [...] btnAdd.addActionListener(a); add(lblName); [...] } class Add implements ActionListener { public void actionPerformed(ActionEvent e) { JCustomer customer = new JCustomer(txtName.getText(), txtSurname.getText(), new JAddress(txtStreet.getText(), txtNr.getText(), txtCity.getText(), txtPc.getText())); System.out.print(customer.toString()); [COLOR="Red"]HERE I WANT TO IMPLEMENT THE CODE TO CLOSE THE JDIALOG[/COLOR] } } }
Thank you in advance,
Christophe