Results 1 to 3 of 3
  1. #1
    raffs03 is offline Member
    Join Date
    Sep 2012
    Posts
    41
    Rep Power
    0

    Talking [SOLVED]How to put JTextField input into JLabel?

    Java 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);
                }
            });
    I get a NullPointerExceptionError at this line
    Java Code:
    Lbl17 = new JLabel("Student#: "+Txt3.getText());//on Visual5 Frame
    Can Someone Give me a sample code on how to do this?? i try the parse method but other runtime error will occur.
    Last edited by raffs03; 02-19-2013 at 11:04 AM.

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default 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)

  3. #3
    raffs03 is offline Member
    Join Date
    Sep 2012
    Posts
    41
    Rep Power
    0

Similar Threads

  1. problem with combining JFrame+JLabel+JTextField
    By Mapisto in forum New To Java
    Replies: 4
    Last Post: 03-31-2012, 09:02 PM
  2. input from JTextField
    By Willriker in forum New To Java
    Replies: 13
    Last Post: 08-14-2011, 02:17 AM
  3. Allow only numerical input on JTextField
    By patriotsfan in forum AWT / Swing
    Replies: 3
    Last Post: 05-31-2011, 12:39 PM
  4. JLabel/JTextfield Animation
    By weikang in forum AWT / Swing
    Replies: 1
    Last Post: 01-05-2011, 02:55 PM
  5. Constraining Input in JTextField
    By kataya in forum AWT / Swing
    Replies: 1
    Last Post: 06-26-2008, 06:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •