Tawi Oei wrote:The JTextField's class is different from the JLabel, how to do that?
K. Tsang CEng MBCS PMP PMI-ACP OCMJEA OCPJP
K. Tsang wrote:
Tawi Oei wrote:The JTextField's class is different from the JLabel, how to do that?
Of course a JTextField is different from a JLabel.
For your question... first you need to get the user input from the JTextField then create the JLabel.
Michael Dunn wrote:is this the same problem as in your other thread?
https://coderanch.com/t/602226/java/java/setText
if so, you need to pass a reference of the class or class label when creating the class with the textfield
here's a very simple demo (would be better with 'setters', but simpler like this)
run it, click the button, change the textfield's text, click the button again
K. Tsang CEng MBCS PMP PMI-ACP OCMJEA OCPJP
Tawi Oei wrote:The JTextField's class is different from the JLabel, how to do that?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Michael Dunn wrote:> I want to put the user's input in JTextField in class A as a JLabel's label and the JLabel is in B class, how to do that?
in my demo I have the textfield in B() and the label in A(), and you want to know how to do it so that
the textfield is in A() and the label in B() - you can't be serious.
K. Tsang wrote:
Michael Dunn wrote:> I want to put the user's input in JTextField in class A as a JLabel's label and the JLabel is in B class, how to do that?
in my demo I have the textfield in B() and the label in A(), and you want to know how to do it so that
the textfield is in A() and the label in B() - you can't be serious.
Your example just have the class reversed. But I don't think that's what the OP want.
Tawi Oei wrote:
Yes, you don't understand the thing that I want. I want to access the user's input at JTextField tf in B class so the label of a JLabel in A class will be the same with user's input in tf, how to do that?
98 errors
Press any key to continue...
Tawi Oei wrote:
Here are the error messages:
Error Messages:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at programtesisbaru.FrameBaru.<init>(ProgramTesisBaru.java:636)
at programtesisbaru.ProgramTesisBaru$1.kontinu(ProgramTesisBaru.java:123)
at programtesisbaru.ProgramTesisBaru$1.actionPerformed(ProgramTesisBaru.java:120)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
BUILD SUCCESSFUL (total time: 14 minutes 57 seconds)
So what shold I do?
Tawi Oei wrote:What objects do you thing are null? What kind of change do you think I have to do to the codes? Why are they null? Can you expain in details? Will I need to call an exception if the user makes no input to every available JTextField?
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Tawi Oei wrote:If you see line 123, you will be able to see that I try to access the JTextField with this technique because I cannot access the JTextField directly from FrameBaru class. Later, I assign the value of the JTextField to lblKriteria1 so lblKriteria1 is not null, I create the lblKriteria1 before. Please see line 603. If that technique is wrong, what technique will be a correct technique?
Get meta with me! What pursues us is our own obsessions! But not this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|