aspose file tools*
The moose likes Applets and the fly likes Applet ability to access HTML page! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Applet ability to access HTML page!" Watch "Applet ability to access HTML page!" New topic
Author

Applet ability to access HTML page!

Jimi Rock
Ranch Hand

Joined: Feb 19, 2001
Posts: 134
Hi all,
I would be grateful if some one could tell me if an applet can open an html page that could contain another applet.this html page is located in the same applet server.
if yes, then please provide me with the segment of code.
Thanks
Simon Xu
Ranch Hand

Joined: Aug 16, 2000
Posts: 235
hi,
This is what you want.

Regards
Jimi Rock
Ranch Hand

Joined: Feb 19, 2001
Posts: 134
Hi Simon,Thanks for your support.
but I don't know why your code does not work, I have added an action listener to a button and then write your code in the method actionPerformed as follows:

I have a Null pointer exception error, so I tried to add the code you provided as it is in the applet init method itself , no compilation error , on runtime error, but nothing happened!
Can you try it please,and tell me what is the problem?
Thanks,
Jimi.
Simon Xu
Ranch Hand

Joined: Aug 16, 2000
Posts: 235
hi, Jimi,
It may be because you are using Swing, which is not supported without plug in.
Simon
Jimi Rock
Ranch Hand

Joined: Feb 19, 2001
Posts: 134
Hi Simon,
It is not because of swing, because I am trying to do it under appletviewr...
Please provide me with your comments, it is urgent problem!
Thanks..
Dewang Shah
Greenhorn

Joined: Mar 14, 2001
Posts: 10
Why do you need to use JApplet applet = new JApplet()??
You need the AppletContext() of the applet that you are running, so just use

Also, AppletViewer does not support showDocument(). That is why you dont see any result. Try viewing the applet in a browser.
Jimi Rock
Ranch Hand

Joined: Feb 19, 2001
Posts: 134
Hi Dewang , I don't think that you mean I should use your single line of code , because I need a button on a JApplet to be able (when clicked) to open an html page that contains another applet. "Why do you need to use JApplet applet = new JApplet()??"
because I have the following error :
cannot resolve symbol : method getAppletContext()
so I have use a new instance of JApplet.
Please provide me with the segment of code that met my requirement, or specify another option , please!
Thanks...
Simon Xu
Ranch Hand

Joined: Aug 16, 2000
Posts: 235
hi, Jimi,

I think Dewang's comment is right.

It replaces the Web page currently being viewed with the given URL.
getAppletContext() is a method inherited from Applet. Just check your import statement.
Simon
Jimi Rock
Ranch Hand

Joined: Feb 19, 2001
Posts: 134
Hi Simon, Dewang,
Thanks for your help, my task is done now , the error was not related to your provided statement. it is related to my case as I have explained before.any way, the code is working now, may be you would like to take a look on it :

Thanks,
Jimi.
d kiruthika
Greenhorn

Joined: May 08, 2001
Posts: 5
Hi,
I tried to use the solution Jimi has given. I donot get any Exception or Error, but IE is not opening. Can you help me?
I have given my code here:
// My applet class
public class A extends JApplet
{
public void init()
{
DB db = new DB();
getContentPane().add(DB);

// setVisible, etc. properties
//pass this applet
DB.setApplet(this);
}
}
// both the classes are in the same folder under different .java files
public class DB extends JInternalFrame implements ActionListener
{
Applet currentapp;
JButton jb;

// other property setting code and other methods......//
DB
{
jb = new JButton("open browser");
jb.addActionListener(this);
getContentPane().add(jb);
}
public void actionPerformed(ActionEvent ae)
{
try
{
URL location = new URL ("http://www.hotmail.com"); // once it works I will be calling my html file
clientapp.getAppletContext().showDocument(location); // supposed to open a new IE with hotmail page
System.out.println("no error"); // in the output this line is printed, but the browser is not opened??? WHY ???
}
catch(Exception ex)
{
System.out.println(ex);
}
}

//get the reference to main Applet
public void setApplet(Applet recdapp)
{
currentapp = recdapp;
}
}

Thanks
regards,
Kiruthika
Jimi Rock
Ranch Hand

Joined: Feb 19, 2001
Posts: 134
Hi,
Could you please explain what you need to do , and what is clientapp?
in my situation, I have two applets , one is able to open the other. I advise you to do it as it is initially (just two applets), and then add your db or what ever...and try it again.

Regards,
Jimi.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Applet ability to access HTML page!