检测项的类型。在我的计划,我有一个JTextField读取用户输入。用户应该输入一个数字,然后点击一个JButton来确认输入,但是我想要知道如果用户没有输入数字,会弹出一个消息,告诉用户这是一个不正确的输入。如何实现一些东西来检测用户是否在点击JButton时输入数字?如果我需要提供更多代码,请告诉我。读取用户输入和Java中
JButton okay = new JButton("OK");
JTextField dataEntry = new JTextfield();
okay.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
firstEntry = Float.parseFloat(dataEntry.getText());
//want to see if it's a float, if true, run the following code
confirm = true;
changeText();
dataEntry.setText("");
}
});
谢谢你的帮助! – 00101100