简体   繁体   中英

i can't change label text from different classes

I added two labels ,jLabel1 and jLabel2 to main frame, and I created one class with the name of language.java now am trying to change the text of these two labels, jLabel1 and jLabel2 from this class language.java but its giving error. here is the my code

public class lang {

    void urdu(){
        jLabel.setText="udru1";    
        jLabe2.setText="udru2";       
    }
 }

Modify your class, add data members to place your labels there, add a modify method with parameters will be better. Additionally, ths setText is a method with String parameter that will be used to change the label's text. So it'll be something like this

public class lang {
    private jLabel lbl1;
    private jLabel lbl2;
    public lang(jLabel lbl1, jLabel lbl2){
        this.lbl1 = lbl1;
        this.lbl2 = lbl2;
    }

    public void urdu(){
        lbl1.setText("udru1");    
        lbl2.setText("udru2");       
    }
    //modify method
    public void modify(String txtLabel1, String txtLabel2){
        lbl1.setText(txtLabel1);
        lbl2.setText(txtLabel2);
    }
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM