|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Child/parent frames
i have a parent frame that opens up a child frame when a JButton is clicked
Code:
JFrame frame = new JFrame("Confirm");
JComponent y = new NewJPanel();
y.setBackground(Color.BLACK);
y.setForeground(Color.YELLOW);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_C LOSE);
frame.setContentPane(y);
frame.setSize(300, 400);
frame.setVisible(true);
frame.requestFocus();
//the frame opens up a pre-existing Jpanel
now i have "dispose on close " so there is no "cascading effect" when the child is closed by the "x" at the top right of t he window, but i need the jframe to close by pressing "exit" button on the child JFrame without putting System.exit(0) which closes parent and child regardless of "Dispose_on_close" is there any command i can place for the actionPerformed for "exit button" which doesnt cause the cascading effect also is there any way to disable/enable buttons on the parent JFrame from the child JFrame? for example: when the "exit button" is clicked on the Child frame it would enable another button on the parent JFrame ? |
|
#2
|
|||
|
|||
|
ok so i scrapped the whole child frame trying to close itself
but now i have a new dilemma, how would i have the parent window close the child window when a jbutton is pressed ? i Set up the open child jframe like this - Code:
//Button Actions
private class EventHandler implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
//created child jframe here so buttons may access the objects "frame" & "y"
JFrame frame = new JFrame("Confirm");
JComponent y = new NewJPanel();
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_C LOSE);
if(evt.getSource() == RefiButton)
{
reason = Refi;
}
else if(evt.getSource() == PayCredButton)
{
reason = PayCredit;
}
else if(evt.getSource() == GetCashButton)
{
reason = Cash;
}
else if(evt.getSource()== ShortSaleButton)
{
reason = Sale;
}
else if(evt.getSource() == ForeClosedButton)
{
reason = ForeClose;
}
else if(evt.getSource() == SellPropButton)
{
reason = Sell;
}
else if(evt.getSource() == BuyInvestButton)
{
reason = Invest;
}
else if(evt.getSource() == BuyNoDownButton)
{
reason = Buy;
}
if(evt.getSource() == Clear)
{
restart();
frame.dispose();
}
if(evt.getSource()== Confirm)
{
y.setBackground(Color.BLACK);
y.setForeground(Color.YELLOW);
frame.requestFocus();
frame.add(y);
frame.setSize(300, 400);
frame.setVisible(true);
No.setEnabled(true);
Yes.setEnabled(true);
}
if(evt.getSource() == Submit )
{
create_file(FName, LName, Address,cit,sta,zip,Email,phoneNumber,reason);
JOptionPane.showMessageDialog(null,"Thank You!\n You will be contacted shortly about your request.");
frame.dispose();
restart();
}
if(evt.getSource() == No)
{
//for somer reason child jframe does not close when this jbutton is clicked
frame.dispose();
No.setEnabled(false);
Yes.setEnabled(false);
Submit.setEnabled(false);
}
if(evt.getSource()== Yes)
{
//for somer reason child jframe does not close when this button is clicked
frame.dispose();
Submit.setEnabled(true);
}
}
}
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > Child/parent frames |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|