• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Applet ability to access HTML page!

 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 235
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
This is what you want.

Regards
 
Jimi Rock
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 235
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, Jimi,
It may be because you are using Swing, which is not supported without plug in.
Simon
 
Jimi Rock
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 235
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic