📄 goodsfield.java
字号:
import javax.swing.*;//the definition of the fieldpublic class GoodsField extends ItemAttribute { //value of the attribute private String value; //data type public final int INTEGER = 1, FLOATING = 2, STRING = 3; //constrain tag public final boolean CONSTRAIN_TRUE = true, CONSTRAIN_FALSE = false; //constrain type that is every integer maping a type of constrain content public final int KEY = 1, ELSE = 2; public GoodsField () { //default super ( "", 0, 0, true, 0 ); setValue ( null ); } public GoodsField ( String gn, int gt, int gl, boolean gct, int gc, String gv ) { super ( gn, gt, gl, gct, gc ); setValue ( gv ); } //use this Constructor most public GoodsField ( ItemAttribute ga, String gv ) { super ( ga.getName(), ga.getType(), ga.getLength(), ga.getConstrainTag(), ga.getConstrain() ); setValue( gv ); } public void setValue ( String gv ) { //the constrains.Here need to improve if( getConstrainTag() == CONSTRAIN_TRUE ) { switch( getType() ) { case INTEGER: int v1 = Integer.parseInt( gv ); if( !( v1 < 0 ) ) value = gv; else{ value = null; JOptionPane.showMessageDialog( null, "Valid data type of "+getName(), null, JOptionPane.ERROR_MESSAGE ); } break; case FLOATING: double v2 = Double.parseDouble( gv ); if( !( v2 < 0 )) value = gv; else{ value = null; JOptionPane.showMessageDialog( null, "Valid data type of "+getName(), null, JOptionPane.ERROR_MESSAGE ); } break; case STRING: if( getLength() >= gv.length() & gv.length() != 0 ) value = gv; else{ value = null; JOptionPane.showMessageDialog( null, "Valid data length of "+getName(), null, JOptionPane.ERROR_MESSAGE ); } break; default: JOptionPane.showMessageDialog( null, "No such data type",null, JOptionPane.ERROR_MESSAGE ); break; } } else value = gv; } public String getValue () { return value; } public String toString() { String buf = new String(""); buf += getName()+"\t"+getType()+"\t"+getLength()+"\t"+getConstrainTag()+"\t"+getConstrain(); buf += "\t" + getValue(); return buf; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -