public void setHorizontalScrollBarPolicy(int policy) {
switch (policy) {
case HORIZONTAL_SCROLLBAR_AS_NEEDED:
case HORIZONTAL_SCROLLBAR_NEVER:
case HORIZONTAL_SCROLLBAR_ALWAYS:
break;
default:
throw new IllegalArgumentException("invalid horizontalScrollBarPolicy");
}
int old = horizontalScrollBarPolicy;
horizontalScrollBarPolicy = policy;
firePropertyChange("horizontalScrollBarPolicy", old, policy);
revalidate();
repaint();
}
个人认为不错的代码结构:利用switch case语句进行参数的取值校验
最新推荐文章于 2022-03-24 08:35:32 发布