Link to home
Start Free TrialLog in
Avatar of coffee_bean
coffee_bean

asked on

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.
Avatar of coffee_bean
coffee_bean

ASKER

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.
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);

...
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???











ASKER CERTIFIED SOLUTION
Avatar of lilian-arnaud
lilian-arnaud

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