C 怎么用onkeypress(JAVA 判断字符串是否由(0-9,A-Z,a-z)组成)

2023-12-31 14:20:02 :86

c 怎么用onkeypress(JAVA 判断字符串是否由(0-9,A-Z,a-z)组成)

大家好,今天小编来为大家解答以下的问题,关于c 怎么用onkeypress,JAVA 判断字符串是否由(0-9,A-Z,a-z)组成这个很多人还不知道,现在让我们一起来看看吧!

本文目录

JAVA 判断字符串是否由(0-9,A-Z,a-z)组成

((c》=’0’ && c《=’9’) || (c》=’A’ && c《=’Z’) || (c》=’a’ && c《=’z’))这是最简单的写法了。

键盘监听,文本框之内 只允许输入1-99之间数字,怎么写呀

import java.awt.event.*;import java.awt.*;import javax.swing.*;import javax.swing.text.*;class CustomedDocument extends PlainDocument { private int limit; public CustomedDocument (int limit) { super(); this.limit = limit; } public void insertString (int offset, String str, AttributeSet attr) throws BadLocationException { if (this.getLength() + str.length() 》 limit) return; char charArray = str.toCharArray(); for (char c : charArray) if ((this.getLength() == 0 && c 《 ’1’) || (this.getLength() != 0 && c 《 ’0’) || c 》 ’9’) return; super.insertString(offset, str, attr); }}public class Demo { private JFrame mainFrame; private JTextField txtInput; public Demo () { Toolkit tk = Toolkit.getDefaultToolkit(); Dimension dms = tk.getScreenSize(); Font f = new Font("Arial", Font.PLAIN, 13); mainFrame = new JFrame("Demo"); mainFrame.setLayout(null); mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainFrame.setBounds((int)dms.getWidth()/2-95, (int)dms.getHeight()/2-50, 190, 73); txtInput = new JTextField(); txtInput.setBounds(5, 5, 165, 25); txtInput.setFont(f); txtInput.setDocument(new CustomedDocument(2)); mainFrame.add(txtInput); mainFrame.setVisible(true); } public static void main (String args) throws InstantiationException, ClassNotFoundException, IllegalAccessException, UnsupportedLookAndFeelException { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); new Demo(); }}

Delphi调用onkeypress

sender就是edit本身,所以你写edit1就可以了第二个key 要传地址,所以不能用常量#13,你定义一个char类型c:=#13.然后txt1KeyPress(txt1,c);保你管用

文章分享结束,c 怎么用onkeypress和JAVA 判断字符串是否由(0-9,A-Z,a-z)组成的答案你都知道了吗?欢迎再次光临本站哦!

c 怎么用onkeypress(JAVA 判断字符串是否由(0-9,A-Z,a-z)组成)

本文编辑:admin
Copyright © 2022 All Rights Reserved 威海上格软件有限公司 版权所有

鲁ICP备20007704号

Thanks for visiting my site.