I'm trying to open DebtForm.java
when the btnAddNewDebt
button is pressed from IOUApplication.java
. Once the button is pressed the IOUApplication.java
window should close and the DebtForm.java
window should open.
I've managed to open the DebtForm.java
when the btnAddNewDebt
button is pressed, yet I'm not able to close the IOUApplication.java
window.
I've tried using the following:
public void close(){
WindowEvent winClosingEvent = new WindowEvent(this,WindowEvent.WINDOW_CLOSING);
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(winClosingEvent);
}
Yet I'm not sure where to place the code or if there are any other alternate methods to close the window.
Here's a snippet of IOUApplication.java
for context:
public void initialize() {
frame = new JFrame();
frame.getContentPane().setBackground(Color.DARK_GRAY);
frame.setBounds(100, 100, 450, 132);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JButton btnAddNewDebt = new JButton("Add new debt");
btnAddNewDebt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DebtForm frame = new DebtForm();
frame.setVisible(true);
}
});
btnAddNewDebt.setBounds(81, 18, 117, 29);
frame.getContentPane().add(btnAddNewDebt);
JButton btnPersonalDebt = new JButton("Personal Debt");
btnPersonalDebt.setBounds(266, 18, 117, 29);
frame.getContentPane().add(btnPersonalDebt);
JLabel lblWrittenAndCoded = new JLabel("Written and coded by Samuel Kahessay");
lblWrittenAndCoded.setForeground(Color.WHITE);
lblWrittenAndCoded.setBounds(108, 88, 252, 16);
frame.getContentPane().add(lblWrittenAndCoded);
}