• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Can one applet load another?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I have gone to look for myself. If I should return before I get back, keep me here with this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic