Passing of information from JFrame to JFrame?

How to pass information from one JFrame (say JFrame1) to another JFrame (say JFrame2)?

For eg, My JFrame2 has retrieve workstation id, startTime and endTime from access database.

Once user are satisfied with the selection, I want to pass these information to JFrame2.

User has to provide additional information on this JFrame2.

Once user click the submit button at JFrame2, workstation id, startTime, endTime (which are passed from JFrame1 to JFrame2) along with the addition information are inserted to the database.

Fyi: I have the Workstation and Reservation classes.

workstation id is a variable of Workstation class.
startTime and endtime are variables of Reservation class.

TIA.
coffee_beanAsked:
Who is Participating?
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.

coffee_beanAuthor Commented:
Fyi, I have the neccessary accessor method at the JFrame1 for workstationId, startTime & endTime so that JFrame2 could call it (thought I am not sure if this is a right way to do so. As workstationId is attribute belonging to workstation java class and startTime & endTime are attributes belonging to Reservation class.)

Howeven even with the accessor methods written for these variables at JFrame1, JFrame2 simply doesn't retrieve the information as said.

Appreciate any helps pls. Thanks a lot.
0
lilian-arnaudCommented:
add an attribute "reservation" to JFrame1/JFrame2, with its getter/setter.

// call to jFrame2

JFrame2 jFrame2  =new JFrame2();

jFrame2.setReservation(jFrame1.getReservation());

jFrame2.setVisible(true);

...
0
coffee_beanAuthor Commented:
what kind of attribute would this "reservation" be a String or a Componet?

I tried setting the attribute to a String & below is the error

cannot resolve symbol symbol  : method setReservation (java.lang.String) location: class javax.swing.JFrame
jFrame2.setReservation(frame1.getReservation());
                               ^
I still having problem in disposing the first frame from the second frame button click.

Additional Background info
--------------------------------
My 1st frame is declared inside this Java file, Main

public class Main extends JFrame implements ActionListener
{
JFrame frame1;
JPanel panel;
.....other variables...

public Main(){

frame 1= new JFrame();

panel = new JPanel();
..... some codes....
..... All other swing components are added to this panel
.....some codes....
frame1.getContentPane().add(panel);
....some codes.....
}
}

Then my 2nd frame2 is declared inside this Java file, ResourceReservation.java

public class ResourceReservationextends JFrame implements ActionListener
{
JFrame frame2;
....other variables...

public ResourceReservation(){
frame 2= new JFrame();
Container c =frame2.getContentPane();
..... some codes....
..... All other swing components are added to this c (the Container)
.....a button here....
}
}

I just can't get the 1st frame1 to dispose off on the button click inside frame2???











0
lilian-arnaudCommented:
the type of your attribute "reservation" must be Reservation.

Perhaps, you should replace a JFrame by a JDialog (Modal Window), see the class JOptionPane to create a JDialog.

If your twos JFrame want to exchange data, they must know each other:

public class ResourceReservation extends JFrame implements ActionListener
{
JFrame frame2;
....other variables...

public ResourceReservation(JFrame1 frame1){
frame 2= new JFrame();
// pass information between frames
frame2.setReservation(frame1.getReservation());

Container c =frame2.getContentPane();
..... some codes....
..... All other swing components are added to this c (the Container)
.....a button here....
JButton button = new JButton(
new javax.swing.AbstractAction("action") {
{
            public void actionPerformed(ActionEvent e) {
                  ... some codes ....
                   // hide (or dispose frame1)
                   frame1.setVisible(false);
            }
);
}
}
0

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
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
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.