Matt Gerrans
Posts: 1153
Nickname: matt
Registered: Feb, 2002
|
|
Re: opening web pages from an applet
|
Posted: Mar 10, 2002 2:15 AM
|
|
Here is a little sample applet that shows (just the bare essentials of) opening a web page in the browser, with a local file that has space characters in the path. I'm not sure if this will work if the applet is not running from your local system, though. Of course, if it is on a server somewhere, the chances it knows the locations of local html files on your system are slim (although, maybe you have a text field where someone can type in the page they want to go to, or something).
import javax.swing.*;
import java.awt.*;
import javax.swing.JApplet;
import java.awt.Graphics;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.net.URL;
import java.net.MalformedURLException;
public class OpenLocalPage extends JApplet
{
Container pane;
public void init()
{
pane = getContentPane();
JButton button = new JButton( "Browse Somewhere!" );
button.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
URL url = null;
try
{
url = new URL( "file:///D|/reference/Java%201.3%20Docs/api/index.html" );
}
catch( MalformedURLException mfue )
{
// TODO: Handle this exception appropriately!
}
if(url != null)
getAppletContext().showDocument(url);
}
} );
pane.add( button );
}
}
|
|