• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Jay Orsaw
Ranch Hand
Posts: 356
Android Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34851
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic