JTextField Problem

Discussion in 'Java' started by Katie Moore, Dec 1, 2003.

  1. Katie Moore

    Katie Moore Guest

    Hi,

    I was using a JTextField originally but I can not get the information from
    the text field. What I would like to happen is get the information from a
    textfield once a "Send" button is pressed. This is my action handler and
    listener. However it always sets Topuc to null. Any suggestions?

    JTextField topicField=new JTextField();
    topicField.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    JTextField tfTopic = (JTextField)e.getSource();
    Topic = (String)tfTopic.getText();
    }
    });
    topicField.setText("");
     
    Katie Moore, Dec 1, 2003
    #1
    1. Advertising

  2. Katie Moore

    Harald Hein Guest

    "Katie Moore" wrote:

    > I was using a JTextField originally but I can not get the
    > information from the text field. What I would like to happen is
    > get the information from a textfield once a "Send" button is
    > pressed. This is my action handler and listener. However it
    > always sets Topuc to null. Any suggestions?
    >
    > JTextField topicField=new JTextField();
    > topicField.addActionListener(new ActionListener()
    > {


    Why do you listen to events on the JTextField, when you want to react
    on the event that someone has pressed the "Send" button? Implement a
    listener for the "Send" button, and in that listener you use

    topicField.getText();
     
    Harald Hein, Dec 1, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter

    JTextField JPassword

    Peter, Jul 11, 2003, in forum: Java
    Replies:
    0
    Views:
    3,329
    Peter
    Jul 11, 2003
  2. Matthew Bailey

    JTextField.requestFocus problem

    Matthew Bailey, Jul 6, 2004, in forum: Java
    Replies:
    4
    Views:
    8,077
    Matthew Bailey
    Jul 8, 2004
  3. blue
    Replies:
    1
    Views:
    1,217
    Babu Kalakrishnan
    Dec 11, 2004
  4. Badshah

    JTextField Unicode Problem

    Badshah, Jan 29, 2007, in forum: Java
    Replies:
    0
    Views:
    390
    Badshah
    Jan 29, 2007
  5. Badshah

    JTextField Unicode Problem

    Badshah, Jan 29, 2007, in forum: Java
    Replies:
    2
    Views:
    1,209
    Badshah
    Jan 30, 2007
Loading...

Share This Page