I already gave up trying to use java ui classes. Now i just want to know if there is at least 1 person who have succesfully used prompt in java agents?
Subject: See my answer in this thread
Subject: Almost
The trouble with Java dialogs is that there is no way (I know of) to get a handle to the parent window (the notes client) and to use that to create a modal dialog. This is a generic problem.
I have used Java dialogs with AWT by creating an invisible parent frame to make up for a lack of parent window.
I run an agent with the Java dialog code in, and it kind of works. It acts modally I think because the UI is frozen until the agent execution is over. There’s a fair bit of code, but the core is:
package ;
import java.awt.*;
import java.awt.event.*;
public class JavaDialog {
private Frame parent;
Dialog msgbox;
public static final int NO_ACTION = -1;
public static final int CANCEL_ACTION = 0;
public static final int OK_ACTION = 1;
int actionCode = NO_ACTION;
JavaDialog()
{
parent = new Frame();
}
public void dispose ()
{
// use this when you're ready to clean up
try { msgbox.dispose(); } catch (Exception e) {}
try { parent.dispose(); } catch (Exception e) {}
}
void displayMsgbox ()
{
// once all of the components have been added to a dialog,
// use this method to display it
msgbox.pack(); // organize all its components
Dimension d = msgbox.getToolkit().getScreenSize();
int xpos = (d.width - msgbox.getWidth()) / 2;
int ypos = (d.height - msgbox.getHeight()) / 2;
xpos = xpos < 0 ? 0 : xpos;
ypos = ypos < 0 ? 0 : ypos;
msgbox.setLocation(xpos, ypos); // center the dialog
msgbox.setResizable(true); msgbox.toFront(); // give it focus
msgbox.show(); // and display it
}
Dialog CreateDialog(String title)
{
msgbox = new Dialog(parent, title, true);
msgbox.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
actionCode = CANCEL_ACTION;
msgbox.dispose();
}});
return msgbox;
}
Button OkButton ()
{
// the OK button
Button ok = new Button("OK");
ok.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
actionCode = OK_ACTION;
msgbox.dispose();
}
});
return ok;
}
Button CancelButton ()
{
// the Cancel button
Button cancel = new Button("Cancel");
cancel.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
actionCode = CANCEL_ACTION;
msgbox.dispose();
}
});
return cancel;
}
Choice Dropdown (String[] selections)
{
// a dropdown box that allows a user to select from a list of
// multiple items
Choice dropdown = new Choice();
for (int i = 0; i < java.lang.reflect.Array.getLength(selections); i++)
dropdown.add(selections[i]);
return dropdown;
}
TextField PasswordTextField(String defaultText, int iLength)
{
TextField txtField = new TextField(defaultText, iLength);
txtField.setEchoChar('*');
return txtField;
}
void AddSubmitOnEnter(TextField textbox)
{
textbox.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
actionCode = OK_ACTION;
msgbox.dispose();
}
});
}
}
So yes, you can do it (ish)
S