0

I want to call (just display another applet)one applet from another applet . I just placed a button on my first applet and on its actionperformed method used the getcontextapplet() method. But second applet was not displayed.

How can I display a second applet on any reaction of first...

The code:

import java.io.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
public class home extends Applet implements ActionListener
{
    Container c1;
    Label l1,l2,l3,l4;
    TextField t1;
    Button b1,b2;
    ImageIcon icon;
    Panel p1;
    URL order;

    public void init()
    {
        // Tell the applet not to use a layout manager. 
        setLayout(null); 



        l1=new Label("MINDSOFT CONSULTANTS");
        Font fg=new Font("Times new roman",Font.BOLD,50);
        add(l1);
        l1.setFont(fg);
        l1.setBounds(20,20,800,70);

        l2=new Label("Strength of 5000 employees");
        fg=new Font("Times new roman",Font.BOLD,25);
        l2.setFont(fg);
        l2.setBounds(180,120,500,30);
        add(l2);

        l3=new Label("Specialised in IT and computing services");
        l3.setFont(fg);
        l3.setBounds(90,180,500,30);
        add(l3);

        l4=new Label("A total of 10 different departments");
        l4.setFont(fg);
        l4.setBounds(140,240,500,30);
        add(l4);

        b1=new Button("VIEW DETAIL");
        b1.setBounds(150,320,150,40);
        add(b1);
        b1.addActionListener(this);

        b2=new Button("ADD DETAIL");
        b2.setBounds(450,320,150,40);
        add(b2);

        try
        {
        order =new URL("C:\Documents and Settings\Administrator\Desktop\try\add.html");   
        }
        catch(MalformedURLException e){
        System.out.println("HH");
        }


    }

    public void actionPerformed(ActionEvent e)
    {

        if(e.getSource()==b1)
        {
        getAppletContext().showDocument(order);
        System.out.println("HI");
        }

    }
}   
10
  • 2
    I'd suggest that you need to post some code to avoid an inevitable downvoting into oblivion...
    – razlebe
    Oct 19, 2009 at 21:17
  • 1
    Can you show what you have done and what unwanted behavior is? And I don't understand. You have two applets on a page and you want one applet to do an action on the other applet? Oct 19, 2009 at 21:17
  • Actually i need to enter some details in first applet. with a button click i want to get another applet where i need to add some other information.
    – user161004
    Oct 19, 2009 at 21:23
  • You said: I m trying to call another applet button click of other Applet. I wonder, is it working?
    – OscarRyz
    Oct 19, 2009 at 21:53
  • It's nice that you try that, come back when you'll have a question and/or some code
    – Nettogrof
    Oct 19, 2009 at 21:55

2 Answers 2

0

If you're still seeing an "Illegal Escape Character" error on line 57, it's down to the string literal you're passing when instantiating order:

order =new URL("C:\Documents and Settings\Administrator\Desktop\try\add.html");   

The Java Escape Character is the backslash (\). Therefore, every time you use a back slash, the compiler thinks you're trying to escape the character that follows it. For example, in the string

C:\Documents

...the compiler is treating \D as a single escaped character rather than as two characters. The compiler error you're seeing is telling you that it doesn't recognise some of the escaped characters (\D, \A, \t) in that string.

The solution is to escape the escape character, e.g. prefix each backslash with a blackslash:

order =new URL("C:\\Documents and Settings\\Administrator\Desktop\\try\\add.html"); 

This tells the compiler to treat the backslashes as backslashes, rather than as escape characters.

1
  • The error has been removed by the above methid. but still i cant open the other applet using appletviewer. Suggest some other technique if possible..
    – user161004
    Oct 20, 2009 at 8:29
-1

Try http://www.wutka.com/hackingjava/ch10.htm or simply Google for inter applet communication

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.