okay..could someone tell me how to check if someone put in a float value in a text field. and if not how can i generate a dialogue box with an error. This is how it looks

marks1 = Float.parseFloat(tf1.getText().trim());

i stored the contents of the textfield into marks1. How can i do it?

you can put that in a try-catch block. if it fails getting a float it will execute the code in catch block

Hi member,

You can surely check whether someone has entered float value in textfield or not.

1. add key listener to the textfield and show an error message whenever "." is pressed. Joptionpane.showmessagedialog() can be used for printing dialog box error message.

2. Instead of storing the content in marks1 you can check the same using the above mentioned concept.

regards
realnapster

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.