passing parameters to Event Handler

Is there a way to do that? I really need to be able to call a method from a windowListener's event handler, but that method has 3 strings as parameters and throws IOException. Here's the code, but it's pretty self explanetory...

public RunMethodTesting(JFrame frame){

frame.addWindowListener(this);

progressBar =new JProgressBar(0, 100);

progressBar.setValue(0);

progressBar.setStringPainted(true);

JPanel panel =new JPanel();

panel.add(progressBar);

add(panel, BorderLayout.PAGE_START);

}

publicvoid propertyChange(PropertyChangeEvent evt){

if ("progress" == evt.getPropertyName()){

int progress = (Integer) evt.getNewValue();

progressBar.setValue(progress);

}

}

publicstaticvoid createAndShowBarGUI(String filenamed, String file2named, String savedFile)throws IOException{

//Create and set up the window.

JFrame frame =new JFrame("Progress Bar");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Create and set up the content pane.

JComponent newContentPane =new RunMethodTesting(frame);

newContentPane.setOpaque(true);//content panes must be opaque

frame.setContentPane(newContentPane);

filenamed = filenamed;

file2named = file2named;

savedFile = savedFile;

//Display the window.

frame.pack();

frame.setLocationRelativeTo(null);

frame.setVisible(true);

}

publicvoid windowActivated(WindowEvent we){

action(filenamed, file2named, savedFile);

}

publicvoid windowDeactivated(WindowEvent we){}

publicvoid windowClosed(WindowEvent we){}

publicvoid windowDeiconified(WindowEvent we){}

publicvoid windowIconified(WindowEvent we){}

publicvoid windowClosing(WindowEvent we){}

publicvoid windowOpening(WindowEvent we){}

publicvoid windowOpened(WindowEvent we){}

publicvoid action(String filenamed, String file2named, String savedFile)throws IOException{

Task task =new Task();

task.addPropertyChangeListener(this);

task.runMethod(filenamed, file2named, savedFile);

}

createAndShowBarGUI() gets called first.

Thanks

[4393 byte] By [snoboardera] at [2007-11-27 6:03:04]
# 1

well, you need the try/catch around it or it won't compile. But otherwise, that's probably okay... Except...

windowActivated is called every time the window is moved to front from not being in front, and possibly on deiconifying as well (can't remember off-hand). If this is a single-use dialog, that's okay, but a long lasting frame, you probably don't want it repeating that every time the window moves to front.

You probably should just call your action method in the property change method where you show the actual frame.

bsampieria at 2007-7-12 16:45:19 > top of Java-index,Java Essentials,New To Java...
# 2
where would I put the try block to make it compile? That's my issue right nowp.s. and it is a single use window, once it's gone its not coming back
snoboardera at 2007-7-12 16:45:19 > top of Java-index,Java Essentials,New To Java...
# 3
I see that you've got your jprogressbar outside of the swingworker code. good for you.
petes1234a at 2007-7-12 16:45:19 > top of Java-index,Java Essentials,New To Java...
# 4
yep, I was meaning to thank you, I got that part working
snoboardera at 2007-7-12 16:45:19 > top of Java-index,Java Essentials,New To Java...
# 5

> where would I put the try block to make it compile?

> That's my issue right now

Around the method call that throws an exception.

> p.s. and it is a single use window, once it's gone

> its not coming back

Still not worth using a WindowListener just to invoke it, IMO. The user can still click another window in another app (email, browser) and then reactivate your frame.

JFrame.setVisible() does not block (last I checked).

bsampieria at 2007-7-12 16:45:19 > top of Java-index,Java Essentials,New To Java...
# 6
> yep, I was meaning to thank you, I got that part> workingThanks are nice,... Duke's stars are better :)
petes1234a at 2007-7-12 16:45:19 > top of Java-index,Java Essentials,New To Java...