import java.awt.Insets; import javax.swing.JButton; import javax.swing.SwingConstants; public class ButtonBase extends JButton ... { private JButton button = new JButton(); private String strButtonType = null; private String[] strBT = ...{"add","del"}; private String[] strImageUrl = ...{"images/pay/add.gif","images/common/delete.gif"}; public ButtonBase(String buttonName,String strButtonType)...{ button.setText(buttonName); this.strButtonType = strButtonType; initButton(); selectImage(this.strButtonType); } /** *//**初始化button。*/ private void initButton()...{ button.setHorizontalAlignment(SwingConstants.CENTER); button.setHorizontalTextPosition(SwingConstants.CENTER); button.setVerticalAlignment(SwingConstants.CENTER); button.setVerticalTextPosition(SwingConstants.BOTTOM); button.setIconTextGap(0); button.setMargin(new Insets(1, 5, 0, 5)); } /** *//**选择button图片*/ private void selectImage(String strButtonType)...{ for(int i=0;i<strBT.length;i++)...{ if(strBT[i].equals(strButtonType))...{ button.setIcon(Resource.getImage(strImageUrl[i])); } } } /** *//**返回配制好的button。*/ public JButton getButton()...{ return button; }} 上面是相关类,下面是调用方法 private JButton buttonAdd = new ButtonBase( " 增加 " , " add " ).getButton(); private JButton buttonUpdate = new ButtonBase( " 修改 " , " modify " ).getButton();