[2044] in java-interest
Dialog does not wait user's choice...
daemon@ATHENA.MIT.EDU (pfu.fujitsu.co.jp!shira@fujitsuI.f)
Fri Sep 22 09:47:02 1995
From: pfu.fujitsu.co.jp!shira@fujitsuI.fujitsu.com
To: java-interest@java.Eng.Sun.COM
Date: Thu, 21 Sep 1995 18:52:22 JST
I'm trying to make a java application on JDK pre-beta1.
I want to create a Dialog confirms "Ok" or "Cancel" with
message and returns the answer as a boolean.
I've made a class named ConfirmDialog extending
java.awt.Dialog like:
------ Test.java ------ Test.java ------ Test.java ------ Test.java ------
/*
* Copyright (c) 1995 PFU Limited.
* author Kazuhisa SHIRAKAMI
*/
import java.awt.*;
class Test extends Frame {
public Test() {
super("Test");
add("Center", new Button("Test"));
add("South", new Button("Quit"));
resize(100, 100);
}
public synchronized boolean action(Event ev, Object arg) {
if (ev.target instanceof Button) {
if (((String)arg).equals("Test")) {
if ((new ConfirmDialog(this, "This is test")).confirm()) {
System.out.println("Ok button is selected");
} else {
System.out.println("Cancel button is selected");
}
return true;
} else if (((String)arg).equals("Quit")) {
System.exit(0);
}
}
return false;
}
public static void main(String args[]) {
(new Test()).show();
}
}
class ConfirmDialog extends Dialog {
private boolean confirm;
public ConfirmDialog(Frame parent, String msg) {
super(parent, true);
Panel message = new Panel();
message.add(new Label(msg));
Panel buttons = new Panel();
buttons.add(new Button("Ok"));
buttons.add(new Button("Cancel"));
add("North", message);
add("South", buttons);
}
public synchronized boolean confirm() {
resize(150, 50); // Why need to resize?
pack();
Rectangle parent = getParent().bounds();
Dimension me = size();
move(parent.x + (parent.width - me.width) / 2,
parent.y + (parent.height - me.height) / 2);
confirm = false;
show(); // Why don't wait until the dialog window hides?
// Why the window appeares on left upper corner of display once?
// Why "Ok" button is occasionally not visible?
return confirm;
}
public synchronized boolean action(Event ev, Object arg) {
if (ev.target instanceof Button) {
if (((String)arg).equals("Ok")) {
confirm = true;
hide();
return true;
} else if (((String)arg).equals("Cancel")) {
confirm = false;
hide();
return true;
}
}
return false;
}
}
--------------------------------------------------------------------------
The dialog is required to be modal because the client ---
who wants the answer of confirmation --- needs to get the
choice given via Ok/Cancel button. The method show() should
wait the user makes the choice, and should not return till
the choice be made. But it seems not to wait.
I can wait the dialog be hidden by checking isShowen()
status, but this idea seems too stupid.
How can I make ConfirmDialog#show() wait user's choice?
Do you have any idea?
Thanks in advance.
--
PFU Limited.
Kazuhisa SHIRAKAMI
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com