不懂的代码可看同栏目的文章,全部都有
import java.awt.event.*;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class cs extends JFrame implements ActionListener{
private JTextField JT;
public cs() {
JButton JB=new JButton("登录");
JB.setBounds(100,100,100,50);
this.setDefaultCloseOperation(3);
this.setSize(500,500);
this.setLocationRelativeTo(null);
JT=new JTextField(10);
JT.setBounds(100,100,100,100);
JPanel JP=new JPanel();
JP.setBounds(100,100,100,100);
this.setLocale(null);
JP.add(JT);
JP.add(JB);
this.setVisible(true);
this.add(JP);
JB.addActionListener(this);
}
public static void main(String[] args) {
new cs();
}
@Override
public void actionPerformed(ActionEvent e) {
char aa[] = JT.getText().toCharArray();
for (int i = 0; i < aa.length; i++) {
if (!Character.isDigit(aa[i])) {
JOptionPane.showMessageDialog(null, "请输入的帐号必须为数字!!");
return;
}
}
}
}