字符串验证
LovoButton addBtn = new LovoButton("添加", 100, 240, this);
addBtn.addActionListener(newActionListener() {
publicvoid actionPerformed(ActionEvent e) {
Stringmsg = "";
if(!codeTxt.getText().matches("\\d+")){
msg += "编号必须为数字\n";
}
if(!nameTxt.getText().matches("[a-zA-Z\\u4e00-\\u9fa5]{2,}")){
msg += "商品名必须为汉字或者字母\n";
}
if(msg.length()!= 0){
JOptionPane.showMessageDialog(null,msg);
return;
}
add(); //下一步操作
}
});