Results 1 to 3 of 3
- 02-19-2013, 05:14 AM #1
Member
- Join Date
- Sep 2012
- Posts
- 26
- Rep Power
- 0
[SOLVED]How to put JTextField input into JLabel?
I get a NullPointerExceptionError at this lineJava Code:public class Trypack { public Trypack(){ final JFrame Visual3 = new JFrame(); final JFrame Visual5 = new JFrame(); Btn5 = new JButton("Save"); Lbl3 = new JLabel("Student #: ");//on Visual3 Frame Lbl17 = new JLabel("Student#: "+Txt3.getText());//on Visual5 Frame Txt3 = new JTextField(); Visual3.add(Lbl3); Visual3.add(Txt3); Visual3.add(Btn5); Visual5.add(Lbl17); Btn5.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { Visual5.show(); Visual3.show(false); } });
Can Someone Give me a sample code on how to do this?? i try the parse method but other runtime error will occur.Java Code:Lbl17 = new JLabel("Student#: "+Txt3.getText());//on Visual5 FrameLast edited by raffs03; 02-19-2013 at 11:04 AM.
- 02-19-2013, 07:18 AM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
Re: How to put JTextField input into JLabel?
The Txt3 field is not initialized at this point (you initialize the textfield after the jlabel, so you will get this NPE).
But I think, you have to put the code into the actionPerformed method (with setText)
- 02-19-2013, 11:04 AM #3
Member
- Join Date
- Sep 2012
- Posts
- 26
- Rep Power
- 0
Similar Threads
-
problem with combining JFrame+JLabel+JTextField
By Mapisto in forum New To JavaReplies: 4Last Post: 03-31-2012, 09:02 PM -
input from JTextField
By Willriker in forum New To JavaReplies: 13Last Post: 08-14-2011, 02:17 AM -
Allow only numerical input on JTextField
By patriotsfan in forum AWT / SwingReplies: 3Last Post: 05-31-2011, 12:39 PM -
JLabel/JTextfield Animation
By weikang in forum AWT / SwingReplies: 1Last Post: 01-05-2011, 02:55 PM -
Constraining Input in JTextField
By kataya in forum AWT / SwingReplies: 1Last Post: 06-26-2008, 06:25 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks