Radu Guest
|
Posted: Tue Feb 14, 2006 8:12 am Post subject: OO question |
|
|
Hi .
I have a program X.
In public class X, in main, I have something like
myFrame frame=new myFrame();
.....
In class myFrame extends JFrame, in the constructor "public myFrame()", I
have
.......
//Add panel to frame:
myPanel panel=new myPanel();
add(panel);
//Add a window events listener
addWindowListener(new WindowEventsListener());
.....
In class myPanel I implemented the isDirty property and an accessor,
getDirtyState. In WindowEventsListener, upon closing, I'd like to check the
isDirty property of myPanel.
My problem is that in WindowEventsListener I cannot say
public void windowClosing(WindowEvent e)
{
JOptionPane pane = new JOptionPane();
Toolkit.getDefaultToolkit().beep();
if (getDirtyState()==true)
{
if (pane.showConfirmDialog(e.getComponent(),"Save before quitting
?", "Program X", JOptionPane.YES_NO_OPTION)==0)
{
//The user chose YES
pane.showMessageDialog(e.getComponent(), "Save here - todo !", "Program
X",
JOptionPane.OK_OPTION);
System.exit(0);
}
else
System.exit(0);
}
}
because getDirtyState refers to myPanel, and I don't see myPanel from there.
Which is the proper OO way of passing this value all the way to my
WindowEventsListener, please ? The isDirty belongs in myPanel, not in
myFrame, and, either way, how would I pass that value to class
WindowEventsListener which extends WindowAdapter ?
Thank you, Alex. |
|