• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Clone Applet

 
Mohammad Farhat
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,
how is it going?
i have a java applet loaded inside a browser. The browser controls many of the functionalities of the applet, and can make modifications to it. That's not the issue...what i am currently doing is creating a button that does a clone of the current window, but the problem is that a fresh new copy of the applet is created inside the new browser with the default settings. What i need to do is to be able to clone the window with the current settings, i.e. if i changed some mode in the initial applet, i want that reflected in the new loaded applet. Any means to do that without the need to save all the current changes into some text file and have the new applet load from that file? this is a troublesome and heavy approach since there might be too many parameters i need to save. So if you know of any means to replicate the currenty opened window into a new one with the settings modified according to the old one, please advice...
Thanks a lot guys..
Best,
Mohammad
 
Lanny Gilbert
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's something that might work...

You can save your settings into Streams using the AppletContext and in your init() method, you can see if these streams exist. If so, you can load the data based on the streams.

Example....
// save a variable

ByteArrayOutputStream baos = new ByteArrayOutputStream ();
ObjectOutputStream oos = new ObjectOutputStream (baos);
oos.writeObject (<object name> ;
oos.close ();

byte [] data = baos.toByteArray ();

is = new ByteArrayInputStream (data);
baos.close ();
getAppletContext ().setStream ("<object name>", is);

In your init() method, check if this stream is null. If not, load it.

InputStream is = getAppletContext ().getStream ("<object name>");
ObjectInputStream ois = null;
if (is != null) {
try {
ois = new ObjectInputStream (is);
<object name> = ((<cast to object type) ois.readObject());
ois.close();
is.close();
}
catch (Exception e) {
e2.printStackTrace(System.out);
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic