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
Printable View
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
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
>
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
>>
>
"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 {
...
}
"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() );
}
}