From Frame1.java to Frame2.java?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: From Frame1.java to Frame2.java?

  1. #1
    alex Guest

    From Frame1.java to Frame2.java?


    If I have a declaration in Frame2.java like this "String z="y";
    and I want to pass the value from z to " String d;" that is declare in Frame1.java.
    How would I accomplish this?

    thanks in advance


  2. #2
    Ruchi Dhar Guest

    Re: From Frame1.java to Frame2.java?


    In true object world you need to to have setXX(String xx) method in Frame1.java
    and while creating Frame2 pass the reference of frame1. When you want to
    assign the value of z call the setXXX method with z as parameter. In the
    other world declare the d as public static variable in Frame2 you can assign
    value by asscssing directly Frame1.d = z;


    "alex" <cad1374@yahoo.com> wrote:
    >
    >If I have a declaration in Frame2.java like this "String z="y";
    >and I want to pass the value from z to " String d;" that is declare in

    Frame1.java.
    >How would I accomplish this?
    >
    >thanks in advance
    >



  3. #3
    alex Guest

    Re: From Frame1.java to Frame2.java?


    I'm still having problems to develop this procedure can you be more especific?
    Thanks

    "Ruchi Dhar" <rdhar@verticalnet.com> wrote:
    >
    >In true object world you need to to have setXX(String xx) method in Frame1.java
    >and while creating Frame2 pass the reference of frame1. When you want to
    >assign the value of z call the setXXX method with z as parameter. In the
    >other world declare the d as public static variable in Frame2 you can assign
    >value by asscssing directly Frame1.d = z;
    >
    >
    >"alex" <cad1374@yahoo.com> wrote:
    >>
    >>If I have a declaration in Frame2.java like this "String z="y";
    >>and I want to pass the value from z to " String d;" that is declare in

    >Frame1.java.
    >>How would I accomplish this?
    >>
    >>thanks in advance
    >>

    >



  4. #4
    thn-d Guest

    Re: From Frame1.java to Frame2.java?


    "alex" <cad1374@yahoo.com> wrote:
    >If I have a declaration in Frame2.java like this "String z="y";
    >and I want to pass the value from z to " String d;" that is declare in

    Frame1.java.
    >How would I accomplish this?


    If Frame1.d and Frame2.z need always to be equal, please consider
    this: make a base class for Frame1 and Frame2 (let's say Frame0)
    that has z as a static property (protected). Then Frame1 and
    Frame2 share the same String z (formerly d in Frame1).
    Here is the code:

    public class Frame0 extends jawa.awt.Frame {
    ...
    protected static String z;
    ...
    }

    class Frame1 extends Frame0 {
    ...
    }

    class Frame2 extends Frame0 {
    ...
    }



  5. #5
    Carl Guest

    Re: From Frame1.java to Frame2.java?


    "thn-d" <thn-d@betasystems.com> wrote:
    >
    >"alex" <cad1374@yahoo.com> wrote:
    >>If I have a declaration in Frame2.java like this "String z="y";
    >>and I want to pass the value from z to " String d;" that is declare in

    >Frame1.java.
    >>How would I accomplish this?



    Do this in a object oriented manner an you won't be sorry.
    *Note: compile each separatly in the same directory.

    // *Frame 2*
    public class Frame2 extends Frame {
    // member variables
    private String z = "y";

    // accessors
    public void setZ( String z ) {
    this.z = z;
    }
    public String getZ() {
    return z;
    }
    }

    // *Frame 1*
    public class Frame1 extends Frame {
    // member variable
    private String d;

    //accessors
    public void setD( String d ) {
    this.d = d;
    }
    public String getD () {
    return d;
    }

    }

    // * MyClass *
    public MyClass {
    // Java application
    public void main ( String [] args) {
    // create 2 frames
    Frame1 frm1 = new Frame1();
    Frame2 frm2 = new Frame2();

    // set the value of 'd' to the value from 'z'
    frm1.setD( frm2.getZ() )
    System.err.println(" The value of frame1's D is : " + frm1.getD() );
    }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center