📄 right7_2_3_9.htm
字号:
<html><head><title>JAVA编程语言</title><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><link rel="stylesheet" href="../../../css/text.css" type="text/css"></head><body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" ><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF"> <tr> <td valign="top"> <table width="97%" border="0" cellspacing="0" cellpadding="0" align="center" bgcolor="#FFFFFF"> <tr> <td height="244" valign="top"> <p> <span class="pt9-black"> 按钮是一个常用组件,按钮可以带标签或图象。 <br> <br> java.lang.Object<br> |<br> +--java.awt.Component<br> |<br> +--java.awt.Container<br> |<br> +--javax.swing.JComponent<br> |<br> +--javax.swing.AbstractButton<br> |<br> +--javax.swing.JButton<br> <br> 常用的构造方法有:<br> JButton(Icon icon) <font color="339900">//按钮上显示图标</font><br> JButton(String text) <font color="339900">//按钮上显示字符</font><br> JButton(String text, Icon icon) <font color="339900">//按钮上既显示图标又显示字符</font></span></p> <p class="pt9-black"><img src="../../../images/html/liti.gif" width="38" height="38" align="absbottom" title="例题"> <font color="000099">例7.2</font><br> public class ButtonDemo extends Jpanel implements ActionListener{<br> JButton b1,b2,b3;<br> public ButtonDemo() {<br> super();<br> ImageIcon leftButtonIcon=new ImageIcon("images/right.gif); <br> <font color="339900">//显示在左按钮上的图标</font><br> ImageIcon middleButtonIcon=new ImageIcon("images/middle.gif); <br> <font color="339900">//显示在中间按钮上的图标</font><br> ImageIcon middleButtonIcon=new ImageIcon("images/left.gif);<br> <font color="339900">//显示在右按钮上的图标</font><br> b1=new JButton("Disable middle button",leftButtonIcon);<br> <font color="339900">//按钮b1上同时显示文字和图标</font><br> b1.setVerticalTextPosition(AbstractButton.CENTER);<br> <font color="339900">//按钮b1上的文字在垂直方向上是居中对齐</font><br> b1.setHorizontalTextPosition(AbstractButton.LEFT);<br> <font color="339900">//按钮b1上的文字在水平居方向上是居左对齐</font><br> b1.setMnemonic('d'); <font color="339900">//设置按钮b1的替代的键盘按键是'd'</font><br> b1.setActionCommand("diaable");<br> ……<br> }<br> }<br> <br> <img src="../../../images/tu/ch07/7_2_3_9.gif" width="366" height="87"><br> </p> <p><span class="pt9-black"><br> </span></p> </td> </tr> </table> </td> </tr></table></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -