Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open new applet window from a applet

Tags:

java

applet

how can i open a new applet window from a applet itself?

like image 872
Chern Avatar asked Mar 12 '10 17:03

Chern


1 Answers

To open a new Java window (JFrame) from an applet, see the following extract from the Java tutorial:

//1. Create the frame.
JFrame frame = new JFrame("FrameDemo");

//2. Optional: What happens when the frame closes?
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//3. Create components and put them in the frame.
//...create emptyLabel...
frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);

//4. Size the frame.
frame.pack();

//5. Show it.
frame.setVisible(true);

To open a new browser window which also contains an applet showDocument(URL, "_blank"):

URL url = new URL(getCodeBase().getProtocol(),
                      getCodeBase().getHost(),
                      getCodeBase().getPort(),
                      "/next.html");
getAppletContext().showDocument(url, "_blank");
like image 84
Pool Avatar answered Sep 30 '22 00:09

Pool