[2945] in java-interest
Modality of dialogs/frames
daemon@ATHENA.MIT.EDU (Ron van Hoof)
Sat Oct 21 06:44:52 1995
Date: Wed, 18 Oct 1995 22:58:22 -0400
From: rvhoof@nynexst.com (Ron van Hoof)
To: java-interest@java.sun.com
Cc: rvhoof@nynexst.com
Hi all!
I'm currently writing a backward chainer (inference mechanism)
and need to use an ask-dialog, in case a value for an attribute cannot
be found in the knowledge base.
Does anybody know how I can implement the modality for a frame.
(The current Java Dialog does not support modality yet and Netscape
2.0 doesn't support the dialogs at all (gives errors)).
Below I've given the methods calling the ask-dialog and the class
for the ask-dialog itself. Any feedback is welcome...
Ron
In the class Variable I have the following two methods:
public void traceValues() {
// Start tracing the value for the variable. First try to
// infer the variable based on the rules in the knowledge
// base, if this doesn't provide a value for the variable
// then if the variable is askable, ask for the value.
ruleBase.traceHandler().writeTrace("Tracing values for "+name);
infer();
if ((established() == false) && isAskable()) {
ruleBase.traceHandler().writeTrace("Asking value for "+name);
ask();
} // end if
setTraced(true);
} // traceValues
public void ask() {
AskDialog askDlg;
System.out.println("Entering ask");
askDlg = new AskDialog();
// process results dialog
if (askDlg.pressedButton().equals("OK")) {
System.out.println("OK");
setTraced(true);
value = askDlg.getText();
System.out.println("value: "+value().toString());
}
else if (askDlg.pressedButton().equals("Cancel")) {
setTraced(false);
System.out.println("Cancel");
askDlg.dispose();
} // end if
} // ask
Next is the class AskDialog itself:
class AskDialog extends Frame {
// Attributes
TextField askField;
String result = "";
String pressedButton = "";
// Methods
public AskDialog() {
//Set title of Dialog and make Dialog modal
super("Ask...");
// Create textfield
askField = new TextField(30);
Panel north = new Panel();
north.setLayout(new BorderLayout());
north.add("Center", askField);
// Create Button panel
Panel center = new Panel();
center.setLayout(new FlowLayout());
center.add(new Button("OK"));
center.add(new Button("Cancel"));
add("North", north);
add("Center", center);
// Set Dialog window size
resize(300, 100);
show();
} //AskDialog
public boolean action(Event evt, Object arg) {
if ("OK".equals(arg)) {
System.out.println("OK pressed");
pressedButton = "OK";
result = askField.getText();
//this.hide();
}
else if ("Cancel".equals(arg)) {
System.out.println("Cancel pressed");
pressedButton = "Cancel";
//this.hide();
}
return true;
} // action
public String pressedButton() {
return pressedButton;
} // pressedButton
public String getText() {
return result;
} // getText
} // AskDialog
---------------------------------------------------------------------
Ron van Hoof NYNEX Science & Technology, Inc.
Member of Technical Staff Research & Development
Work Systems Design Group
E-Mail: rvhoof@nynexst.com 400 Westchester Avenue, Rm 115a
Voice: (914) 644-2046 White Plains, NY 10604
Fax: (914) 949-9566 USA
---------------------------------------------------------------------
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com