Reputation: 65
When I select the create
option it will still show the options.
public Assign(){
setLayout(new BorderLayout());
JPanel jpnButton = new JPanel();
jpnButton.add(jbtCreate); //the selection for user to choose
jpnButton.add(jbtRetrieve);
jpnButton.add(jbtUpdate);
jpnButton.add(jbtDelete);
add(jpnButton, BorderLayout.CENTER);
jbtCreate.addActionListener(new ActionHandle());
jbtRetrieve.addActionListener(new ActionHandle());
jbtUpdate.addActionListener(new ActionHandle());
jbtDelete.addActionListener(new ActionHandle());
setTitle("Manage Supplier");
setSize(500,100);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public class ActionHandle implements ActionListener{
@Override
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == jbtCreate){ //if the user choose to create a new supplier then it will come out the previous selection together- Create,retrieve,update and delete
add(ptn1, BorderLayout.CENTER);
add(ptn2, BorderLayout.SOUTH);
ptn1.setBorder(new TitledBorder(null, "New Supplier Details"));
ptn1.add(new JLabel("Company Name"));
ptn1.add(jtxt1);
ptn1.add(new JLabel("Address"));
ptn1.add(jtxt2);
ptn1.add(new JLabel("Town"));
ptn1.add(jtxt3);
ptn1.add(new JLabel("Postcode"));
ptn1.add(jtxt4);
ptn1.add(new JLabel("Country"));
ptn1.add(jtxt5);
ptn1.add(new JLabel("Contact Information"));
ptn1.add(new JLabel("Contact Name"));
ptn1.add(jtxt6);
ptn1.add(new JLabel("Email"));
ptn1.add(jtxt7);
ptn1.add(new JLabel("Product Supply"));
ptn1.add(jtxt8);
ptn2.add(jbtOK);
ptn2.add(jbtCancel);
setSize(1000,500);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Upvotes: 0
Views: 78
Reputation: 15821
First of all set for first frame
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
and if you want to close first and open second use atach this listener to button in first JFrame
@Override
public void actionPerformed(ActionEvent e)
{
setVisible(false);
dispose();
new SecondJFrame();
}
to @Andrew Thompson :
System.exit();
causes the Java VM to terminate completely.
JFrame.dispose();
causes the JFrame
window to be destroyed and cleaned up by the operating system. According to the documentation, this can cause the Java VM to terminate if there are no other Windows available, but this should really just be seen as a side effect rather than the norm.
The one you choose really depends on your situation. If you want to terminate everything in the current Java VM, you should use System.exit()
and everything will be cleaned up. If you only want to destroy the current window, with the side effect that it will close the Java VM if this is the only window, then use JFrame.dispose()
.
Upvotes: 1