javanetbeansjpaneljsr296

Java Desktop Application Using Netbeans


I am working on tutorial software which help to solve problems of a Financial Book. So it is something like an worksheet kind of thing containing combo-boxes and formatted text boxes. Everything is working as i want except one thing. Is there a way i could save my work done by me any point of time.

Lemme be specific. There are twelve chapters and each chapter contains some 15-20 problems. Each problem is design with combination of text boxes and combo-boxes and some jtabbed panel etc. If i solved half my worksheet and want to save so that i could open it later i open my software. Is there any way to do that. The problem is every sheet have different no of combo-box and text boxes so the variable are also different.

Thanks in advance


Solution

  • You need a model for your worksheet. This model is a data-structure and has nothing (per se) to do with the fact that GUI widgets are used to represent it.

    You save the state of the model -- start with simple Serialization -- to disk on save. Load on startup.

    Something along these lines allow for uniform treatment of your worksheets.

    public interface PersistentModel {
        boolean save (OutputStream out) throws IOException;
        boolean load (InputStream out) throws IOException;
    }
    public interface SpreadSheet extends PersistentModel {
        Worksheet[] getWorksheets();
        Worksheet getWorksheet(int i); // and other related, etc.
    }
    
    public interface Worksheet extends PersistentModel {
       int id();
       Element get(String name):
       Element[] getElements();
    
       public interface Element<T> extends PersistentModel { 
            String getName();
            T getValue();
            boolean setValue(T v);
       }
    }
    

    Swing uses MVC and you have standard mechanisms of hooking your model (the data structure holding state of the worksheets), and, the GUI (swing likely) that is the presentation of the same. I assume that is not an issue.