aspose file tools*
The moose likes Java in General and the fly likes How to transfer data when the 1st class calls the 2nd and 3rd, and the 2nd needs the 3rd. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to transfer data when the 1st class calls the 2nd and 3rd, and the 2nd needs the 3rd." Watch "How to transfer data when the 1st class calls the 2nd and 3rd, and the 2nd needs the 3rd." New topic
Author

How to transfer data when the 1st class calls the 2nd and 3rd, and the 2nd needs the 3rd.

Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

Okay so I have a class called Main which calls the draw class into a panel(works). Also in the main class I have a file opener to which the file is needed to read in the format class(works). This format class has info the draw class needs. How can I do this? I tried making a method to return the format class info, but I have to do Main main = new Main(); in the draw class which causes an infinite loop. So essentially I only need the format class data, how can I pas it along? I tried static also(not sure how static works fully either).

Im thinking this is important in a lot of things.... if I don't make 100% sense I will post some code.


The only thing I can think of is having a central class for storing everything in case some classes need others especially the data coming into the "main" class.... Maybe I will do that, so that way I only need the data and don't care about the rest of the class and if I do care I will have it called. I could also have another class for this one thing and maybe this might be a one time occurrence.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30762
    
156

I might not be understanding the problem correctly, buy why can't you have a data transfer object that you pass around?

Main
HelperDto d = new HelperDto();
Panel p = new Panel(d);

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

I forgot to mention that I believe I figured out the issue.

Class 1 Main is a Jframe and calls Draw which extends JPanel...

Draw needed the information in the format class to work.

Main has the menus which the "Open" menu is for selecting files[]. These files are read and then set into the format class. Once that's done I have to call it in the Draw Class. Now I realized I could just make a Constructor of Draw to read in the Format classes information and/or the file. I was really tired when I was doing this, and figured it out later in the day :P.
 
Don't get me started about those stupid light bulbs.
 
subject: How to transfer data when the 1st class calls the 2nd and 3rd, and the 2nd needs the 3rd.