+ 3
How I can switch data between two frames in java?
6 ответов
+ 6
you mean get value from Jframe to another :
frame2 f2 = new frame2();
f2.value2.setText(frame1.value1.getText());
f2.setVisible(true);
ps: the values should be "public static"
+ 5
If you don't want to use the public modifier you should use the getter and setter methods to access your variable from another class.
For example
class MyFrame extends JFrame {
private int value = 777;
//Some operations
...
public void setValue(int v) {
value=v;
}
public int getValue() {
return value;
}
}
You can do this with all variables you want.
PS: The method of Med Imed-Eddine Boucenda is right, but the static modifier is not necessary in his method.
+ 1
ok Thanks
but how can I handle it if I don't want to make the values public ,?
+ 1
can I handle it about a second class ?
0
@FreakManMega
I do not understand your example
0
in a Dialog Form I set the variable in the class and when I want to use the variable in my Main Form I have to create a new object of this class and then the variable is null