0

I have this problem: I have an ArrayList that contains a few items that I want to use in a particular frame, the problem is that the array list gets full by initializing it in the main class of my project. In this class I also launch my starting frame that is chained with other frames (login frame -> middle frame --> last frame). I want to carry this ArrayList without having to carry it on through all frames and get it directly usable from main --> last frame. How can I do this?

EDIT

Wat I did it was like first frame start with this ArrayList as parameter:

Jframe jf = new LoginFrame(arraylistvariable,"Login Window");           

Then in all ActionListener calls on the buttons that create new frames, disposing old ones, I set it like:

Jframe jo = new MiddleFrame(arraylistvariable,"Middle Window");

Passing this variable all over the frames but I want this to be like called only by the frame that needs this, because login frame doesn't need this variable. However, it is necessary to start the program by the login frame.

The BigBoss
  • 111
  • 2
  • 11

3 Answers3

1

"However, it is necessary to start the program by the login frame."

No it's not.

public class MiddleFrame() {
    private LoginFrame;
}

...
public static void main(String[] args){
    new MiddleFrame();
}

Make the middle frame not visible upon instantiation, but make the LoginFrame visible. If the login is successfful, but make the MiddleFrame visible.

Note You don't need to use to many frame. Make use of JDialogs. See this answer for How to make a Login with a JDialog

Community
  • 1
  • 1
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
  • sry mate, i meant it is mandatory because of an obligation from my professor because this is a project for a university exam, thanks for the explanation and the suggestion anyway – The BigBoss Jan 27 '14 at 19:29
  • Where is the `MiddleFrame` being loaded from? – Paul Samsotha Jan 27 '14 at 19:36
  • from an action listener connected to a button in the login frame that dispose the login frame and create the middle frame – The BigBoss Jan 27 '14 at 22:50
  • *"i meant it is mandatory because of an obligation from my professor"* I'd bet your professor said 'frame' as a generic term, rather than specifying many `JFrame` objects. Because that is just silly. – Andrew Thompson Jan 28 '14 at 00:50
0

one from the easiest way it to pass it/them trough system properties

Festus Tamakloe
  • 11,231
  • 9
  • 53
  • 65
0

You might want to create some class like ArrayListVariableProviderService and make it accessible either to all classes (JFrames) or via static call.

This can act as a container to many things, yet it'll abstract out all peculiarities.

Good luck.

Tanmay Patil
  • 6,882
  • 2
  • 25
  • 45