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.
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.
add an attribute "reservation" to JFrame1/JFrame2, with its getter/setter.
// call to jFrame2
JFrame2 jFrame2 =new JFrame2();
jFrame2.setReservation(jFr ame1.getRe servation( ));
jFrame2.setVisible(true);
...
// call to jFrame2
JFrame2 jFrame2 =new JFrame2();
jFrame2.setReservation(jFr
jFrame2.setVisible(true);
...
ASKER
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(fra me1.getRes ervation() );
^
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().ad d(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???
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(fra
^
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().ad
....some codes.....
}
}
Then my 2nd frame2 is declared inside this Java file, ResourceReservation.java
public class ResourceReservationextends
{
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.