File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes Applet from another Applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Applet from another Applet" Watch "Applet from another Applet" New topic
Author

Applet from another Applet

Devu Nair
Greenhorn

Joined: Sep 12, 2002
Posts: 3
Hi,
Is there any one who can help me in finding out how an Applet is called from another Applet. I need to call the second applet when an event is generated from the 1st applet ( e.g. on click of a button). Find attached the code I wrote for the 1st applet
import java.awt.*;
import java.applet.*;
/* <APPLET CODE=AWTEventDemo.class WIDTH=500 HEIGHT=500></APPLET>*/
public class AWTEvent extends Applet
{
TextField t1;
TextField t2;
Button b1;
// Default constructor
public AWTEvent()
{
// Call superclass
super();
setLayout(null);
setBackground(Color.lightGray);
t1=new TextField("1");
t1.reshape(10, 40, 80, 25);
add(t1);
t2=new TextField("2");
t2.reshape(10, 80, 70, 30);
add(t2);
b1=new Button("Button1");
b1.reshape(10, 120, 70, 30);
add(b1);

}
// Init method, called when applet first initialises
public void init()
{
setBackground( Color.gray );
}
public boolean action (Event evt, Object what)
{
// Was the focus of the event our button
if (evt.target == b1)
{
//this is where I need the new applet to be opened up, can any body give me a helping hand
// Clear the textfield
t1.setText(t2.getText());
// Event handled
return true;
}
else
return false;
}

// Overridden paint method
public void paint ( Graphics g )
{
g.setColor ( Color.blue );
}
}

Thanks in advance
Philip Pross
Ranch Hand

Joined: Jan 17, 2001
Posts: 76
To call your second applet from the first, all you have to do is call another web page that contains your second applet.
in your eventHandle(ActionPerformed)
try
{
getAppletContext().showDocument
(new URL("http://yourwebpage.com/index.html"),"_self");
}
catch (Exception ex) {System.out.println(ex}
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
The third item listed on Tony Alicea's web page is an example of inter-Applet communication.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Devu Nair
Greenhorn

Joined: Sep 12, 2002
Posts: 3
Thanks Philip Pross and Dirk Schreckmann, It worked.
Thanks a lot for your help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Applet from another Applet