Results 1 to 3 of 3
- 12-04-2007, 10:07 AM #1
Member
- Join Date
- Dec 2007
- Posts
- 12
- Rep Power
- 0
getting attributes from one class to another in 2 different .java files
Hi there,
I have run in to a little trouble which should be quite simple
I have 2 java files: one that loads the data, the second that displays data in a jframe
how can I pass the data from one to another?
in file ReadXML.java:
in file Cpass.java:PHP Code:public class ReadXML { public ReadXML() { init(); // Reads in the data from XML // sets StrAllData } private String StrAllData;
public class Cpass extends javax.swing.JFrame {
PHP Code:/** Creates new form Cpass */ public Cpass() { initComponents(); // on pushing a button new ReadXML(); // need a way to grab StrAllData // can then set a text field to this }
- 12-04-2007, 10:38 AM #2
Member
- Join Date
- Dec 2007
- Posts
- 12
- Rep Power
- 0
I have set StrAllData to puclic and tried to get this via ReadXML.StrAllData, but it tells me non-static variable can not be refrenced from a static context:
jTextArea13.setText(ReadXML.StrAllData);
- 12-04-2007, 10:49 AM #3
Member
- Join Date
- Dec 2007
- Posts
- 12
- Rep Power
- 0
This works:
In ReadXML create a getter for the StrAllData like this:
public String getStrAllData() {
return this.StrAllData;
}
In Cpass call getStrAllData on the ReadXML instance, for example:
ReadXML reader = new ReadXML();
String xmlContent = reader.getStrAllData();
Similar Threads
-
Eclipse adding $1.class files
By eboraks in forum EclipseReplies: 1Last Post: 11-28-2007, 04:35 PM -
how to see the code of class files
By mary in forum Advanced JavaReplies: 1Last Post: 08-02-2007, 01:52 PM -
'class' and 'jar' files
By ai_2007 in forum Advanced JavaReplies: 1Last Post: 06-29-2007, 03:11 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks