AppletBase and JAppletBase classes (Java™)
Applets must extend AppletBase or JAppletBase and use notesAppletInit(), notesAppletStart(), and notesAppletStop() as the entry points for their functional code. Use openSession() or openSession(String user, String pwd) to create a Session object.
The JAppletBase class is the same as AppletBase except that it imports com.sun.java.swing.* and extends JApplet rather than Applet.
For more information, see "Running a Java™ program" in the chapter "Java™ Classes Coding Guidelines."
Skeleton for Java™ applets that use Domino® Objects
This code demonstrates the essentials for an applet that uses Domino® Objects. AppletBase distinguishes between local and remote (IIOP) access, and uses NotesThread for local access in the main applet code. See the next section if the applet creates threads.
import lotus.domino.*;
public class foo extends AppletBase
{
// User declarations
public void notesAppletInit()
{
// User initialization code, for example, to set up a TextArea object
}
public void notesAppletStart()
{
Session s = null;
try
{
// Can also do openSession(user, pwd)
s = this.openSession();
if (s == null) { //not able to make the connection, warn user
ta.append("Unable to create a session with the server");
return;
}
// User code for main activities
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
try {this.closeSession(s);}
catch(NotesException e) {e.printStackTrace();}
}
}
}
Applets that create threads including AWT handlers
If an applet creates a thread that uses Domino® Objects, the thread code must explicitly use NotesThread for local access to Domino® Objects. Thread creation includes the handling of AWT events. Use AppletBase.isLocal to determine the applet's status.
The following code should go at the beginning of the thread before calling any Domino® Objects:
if (isNotesLocal())
{
NotesThread.sinitThread();
}
The following code should go at the end of the thread (for example, the finally block) after calling any Domino® Objects:
if (isNotesLocal)
{
NotesThread.stermThread();
}
Specification of AppletBase
The specification (public methods) of the AppletBase class is as follows:
public class AppletBase extends Applet
implements DominoAppletBase {
public Session getSession() throws NotesException;
public Session getSession(String user, String pwd)
throws NotesException;
public Session openSession() throws NotesException;
public Session openSession(String user, String pwd)
throws NotesException;
public void closeSession(Session session)
throws NotesException;
public final void init();
public void notesAppletInit();
public final void start();
public void notesAppletStart();
public final void stop();
public void notesAppletStop();
public final void destroy();
public void notesAppletDestroy();
public boolean isNotesLocal();
public NotesAppletContext getContext(Session session)
throws NotesException
}