lokesh05
Member
Reputation: 0
Offline
Gender: 
Posts: 32
Referrals: 0
|
 |
« 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"); } } } }
|