Link to home
Start Free TrialLog in
Avatar of C-begin
C-begin

asked on

JFrame application

Hi, My JFrame application is almost complete but I have one idea that I would like to implement.

How can I keep the last 5 open file in the menu bar?

if I click on one of the las open file it should be able to open? can Java do that?


Thank You
C-begin
SOLUTION
Avatar of InteractiveMind
InteractiveMind
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of OBCT
OBCT

Just like in the link I posted ;-)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of C-begin

ASKER

OBCT, Thanks for the link,

I thought it would be easier than that,


is the another wayx
Have you considered my way?

copy and paste that class where necessary, then here's an example of it being used:

...
String filename = "a file name and location";

LastFive lf = new LastFive();
lf.add( filename );
lf.add( "another filename" );
...
ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream( "saveFile.ser" ) );   // Save to file
out.writeObject( lf );                                                                                                              //
out.close();                                                                                                                           //

Then, later on, to load it back up, use this:

...
ObjectInputStream in = new ObjectInputStream( new FileInputStream( "saveFile.ser" ) );
LastFive lf = (LastFive) in.readObject();

String [] lastFive = new String [5];
for ( int i = 0; i < 5; i++ )
{
   lastFive[i] = lf.getFile( i );
   if ( lastFive[i] == "" )
      break;
}
...


I hope that helps..?

Regards;
By the way, to save you scrolling back up again, here's the class you'd require for my idea:


class LastFive implements Serializable
{
    String [] files = new String [5];
   
    public LastFive()
    {
        for ( int i = 0; i < files.length; i++ )
        {
            files [i] = "";
        }
    }
   
    public void add( String filename )
    {
        for ( int i = 0; i < files.lengthl i++ )
        {
            if ( files [i] == "" )
                files [i] = filename;
            else if ( i == 5 && files[i] != "" )
                files[0] = filename;
        }
    }
   
    public String getFile( int index )
    {
        return files[index];
    }
}

Avatar of C-begin

ASKER

InteractiveMind  I don't quit understand your suggestion,

I am a nocive in java programing so I need to see a few example,

Thank you
Okay, fair enough. Could you post the code that you've done so far? Then I'll implement my idea into it for you?
dear C-begin, didn't u test my code?
Avatar of C-begin

ASKER

Hi all,

I would like to thank you for helping me,

Your inputs will be rewarded just to be fair and to show my appreciatio. However OBCT
gave me a great Start with the link that he gave me. I was able to solve 90% of my request.


Thank You All.