Results 1 to 3 of 3
  1. #1
    Mr tuition is offline Member
    Join Date
    Dec 2007
    Posts
    12
    Rep Power
    0

    Default 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:
    PHP Code:
    public class ReadXML {
        public ReadXML() {
            init();
           // Reads in the data from XML
          // sets StrAllData
    }
    private String StrAllData;
    in file Cpass.java:
    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 
      }

  2. #2
    Mr tuition is offline Member
    Join Date
    Dec 2007
    Posts
    12
    Rep Power
    0

    Default

    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);

  3. #3
    Mr tuition is offline Member
    Join Date
    Dec 2007
    Posts
    12
    Rep Power
    0

    Default

    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

  1. Eclipse adding $1.class files
    By eboraks in forum Eclipse
    Replies: 1
    Last Post: 11-28-2007, 05:35 PM
  2. how to see the code of class files
    By mary in forum Advanced Java
    Replies: 1
    Last Post: 08-02-2007, 02:52 PM
  3. 'class' and 'jar' files
    By ai_2007 in forum Advanced Java
    Replies: 1
    Last Post: 06-29-2007, 04:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •