package yuekun1;
import javax.swing.UIManager;
import java.awt.*;
import scope.*;
import javax.swing.UIManager;
import java.awt.*;
public class VerifyPro {
  private boolean packFrame = false;
  //构造方法
  public VerifyPro() {
    VarifyFrame frame = new VarifyFrame();
    //使窗口居中显示
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = frame.getSize();
    frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
    //显示窗口
    frame.setVisible(true);
  }
  //主方法
  public static void main(String[] args) {
    try {
     UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
   }
   catch(Exception e) {
     e.printStackTrace();
   }
    new VerifyPro();
  }
}
----------------------------------
package scope;
import java.text.DateFormat;
public class VerifyMethod {
  /**该方法是字符串合法性检验,如果输入的值是数字,返回false,输入的值是文字,返回值是true*/
    public boolean onlyString(String input){
      //引入导常处常语句,尝试转换输入字符串,如果转换成功,那么输入的信息是数字,否则是文字
      try{
        Double.parseDouble(input);
      }catch(Exception e){//当输入的信息不是全部都是数字的执行代码
        if(input.length() <= 5) //当长度小于等于5时通过检验
          return true;
        else                    //当长度大于5时不能通过检验
          return false;
      }
      return false;
    }
    /**该方法是数字的合法性检验*/
    public boolean onlyNumber(String input){
      try{
        Double.parseDouble(input);
      }catch(Exception e){
        return false;
      }
      return true;
    }
    /**该方法是数字范围的合法性检验*/
    public boolean ageScope(String input) {
      double age;
      try{
        age = Double.parseDouble(input);
      }catch(Exception e){
        return false;
      }
      //数字范围在18至60的返回值是true
      if((age >= 18) && (age < 60))
        return true;
      else
        return false;
    }
    /**该方法是日期变量的合法性检验*/
    public boolean onlyDate(String input){
      DateFormat dateFormat = DateFormat.getDateInstance();
      try{
        dateFormat.parse(input);
      }catch(Exception e){
        return false;
      }
      return true;
    }
}
-----------------------------
package yuekun1;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import scope.*;
public class VarifyFrame extends JFrame {
  private JPanel contentPane;
  private JLabel nameLabel = new JLabel();
  private JLabel idLabel = new JLabel();
  private JLabel ageLabel = new JLabel();
  private JTextField nameTextField = new JTextField();
  private JTextField idTextField = new JTextField();
  private JTextField ageTextField = new JTextField();
  private JButton submitBtn = new JButton();
  private JButton exitBtn = new JButton();
  //创建字符检验方法类
  VerifyMethod verifyMethod = new VerifyMethod();
  //创建3个变量,用于保存3个编辑框的值
  String name, id, age;
  /**构造方法*/
  public VarifyFrame() {
    try {jbInit();}catch(Exception e) {e.printStackTrace();}
  }
  /**窗口初始化代码*/
  private void jbInit() throws Exception  {
    //取得面板容器,设置面板容器的布局,大小与窗口的标题
    contentPane = (JPanel) this.getContentPane();
    contentPane.setLayout(null);    //任意位置布局
    this.setSize(new Dimension(400, 300));
    this.setTitle("新员工信息输入窗口");
    //设置标签的标题,位置与大小
    nameLabel.setText("新员工的名字:");
    nameLabel.setBounds(new Rectangle(32, 40, 93, 14));
    idLabel.setText("新员工的身份证号:");
    idLabel.setBounds(new Rectangle(32, 86, 112, 14));
    ageLabel.setText("新员工的年龄:");
    ageLabel.setBounds(new Rectangle(32, 136, 112, 14));
    //设置编辑框的位置与大小
    nameTextField.setBounds(new Rectangle(170, 28, 196, 32));
    idTextField.setBounds(new Rectangle(170, 77, 196, 32));
    ageTextField.setBounds(new Rectangle(170, 127, 196, 32));
    //设置按钮的标题,位置,大小与加入动作接收器
    submitBtn.setText("提交");
    submitBtn.setBounds(new Rectangle(28, 208, 123, 37));
    submitBtn.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        submitBtn_actionPerformed(e);
      }
    });
    exitBtn.setText("退出");
    exitBtn.setBounds(new Rectangle(236, 204, 130, 42));
    exitBtn.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        exitBtn_actionPerformed(e);
      }
    });
    //向容器加入各个控件
    contentPane.add(nameLabel, null);
    contentPane.add(idLabel, null);
    contentPane.add(ageLabel, null);
    contentPane.add(nameTextField, null);
    contentPane.add(idTextField, null);
    contentPane.add(ageTextField, null);
    contentPane.add(submitBtn, null);
    contentPane.add(exitBtn, null);
  }
  /**退出窗口时清空内存*/
  protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
      System.exit(0);
    }
  }
  /**退出按钮的外理代码*/
  void exitBtn_actionPerformed(ActionEvent e) {
    System.exit(0);
  }
  /**提交按钮的处理代码*/
  void submitBtn_actionPerformed(ActionEvent e) {
    //重新获得编辑框的值
    upDateInfor();
    String resStr = "";
    //检验名字的输入是否符合标准
    if(!verifyMethod.onlyString(name)){
      resStr = resStr + " 名字不能输入数字,长度应该小于5 ";
    }
    //检验身份证号码的输入是否符合标准
    if(!verifyMethod.onlyNumber(id)){
      resStr = resStr + " 身份证号码不能输入字符 ";
    }
    //检验年龄的输入是否符合标准
    if(!verifyMethod.ageScope(age)){
      resStr = resStr + " 年龄的输入范围是18至60 ";
    }
    //如果全部符合标准,显示员工信息
    if(verifyMethod.onlyString(name) && verifyMethod.onlyNumber(id) &&
                     verifyMethod.ageScope(age)){
      JOptionPane.showMessageDialog(null,"新员工的名字是" + name +
                      " 新员工的年龄是" + age + " 新员工的身份证号码是" + id);
    //如果其中一项不符合标准,显示错误信息
    }else{
      JOptionPane.showMessageDialog(null,resStr);
    }
  }
  /**重新取得3个编辑框的字符串的方法*/
  void upDateInfor(){
    name = nameTextField.getText();
    id = idTextField.getText();
    age = ageTextField.getText();
  }
}
这三个文件一个是appliaction 一个是frame 一个是method
但是运行之后说main函数有异常 ,不运行的时候没错误显示,只是运行以后出错



 
											





 
	    

 
	