JTextField Problem

K

Katie Moore

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("");
 
H

Harald Hein

Katie Moore said:
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();
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top