• Post Reply Bookmark Topic Watch Topic
  • New Topic

text listeners  RSS feed

 
kelly devon
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i have a gui with a button and two textfields. i used textListener
for the textfield(one of them) so that once i type in a word it will
be read by the text listener and transfer it to the other textfield
then i will click thebutton and get info from the database.
the problem is that i used both listeners but that for the textlistener
keeps giving me an error complining about the textListener that it is
not recognised. this is what i did
public class mygui extends JFrame implements ActonListener, TextListener{
..................
..............
JTextField transtext = new JTextField(10);

public mygui(){
transtext.addTextListener(this);}
}
its only showing the important bits
whats wrong with it pls help
 
Jared Cope
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Did you import the TextListener class from java.awt.event package?

Cheers, Jared.
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JTextField transtext is a swing component and addTextListener is not a method for JTextField

You need the AWT component TextField if you want to use addTextListener method.

Are you required to use AWT? You may want to use Swing instead and use the JTextField with an ActionListener to get the same functionality.
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, ActionListener is mis-spelled as ActonListener in the code you pasted
 
kelly devon
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thx tim for pointing that out. if i use the actionlistener for JTextField
will i still use the public void textValuChanged(TextEvent a) or wat
thx
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!