ImageIcon leftButtonIcon = new ImageIcon("images/right.gif");
ImageIcon middleButtonIcon = new ImageIcon("images/middle.gif");
ImageIcon rightButtonIcon = new ImageIcon("images/left.gif");
b1 = new JButton("Disable middle button", leftButtonIcon);
b1.setVerticalTextPosition(AbstractButton.CENTER);/**设置垂直文本位置*/
b1.setHorizontalTextPosition(AbstractButton.LEFT);/**设置水平文本位置*/
b1.setMnemonic(KeyEvent.VK_D);/**加一个键盘上的快捷键*/
b1.setActionCommand("disable");/**Sets the command name for the action event fired by this button.
By default this action command is set to match the label of the button*/
b2 = new JButton("Middle button", middleButtonIcon);
b2.setVerticalTextPosition(AbstractButton.BOTTOM);
b2.setHorizontalTextPosition(AbstractButton.CENTER);
b2.setMnemonic(KeyEvent.VK_M);
b3 = new JButton("Enable middle button", rightButtonIcon);
//Use the default text position of CENTER, RIGHT.
b3.setMnemonic(KeyEvent.VK_E);
b3.setActionCommand("enable");
b3.setEnabled(false);/**Sets the enabled state of the object,
if true, enables this object; otherwise, disables it*/
//Listen for actions on buttons 1 and 3.
b1.addActionListener(this)
ImageIcon leftButtonIcon = new ImageIcon("images/right.gif");
ImageIcon middleButtonIcon = new ImageIcon("images/middle.gif");
ImageIcon rightButtonIcon = new ImageIcon("images/left.gif");
b1 = new JButton("Disable middle button", leftButtonIcon);
b1.setVerticalTextPosition(AbstractButton.CENTER);/**设置垂直文本位置*/
b1.setHorizontalTextPosition(AbstractButton.LEFT);/**设置水平文本位置*/
b1.setMnemonic(KeyEvent.VK_D);/**加一个键盘上的快捷键*/
b1.setActionCommand("disable");/**Sets the command name for the action event fired by this button.
By default this action command is set to match the label of the button*/
b2 = new JButton("Middle button", middleButtonIcon);
b2.setVerticalTextPosition(AbstractButton.BOTTOM);
b2.setHorizontalTextPosition(AbstractButton.CENTER);
b2.setMnemonic(KeyEvent.VK_M);
b3 = new JButton("Enable middle button", rightButtonIcon);
//Use the default text position of CENTER, RIGHT.
b3.setMnemonic(KeyEvent.VK_E);
b3.setActionCommand("enable");
b3.setEnabled(false);/**Sets the enabled state of the object,
if true, enables this object; otherwise, disables it*/
//Listen for actions on buttons 1 and 3.
b1.addActionListener(this)