Re: How to pass values between frames? (like login session)

I just joined that thread and it seems to me that you complicate your life a lot for nothing

YES you can pass whatever you want from one class to another what is your problem ?

String are immutable in Java is that whjat cause you a problem ?
If it is the case just create the class

class User {
String username;
}

pass a User object to all the classes/method that require it
change the username value on the fly if require

If does not fix it, clearly explain your problem (or more exactly what you perceive as a problem) because there in no problem there !!!

I know that I'm really bugging programmers here. I'm looking for your kind consideration.
Please pardon me for I have a poor understanding java in a natural way like other programmers do.
I have my own way on understanding, more like by codes.

I'll try to explain how I really wanted the program to be.

In Frame1, variable user (username and user are totally different variables) is generated through user's input, which is:

It passes to the Frame2's dbConnect() method. At first I thought that by passing to dbConnect() method,
all the methods in Frame2 can use it to pass it to Frame3, Frame4 and so on. What I want to know is that
how can I pass it to Frame2 but not just dbConnect() method can I use it, and all of Frame2's method can use
it so that it can also be passed on the following frames (Frame3, Frame4, Frame5, etc...).

I tried f2.Manager(user); because it's the name of the Frame2, I thought all the methods in Frame2 would be able
to use it. But as what g00se said, I can't use it at the moment.

I'm ashamed of myself, please close this thread if I've gone too far to ask for help.

Re: How to pass values between frames? (like login session)

Posted 26 February 2013 - 07:21 AM

I think there are a lot ways of getting a variable from private classes such as jButton1. I just don't know the proper way to do it on my case.
It seems that it is preventing me from accessing the variables declared in jButtonActionPerformed, can anyone tell me why and how to solve it?

Tried browsing on google on different ways of passing variables from private classes like jButton but most of them were too complicated or advanced and beyond my knowledge.

Re: How to pass values between frames? (like login session)

Posted 26 February 2013 - 09:13 AM

In broad terms, it should be passed to where it's going to be used. Sometimes that will be into the ctor of another class, sometimes to a method in that other class. That's of course assuming that another class is involved

Re: How to pass values between frames? (like login session)

Posted 26 February 2013 - 03:22 PM

g00se, on 26 February 2013 - 09:13 AM, said:

In broad terms, it should be passed to where it's going to be used. Sometimes that will be into the ctor of another class, sometimes to a method in that other class. That's of course assuming that another class is involved

Yeah, it should be passed to a method of other class but how? Based on my last attempt, it doesn't get the value of the variable.

Thanks! Now I'm able to pass variables by using instance variables but when I tried to pass in three frames (from Frame1 to Frame2 then to Frame3 then back to Frame2 again),
server says "Data source rejected establishment of connection, message from server: "Too many connections"". It also prevents me from going to the Frame3.

Re: How to pass values between frames? (like login session)

Posted 27 February 2013 - 04:14 AM

Using frames like that is messy. It's seldom seen in professional apps. Your app should have ONE frame and any other window should normally be of the dialog kind. See http://technojeeves....with-cardlayout
That can be extended to include other views into your app

Re: How to pass values between frames? (like login session)

Posted 27 February 2013 - 05:03 AM

g00se, on 27 February 2013 - 04:14 AM, said:

Using frames like that is messy. It's seldom seen in professional apps. Your app should have ONE frame and any other window should normally be of the dialog kind. See http://technojeeves....with-cardlayout
That can be extended to include other views into your app

Well, I'm not yet a professional.. But I think I would start learning about it later on after this project. Thank you for informing me about that.

pbl, on 27 February 2013 - 04:49 AM, said:

Despite the fact that you should use a CardLayout there is no reason to have more than one connection into your database. There are 2 solutions:

- make MyDB a singleton and thus always maintaining a single connection
- close the connection after each SQL call performed by a method of MyDB

Re: How to pass values between frames? (like login session)

Posted 01 March 2013 - 04:50 PM

We have been helping you with this for 20 - 30 posts. You've been given almost every possible perspective and answer on the topic. What more can we do, can anyone do? User getter and setter methods to access the variables between class instances.