I have the following class that draws a Label. (I have only given part of the code here). Everyhting works fine, the label gets displayed.
Now, i have another class called Caller
Class. I have a method in that where i will use to change the value of this label. how can i do that
public class MyClass{
private JLabel label;
MyClass(){
run();
}
public void editTheLabelsValue (String text) {
label.setText(text);
frame.repaint();
}
run(){
.... // there were more code here, i removed it as it's not relevant to the problem
label = new JLabel("Whooo");
label.setBounds(0, 0, 50, 100);
frame.getContentPane().add(label);
.....
}
later on, i will be using the following class to change the text of the above label. How can i do this.
public class Caller {
void methodA(){
MyClass mc = new MyClass();
mc.editTheLabelsValue("Hello");
}
}
1.) When the methodA() is executed, the text Hello
is not getting displayed on the Label field. it still remains as Whooo
. How can i correct this. I want the label text to be Hello
once that method has been executed.