I'm creating a simple Task Manager, the issue I have is I want to open a new JFrame when I click the JButton. The window open's but the problem is multiple windows open. I have two classes App(Main) and NewTask. If someone could have a look at the code and see what I'm doing wrong that would be great, Sorry if I posted too much Code, Thanks in Advance.
App Class
JButton btnNewTask = new JButton("New Task");
btnNewTask.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JFrame frame = new JFrame ("New Task");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
//frame.getContentPane().add (new NewTask());
frame.pack();
frame.setVisible (true);
}
});
btnNewTask.setBounds(10, 216, 116, 23);
contentPane.add(btnNewTask);
NewTask Class
/**
* Launch the application.
*/
//public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
try
{
NewTask frame = new NewTask();
frame.setVisible(true);
}
catch (Exception e)
{
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public NewTask()
{
setTitle("New Task");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);