• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can one applet load another?

 
Philip Stephens
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to build an application that has a treeview applet that loads other applets to show detail depending on the type of item selected in the treeview. This would require the treeview applet to load differnet applets as different nodes are selected. This would be an explorer style app with "plugin" capability as new applets are added.

Is this possible using standard methods (I know everything is possible, but I am a beginner).

Thanks - Phil S.
 
Venkata Narayana Reddy Pingala
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Below is the sample code of the applets communication:

[Applet1_0022.java] import java.awt.*;
public class Applet1_0022 extends java.applet.Applet {
TextField inputText;
Button b;

public void init() {
setLayout(new FlowLayout());
inputText = new TextField( "", 15 );
b = new Button("Send to Applet 2");
add(inputText);
add(b);
}

// JDK 1.02 style evant handling
public boolean action(Event ev, Object arg) {
if (ev.target instanceof Button) {
String textMsg = inputText.getText().trim();
Applet2_0022 applet2 =
(Applet2_0022)getAppletContext().getApplet("applet2");
if ( applet2 != null ) {
applet2.append( textMsg );
return true;
}
else {
System.out.println("Applet2 not found?");
return false;
}
}
return false;
}
}
[Applet2_0022.java] import java.awt.*;

public class Applet2_0022 extends java.applet.Applet {
TextArea textBox;

public void init() {
setLayout(new FlowLayout());
textBox = new TextArea( 5, 40 );
add( textBox );
}

public void append( String msg ) {
textBox.append( msg );
textBox.append( "\n" );
}
}
[HTML] <HTML><HEAD></HEAD><BODY>
<APPLET CODE="Applet1_0022.class"
NAME="applet1"
HEIGHT=200 WIDTH=150>
</APPLET>
<APPLET CODE="Applet2_0022.class"
NAME="applet2"
HEIGHT=200 WIDTH=400>
</APPLET>
</BODY></HEAD>
 
Philip Stephens
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, but does this not require both applets to already be running? Can the first applet start the next one?

Phil S.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds as if the enclosing code is an application, not an applet - is that correct?. Maybe the MainFrame class can help with this.
 
Christopher Arthur
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's really great to know! Coincidentally I was thinking of a page design where one applet would be the view and the other would be the conroller, but i wasn't sure it was possible.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic