How do you practically save / load temporary user data with JApplet made of a JPanel app?

I would like to make some applets out of Java desktop applications, basically by loading JPanels
with the built-in functionality into JApplets. This is sort of a "test case" that I made here for you
to reduce your work looking over my problem.

I put loading the JPanel in the init() method of the JApplet, and I represented the user info that is to be saved when the user navigates away from the applet page with the array:

private String[] TestArray = { "one", "two", "three", "Original"};  

(This is in the JPanel of course, with the 'application' part.)

Where the TestArray[3] element of the array is being changed by the user as they type in something in the textfield and hit the Update button.

What I would like to see is that if I navigate away from the applet in the browser and then come back to it without closing the browser that the last values for TestArray are restored to the last user values as opposed to being reloaded with the initial values.

How do I set up the start() and stop() methods in the applet so that that happens?

Also, the button for loading the URL for Google in this example  used to work, but for some reason it will just generate an exception now. I don't know hat is happening with that.

Attached the source code in the code windows and I also uploaded the applet to the Web so that you can see it running as it is running at the URL:

import javax.swing.*;

import java.awt.Dimension;

public class Test_Applet extends JApplet {

	private Operating_Panel operating_Panel = new Operating_Panel();

	private String[] savedUserData = new String[4];


    public void init() {



    private void createGUI() {

    	 this.setSize(new Dimension(395, 213));




    //code for restoring/loading user's data when they return from a different page to applet

    public void start()






     //code for saving user's data when they go away from page with applet

    public void stop()



    	savedUserData = operating_Panel.getCurrentArrayOfNumbers();



Open in new window

Thank you.



	<body bgcolor="000000">



				code	= "Test_Applet.class"

				width	= "395"

				height	= "213"






Open in new window

import java.awt.Color;

import java.awt.Desktop;

import java.awt.Dimension;

import java.awt.Font;

import java.awt.Rectangle;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;




import javax.swing.JButton;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JTextField;

public class Operating_Panel extends JPanel {

    private JLabel jLabel1 = new JLabel();

    private JTextField jTextField1 = new JTextField();

    private JButton jButton1 = new JButton();

    private JLabel jLabel2 = new JLabel();


    private String[] TestArray = { "one", "two", "three", "Original"};

    private JLabel jLabel3 = new JLabel();

    private JButton jButton2 = new JButton();

    public Operating_Panel() {

        try {


        } catch (Exception e) {




    private void jbInit() throws Exception {

        this.setLayout( null );

        this.setSize(new Dimension(395, 213));

        jLabel1.setText("Last typed data:");

        jLabel1.setBounds(new Rectangle(90, 15, 210, 30));


        jLabel1.setFont(new Font("Tahoma", 1, 20));

        jTextField1.setBounds(new Rectangle(50, 95, 185, 35));

        jTextField1.setFont(new Font("Tahoma", 0, 13));


        jButton1.setBounds(new Rectangle(255, 95, 100, 35));

        jButton1.setFont(new Font("Tahoma", 1, 13));

        jButton1.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {




        jLabel2.setBounds(new Rectangle(90, 60, 165, 25));

        jLabel2.setFont(new Font("Tahoma", 1, 20));



        jButton2.setText("Open URL");

        jButton2.setBounds(new Rectangle(285, 0, 110, 20));

        jButton2.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {




        this.add(jButton2, null);

        this.add(jLabel2, null);

        this.add(jButton1, null);

        this.add(jTextField1, null);

        this.add(jLabel1, null);


    private void jButton1_actionPerformed(ActionEvent e) {

        System.out.println("Update Button Clicked");



        TestArray[3] = jLabel2.getText();


    private void jButton2_actionPerformed(ActionEvent e) {

        System.out.println("Open URL Clicked");

        // For some reason it does not bring up the webpage ???

        try {

                    String url = "";



                  catch (IOException ex) {






    // Getter to access the array to be saved from the Applet class:

    public String[] getCurrentArrayOfNumbers(){

    	return this.TestArray;




Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

What's your motivation for using an applet instead of an application? An applet needs to be signed in order to read from/write to disk
AttilaBAuthor Commented:
Well the motivation is for the application to run as an applet so that the applet can serve as an online demo for the application, with limited capabilities.

So, actually when you browse away from the applet is all the data in the applet lost forever from memory?

Is there any way to store away data in memory, that could be retrieved after returning to the applet page?

If that's the case and "signing in the applet" would be the only option and store a temp file on the user's machine, I guess.

Code-wise, is signing in the applet an involved process? There must be a standard way to do it, I hope.
>>Well the motivation is for the application to run as an applet so that the applet can serve as an online demo for the application, with limited capabilities.

It will be easier to fulfill your use case with Web Start. That will give you an online demo with limited persistence abilities without needing the code to be signed and won't require any paradigm shift from application to applet

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

AttilaBAuthor Commented:
So, you are saying that instead of being a simple applet, it would be easier to deploy something like this as a JWS (Java Web Start) application.

I did a search what JWS is, and found some tutorials like this one:

Seems to make sense also I tried how it runs, from another tutorial, which lets you try it online
how the security dialog comes up for the user:

Here is a scary thought though:

The tutorial talks about "placing the jnlp file in web server(tomcat) root folder".
So this implies that this is MY web server, I have FULL access to.

So I do need to have FULL access to the computer the web server runs on, as opposed just having access to a home folder on the server where up until now I have uploaded my .class files, images and
HTML code?

AttilaBAuthor Commented:
Well, actually Web Start appears to be the best solution if I wanted to save user info, as you suggested. Thanks.

>>as opposed just having access to a home folder on the server where up until now I have uploaded my .class files, images and HTML code?

You can't deploy a real world web-enabled solution in that way anyway
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.