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
5 Replies - 149 Views - Last Post: 27 December 2012 - 08:38 AM
#1
i can't use label in JFrame to display string in another class
Posted 27 December 2012 - 07:51 AM
Replies To: i can't use label in JFrame to display string in another class
#2
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.
#3
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
proses.java
first melankolis in form java is label
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
#4
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.
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.
#5
Re: i can't use label in JFrame to display string in another class
Posted 27 December 2012 - 08:37 AM
thanks GragBrannon
#6
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.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|