Java Language Applets Open links from within the applet


You can use the method getAppletContext() to get an AppletContext object that allows you to request the browser to open a link. For this you use the method showDocument(). Its second parameter tells the browser to use a new window _blank or the one that shows the applet _self.

public class MyLinkApplet extends JApplet{
    public void init(){
        JButton button = new JButton("ClickMe!");
        button.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent ae) {
                AppletContext a = getAppletContext();                 
                try {
                    URL url = new URL("");
                } catch (Exception e) { /* omitted for brevity */ }