OK, see how you go with this... Taking your original example, I worked up some skeleton classes thus. One, "JavaAgent", is the agent code. The other, "DomGUI" is the equivalent of your MyWindow class... some of the original code has been taken out for brevity. Notice the NotesThread calls in the sendToAll() method: they are key to the Domino interfaces / classes being accessible in sendToAll().
JAVAAGENT:
import lotus.domino.*;
public class JavaAgent extends AgentBase {
private Session session;
private AgentContext ac;
private Database db;
private String myString;
private DomGUI myWin;
public void NotesMain() {
try {
session = getSession();
ac = session.getAgentContext();
db = ac.getCurrentDatabase();
Document doc = ac.getDocumentContext();
if(doc!=null) {
myString = doc.getFirstItem("e_mail").getText();
} // end if
myWin = new DomGUI(session, db);
while (!myWin.isClosed) {
Thread.sleep(250);
} // end while
} catch(Exception e) {
e.printStackTrace();
} // end try catch
} // end NotesMain method
} // end JavaAgent class
DOMGUI:
import lotus.domino.*;
import java.awt.*;
import java.awt.event.*;
class DomGUI extends Frame implements ActionListener {
public boolean isClosed = false;
private Button btnPerson;
private Button btnSend;
private Session session;
private Database db;
private View view;
DomGUI(Session parentSession, Database currentDb) {
super("Mailing");
try {
this.session = parentSession;
this.db = currentDb;;
view = db.getView("MyView");
// enable window events
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
} catch(Exception e) {
e.printStackTrace();
} // end try catch
setLayout(new BorderLayout());
btnSend = new Button("Send to all");
btnSend.addActionListener(this);
add(BorderLayout.EAST, btnSend);
btnPerson = new Button("Send to a person");
btnPerson.addActionListener(this);
add(BorderLayout.WEST, btnPerson);
setSize(500,500);
setVisible(true);
} // end constructor
public void sendToAll() {
NotesThread.sinitThread();
// do view stuff here
NotesThread.stermThread();
} // end sendToAll method
// necessary to implement ActionListener
public void actionPerformed (ActionEvent e) {
if (e.getSource() == btnSend) {
sendToAll();
dispose();
isClosed = true;
} // end if
} // end method
protected void processWindowEvent (WindowEvent e) {
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
dispose();
isClosed = true;
} else {
super.processWindowEvent(e);
} // end if else
} // end method
} // end DomGUI class
--
Hope this is of use. Like I said before, thi is fairly new to me -- as is Java itself -- so if my code contains glaring horrors, my apologies. The thread sleeping is a bit of a cludge, but it works, and makes sense in the context of a Notes agent running in the foreground in any case.
--
http://www.benpoole.com