Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Restricting input type on a JTextField

807597Feb 1 2005 — edited Feb 2 2005
Hi all.

I've setup an actionistener on some JTextFields so that I can perform mathematical calculations on them. Basically, how do I stop text being actioned?

What I would like is that if the user enters text, then do nothing.

My code for the action listener is:
public void actionPerformed(ActionEvent event)
{
String string1 = text1.getText(); //Assign value of textbox to the string
int counter = Integer.parseInt( string1 ); //Convert to integer
.
.
.
.
}
Is there some way of saying if Text1 = texttype then do nothing? i.e. dont try and calculate?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 2 2005
Added on Feb 1 2005
3 comments
418 views