rohit arora
rohit arora

Reputation: 105

how to get the value of JLabel in some other class

I set the value of JLabel in class1

 NewLabel.setText("xyz");

I can read the value of Jlabel using

 NewLabel.getText();

and now I want to know How to Get the value of JLabel in Class2 using button click

   public void actionPerformed(ActionEvent arg0){}

Upvotes: 1

Views: 6785

Answers (1)

InsaneCoder
InsaneCoder

Reputation: 8268

In class 1 create a method that returns the text of NewLabel (you can do this by putting the NewLabel's text in a String object,say str,and then return str).

Now in class 2 ,create an object of class 1,(e.g. Class1 cl1=new Class1();).Now simply call that method you created in class 1(e.g.,cl1.getNewLabelText()) .getNewLabelText() is a sample name you can give to your method created for class 1.

Upvotes: 2

Related Questions