2

So my Applet work like that :

The main .class is extended from JApplet, therefore it can be use as an applet.

This main class load other .class file to display new window, that are extented from JPanel.

This current set up work fine as an applet, however, in one of my JPanel class I have a button that open an URL. I use the Desktop API and it works fine on the browser, the problem is : It opens the URL in the same tab as the applet.

I would like the URL to open in a new tab from my JPanel. I know I can use something like :

  AppletContext a = getAppletContext();
  URL url = new URL(link);
  a.showDocument(url,"_blank");

but the method getAppletContext() only work from a class that has extented JApplet, not a JPanel.

I have tried to change my Jpanel to a JApplet but that seems to create some kind of mess.

Any idea how I could achieve that ?

Thank you !

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Inpu
  • 93
  • 10

1 Answers1

2

I haven't tried it, but two possibilities come to mind:

  • Pass the AppletContext to your JPanel as a constructor parameter.

  • Set the target attribute in the URL, as shown here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Genius, I have to rethink the design of my applet but I'm pretty sure your first thought will work. Thanks ! – Inpu Aug 30 '13 at 12:59