?
Solved

Passing of information from JFrame to JFrame?

Posted on 2004-11-09
4
Medium Priority
?
441 Views
Last Modified: 2008-02-26
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.
0
Comment
Question by:coffee_bean
  • 2
  • 2
4 Comments
 

Author Comment

by:coffee_bean
ID: 12550639
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
 
LVL 3

Expert Comment

by:lilian-arnaud
ID: 12575926
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
 

Author Comment

by:coffee_bean
ID: 12584927
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
 
LVL 3

Accepted Solution

by:
lilian-arnaud earned 320 total points
ID: 12588226
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Progress
Introduction to Processes

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question