Pausing execution of method for an event.

Greetings.

I wish to do something like the following:

Execute the first half of a method then have it pause midstride, only continuing once until an event occurs (like a button click or a keypress).

In many ways, I am trying to replicate the event handling of a dialog box, but without using JDialog, JOptionPane, etc., and so far have not met with any success in this.

Any assistance would be appreciated. Thank you.

[448 byte] By [kv1at3485] at [2007-9-30 22:51:41]
# 1
Hi,Usually it's not a good ideia to wait inside a method, why don't you divide your method in two? Then when the event occur just call the second method...Rgds,Andre'
acneto at 2007-7-7 13:25:51 > top of Java-index,Archived Forums,Java 2 Software Development Kit (J2SE SDK)...
# 2

Indeed. Unfortunately I do not see how that would lead to a solution to my problem. I shall try to explain.

Currently, I have something like this:

public class ParentFrame extends JInternalFrame {

private void createPsuedoDialog() {

// As you can see, I am trying to replicate the convenient functioning of a

// JOptionPane, but for a number of reasons, I am prevented from using

// JOptionPane.

int n=PseudoDialog.createDialog(...);

}

}

public class PsuedoDialog extends JInternalFrame implements ActionListener {

private int buttonClicked=0;

public int createDialog(...) {

// Put a glasspane over the parent frame. Create dialog interface here and

// display the dialog.

...

// Wait for the user to click a button here.

....

// Return an interger value representing the button clicked.

return buttonClicked;

}

public void actionPerformed(...) {

// Assign a value to buttonClicked depending on the button selected, and

// remove the glasspane from the parent frame.

...

}

}

The only other way I have solved this is by having the parent frame's actionListener detect clicks from the dialog's buttons, but this makes the system very inconvenient and cumbersome.

kv1at3485 at 2007-7-7 13:25:51 > top of Java-index,Archived Forums,Java 2 Software Development Kit (J2SE SDK)...
# 3

Hi,

It doesn't seem to be an easy task, anyway try to look at the Dialog (from SUN) code... I took this from there:

// We have two mechanisms for blocking: 1. If we're on the

// EventDispatchThread, start a new event pump. 2. If we're

// on any other thread, call wait() on the treelock.

From the method show() of the Dialog class

Good luck,

Andre'

acneto at 2007-7-7 13:25:51 > top of Java-index,Archived Forums,Java 2 Software Development Kit (J2SE SDK)...