Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Handling TextExevents plsssssss

Status
Not open for further replies.

Nandito

Programmer
Apr 12, 2000
31
0
0
AU
Visit site
Hello Javanauts..<br><br>I have an applet that takes values from textfields and by pressing a button it does some calculations.<br>However I wanted to know how would I use without a button.<br>Ie put values in the textfield and listen the textfields for the values.<br><br>I tried to use the TextListener but I get an error <br><br>ie: atextField.addTextField(this);<br>&nbsp;&nbsp;&nbsp;<br>public void textValueChanged(TextEvent ev)<br>{ Object ob = ev.getSource();<br>&nbsp;&nbsp;if (ob == atextField)<br>&nbsp;&nbsp;&nbsp;{ TakeTheValue();<br>&nbsp;&nbsp;&nbsp;}<br>&nbsp;}<br><br>
 
Maybe you should write: atextField.addTextListener(this)<br><br>Bye, Otto.<br>
 
Yess sorry I did that...I miss-typed the question it was meant to be<br>atexField.addTextListener(this);<br><br>but still am getting the error...
 
Error message?<br><br>Guess #2 :)):<br><br>This little example may will help you:<br><br>import java.awt.*;<br>import java.applet.Applet;<br>import java.awt.event.*;<br><br>public class TextEventExample extends Applet implements TextListener {<br>&nbsp;&nbsp;TextField tf;<br>&nbsp;&nbsp;Label l;<br><br>&nbsp;&nbsp;public void init() {<br>&nbsp;&nbsp;&nbsp;&nbsp;setLayout(new BorderLayout());<br>&nbsp;&nbsp;&nbsp;&nbsp;tf=new TextField(80);<br>&nbsp;&nbsp;&nbsp;&nbsp;tf.addTextListener(this);<br>&nbsp;&nbsp;&nbsp;&nbsp;l=new Label(&quot;&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;add(&quot;North&quot;, tf);<br>&nbsp;&nbsp;&nbsp;&nbsp;add(&quot;Center&quot;, l);<br>&nbsp;&nbsp;&nbsp;&nbsp;tf.requestFocus();<br>&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;public void textValueChanged(TextEvent e) {<br>&nbsp;&nbsp;&nbsp;&nbsp;if (e.getSource()==tf) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;l.setText(tf.getText());<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;}<br>}<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top