📄 componentvalidator.java
字号:
package net.sf.fmj.ui.objeditor;import javax.swing.JComboBox;import javax.swing.JLabel;import javax.swing.JTextField;/** * * @author Ken Larson * */public class ComponentValidator { public void validateNotEmpty(JTextField f, JLabel label) throws ComponentValidationException { final String s = f.getText(); if (s == null || s.equals("")) throw new ComponentValidationException(f, buildMessage(label.getText(), "may not be empty")); } public void validateNotEmpty(JComboBox c, JLabel label) throws ComponentValidationException { final Object o = c.getSelectedItem(); final String s = o == null ? null : o.toString(); if (s == null || s.equals("")) throw new ComponentValidationException(c, buildMessage(label.getText(), "may not be empty")); } public void validateInteger(JComboBox c, JLabel label) throws ComponentValidationException { final Object o = c.getSelectedItem(); final String s = o == null ? null : o.toString(); try { Integer.parseInt(s); } catch (NumberFormatException e) { throw new ComponentValidationException(c, buildMessage(label.getText(), "not a valid number")); } } public void validateInteger(JTextField f, JLabel label) throws ComponentValidationException { final String s = f.getText(); try { Integer.parseInt(s); } catch (NumberFormatException e) { throw new ComponentValidationException(f, buildMessage(label.getText(), "not a valid number")); } } private static String buildMessage(String label, String msg) { if (label == null || label.equals("")) return msg; if (label.endsWith(":")) return label + " " + msg; else return label + ": " + msg; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -