Skip to main content

data from one class to another ??

1 reply [Last post]
Joined: 2009-07-29


I have a problem with my program :

I use a class "public class panel extends JPanel" to create the interface (menu, tree and so on).

In this class I use an other class "1" to define the file (Kmlfile), and then I use an other class "2" to read the file. => public class 1 extends 2
When I read the file I save the data (wich are in the kmlfile) in an array (String[]).

And I need this data in my class panel to do the interface.

I don't know how I can have the data in the class panel wich is not implents or extends with the class 1.

Can you help me.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2009-04-15

I'm not sure that I understand your question, so let me rephrase it the way i read it.

You want your data in class "1" to be visible in class "panel"?

In that case, just add class "1" as a variable in your panel class and then have some kind of getter implemented in class "1" for accessing your String array.

public class panel extends JPanel {
private Class1 class1;

public void someMethodThatAccessesClass1Data() {
String[] dataFromClass1 = this.class1.getData();

and then in Class1 have the following method.

public String[] getData() {
return this.kmlFileData; // assuming that kmlFileData is a variable in the class.

I hope it helps.