Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

opening browser window from an applet

 
Anna Dow
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, guys,
I wonder how to open a new browser window from the applet (e.g. when user clicks a button)? I remember seeing such thing somewhere, and now I would like to do it myself and can't
 
Philip Pross
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there, to answering your question fast here what I've already done and it works perfect.
//MY JAPPLET
import java.awt.*;
import java.applet.*;
import javax.swing.*;
public class Applet1 extends JApplet
{
public void init()
{
//SENDING "this" TO MY CLASS TOOLS
Tools tool = new Tools(this);

Login log = new Login();
}
}

//ACTION LISTENER TO OPEN BROSWER
btLogin.addActionListener( new ActionListener()
{
Tools tool = new Tools();
public void actionPerformed (ActionEvent e)
{
URL url = new URL("www.yourWebSite.com");

tool.getAppletThis().getAppletContext().showDocument(url, "test");
}
});
//AND MY CLASS TOOLS
import java.net.*;
import java.net.URL.*;
import java.applet.Applet;
class Tools extends Applet
{
static Applet applet;
Tools(Applet unApplet)
{
applet= unApplet;
}
Tools()
{}

public Applet getAppletThis()
{
return applet;
}
}
Go for it and try it.
Phil
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic