Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Closing Parent Window  RSS feed

 
VIV sharma
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers,

this in some part of my code,
actually my req. is to close the parent window(JFrame) on OK click of Dialog box, and on Cancel Dialog Close.

Thanks
ViV

// CODE
public class UpdateData extends JFrame
{

JPanel main_panel = new JPanel();
JPanel sub_panel = new JPanel();
JTable table = new JTable(data, name);
Button_Listener but_list = new Button_Listener();
JButton updateButton = new JButton("UPDATE");
JButton cancelButton = new JButton("CANCEL");
updateButton.addActionListener(but_list);
cancelButton.addActionListener(but_list);
JScrollPane messageSP = new JScrollPane(table);

main_panel.add(table);
sub_panel.add(updateButton);
sub_panel.add(cancelButton);

main_panel.setLayout( new GridLayout(2,1));
sub_panel.setLayout( new FlowLayout());

addWindowListener( new WindowAdapter() {
public void windowClosing( WindowEvent e ) {
return; } } );

getContentPane().add(main_panel);
main_panel.add(sub_panel);
setVisible(true);

class Button_Listener implements ActionListener
{
public void actionPerformed( ActionEvent event) {
System.out.println("in Button_Listener");
Object source = event.getActionCommand();

try
{


if(source.equals("UPDATE"))
{
System.out.println("UPDATE Command");
}
else
{

DialogListener dialogListener = new DialogListener();
JOptionPane jPane = new JOptionPane();

jPane.addMouseListener(dialogListener);
int check = jPane.showConfirmDialog(main_panel,"Are you sure you dont want to update the Edited Changes ?","Confirmation",JOptionPane.OK_CANCEL_OPTION);

}
}


class DialogListener implements MouseListener
{

public void mouseClicked(MouseEvent e)
{
System.out.println("Source" + e.getSource());
// here on click of 'cancel' i have to close the dialog box,
//and on click of 'OK' i have to close the dialog as well as Parent Window


}
public void mouseEntered(MouseEvent e)
{

}
public void mouseExited(MouseEvent e)
{

}
public void mousePressed(MouseEvent e)
{

}
public void mouseReleased(MouseEvent e)
{

}


}

}
 
jay kumar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well on click of ok use :
this.dispose() or simply dispose() (that is JFrame.dispose())

if it is cancel then use :

jPane.dispose()
--------------------------------------------------------------------------

the thing is u have to use the function 'dispose()' along with the object of the frame/dialog u have to close
--------------------------------------------------------------------------

did that help???
 
VIV sharma
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,

it's Working

Viv
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!