如何在java swing中验证。 [英] How to validate in java swing.

查看:109
本文介绍了如何在java swing中验证。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Java Swing应用程序。



应用程序以一个表单结束,以获取客户的输入信息(姓名,姓氏,电子邮件,性别等) )



我试图以一种方式验证文本字段,当应用程序启动时,焦点将放在第一个文本框(名字)上。我希望用户在输入有效名称(没有数字,标点符号等)之前无法离开包装盒。



不幸的是,即使在线查看之后,我无法找到验证这些盒子的解决方案。



行动计划:



焦点在第一个文本字段>>>除非输入有效输入,否则无法离开>>输出给用户的消息>>验证完成>>焦点设置在下一个字段>>等等。



帮助将不胜感激。



我的尝试:



i已经尝试过焦点丢失的监听器来处理它但是不能成功。

解决方案

如何编写焦点监听器(Java™教程>使用JFC / Swing创建GUI> ;编写事件监听器) [ ^ ]

I am developing a Java Swing Application.

The application ends with a form to take the customer's input information (name, last name, email, gender, etc)

I am trying to validate the text fields in a way that when the application is launched focus will go on the first text box (first name). I want the user to not be able to leave the box until they have entered a valid name (no numbers, punctuation and so on).

Unfortunately even after looking online, I am not able to find a solution to validating these boxes.

Action Plan:

Focus on first textfield >>> Unable to leave unless valid input is entered >> messages outputted to user >> validation completed >> focus set on next field >> and so on.

Help would be appreciated.

What I have tried:

i have tried focus lost listener to deal with it but could't succeed.

解决方案

How to Write a Focus Listener (The Java™ Tutorials > Creating a GUI With JFC/Swing > Writing Event Listeners)[^]


这篇关于如何在java swing中验证。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆