5 Replies - 457 Views - Last Post: 27 December 2012 - 08:38 AM Rate Topic: -----

#1 danielistyo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-December 12

i can't use label in JFrame to display string in another class

Posted 27 December 2012 - 07:51 AM

who knows ? why i can't use label in JFrame to display string in another java file ?

first file java class (class1):

String [] a = new String(2);
a[0]="ZZz";

second file java class(JFrame) :

i use label. its variabel name is label1
class1 b = new class1();
label.setText(b.a[0]);

when i run my JFrame, the label is blank display. please help.. thanks
Is This A Good Question/Topic? 0
  • +

Replies To: i can't use label in JFrame to display string in another class

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2204
  • View blog
  • Posts: 5,236
  • Joined: 10-September 10

Re: i can't use label in JFrame to display string in another class

Posted 27 December 2012 - 07:55 AM

It's hard to help without seeing your code.
Was This Post Helpful? 0
  • +
  • -

#3 danielistyo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-December 12

Re: i can't use label in JFrame to display string in another class

Posted 27 December 2012 - 08:16 AM

This is part of the coding :


form.java

public class form extends javax.swing.JFrame {
    proses a = new proses();
    private void melankolisActionPerformed(java.awt.event.ActionEvent evt) {
        melankolis.setText(a.melankolis[i]);
    }  
}


proses.java

public class proses {
    public String[] melankolis = new String[20];

    public void data() {
        melankolis[18]="Memerlukan banyak waktu pribadi dan cenderung menghindari orang lain.";
    }
}


first melankolis in form java is label

This post has been edited by smohd: 27 December 2012 - 08:31 AM
Reason for edit:: use code tags when posting code

Was This Post Helpful? 0
  • +
  • -

#4 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2204
  • View blog
  • Posts: 5,236
  • Joined: 10-September 10

Re: i can't use label in JFrame to display string in another class

Posted 27 December 2012 - 08:23 AM

Do you add the actionListener to the desired component to cause the JLabel's text to change?

You also mentioned that the JLabel is blank on startup - when you initially run the application. You should set the initial text desired in the JLabel using the setText() method.

From there, the actionListener can change the text in the JLabel by using the same method.
Was This Post Helpful? 1
  • +
  • -

#5 danielistyo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-December 12

Re: i can't use label in JFrame to display string in another class

Posted 27 December 2012 - 08:37 AM

thanks GragBrannon :)
Was This Post Helpful? 0
  • +
  • -

#6 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2204
  • View blog
  • Posts: 5,236
  • Joined: 10-September 10

Re: i can't use label in JFrame to display string in another class

Posted 27 December 2012 - 08:38 AM

You're welcome. Glad to help.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1