Welcome, Guest. Please login or register.
Did you miss your activation email?
Pages: [1]   Go Down
  Print  
Author Topic: Load one applet from another  (Read 880 times)
0 Members and 1 Guest are viewing this topic.
lokesh05
Member
*

Reputation: 0
Offline Offline
Gender: Male
Posts: 32
Referrals: 0

Awards
« on: July 02, 2008, 11:50:49 PM »

Suppose there are 2 applets, parent and child, and they are embedded into 2 separate HTML files :

i) parent.html
ii) child.html

The task on our hand is .. when there is an event in the parent.. for eg. a mouse-click or a button press.. it loads the child applet automatically.


I will demonstrate this with this example:.. here is an applet .. parent which has a button.. upon button press. it loads the child applet.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.applet.*;
 
public class parent extends JApplet implements ActionListener
{
   JPanel p=new JPanel();
   JButton b=new JButton("Submit");
 
   public void init()
    {
      b.addActionListener(this);
      p.add(b);
      getContentPane().add(p);
   
           parent p=new parent();
       }
 
   public void actionPerformed(ActionEvent ae)
   {
 
      if (ae.getSource()==b)
      {   //pay attention here
 
              AppletContext ac=getAppletContext();
         
            URL url=getCodeBase();
         
            try
             {
                           ac.showDocument(new URL(url+"child.html"));
              }
            catch (MalformedURLException e)
             {
         showStatus("URL not found");
              }   
          }   
          }
}

Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Your Ad Here