java swing课件,第17章Java-Swing.ppt

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 命令按钮JButton 命令按钮(JButton)是一种组件,当用户通过单击按钮时将产生动作事件ActionEvent,以触发特定的动作代码,从而完成预先指定的功能。 Swing中JButton既支持文本按钮,也支持图像按钮,或两者兼有。 * 命令按钮JButton 创建按钮对象 public JButton() 创建不带有设置文本或图标的按钮。 public JButton(String?text) 创建一个带文本的按钮。 public JButton(Icon ?icon) 创建一个带图标的按钮。 public JButton(String?text, Icon?icon) 创建一个带初始文本和图标的按钮。 * 命令按钮JButton 按钮对象的常用方法 public String getText() 返回按钮的文本。 public void setText(String ?text) 设置按钮的文本。? * JCheckBox和JRadioButton SwingGUI组件包含3种类型的状态按钮: JToggleButton 复选框按钮JCheckBox 单选按钮JRadioButton 按钮都有开/关(真/假)两种值。提供用户在给定的数据中进行选择.? Swing button 的继承层次 JComponent AbstractButton JToggleButton JRadioButton JCheckBox JButton * 复选框(JCheckBox) JCheckBox提供简单的“on/off”开关,旁边显示文本标签。它只有两种状态:选中和未选中。在一组复选框中,可以同时选择多项。 * 复选框(JCheckBox) 复选框的常用的构造方法: JCheckBox(String text) JCheckBox(String text, boolean selected) JCheckBox(Icon icon, boolean selected) JCheckBox(String text, Icon icon, boolean selected) 创建一个带文本“Italic”的复选框,指定其最初为非选定状态 JCheckBox italic = new JCheckBox( "Italic" ); 创建一个带文本“Bold”的复选框,指定其最初为选定状态。 JCheckBox bold = new JCheckBox( "Bold" ,true); * 单选按钮JRadioButton 单选按钮(JRadioButton)与复选框一样也只有两种状态:选中和未选中。 * 单选按钮(JRadioButton) JRadioButton的常用的构造方法: JRadioButton(String text) JRadioButton(String text,boolean selected): JRadioButton(Icon icon) RadioButton(String text,Icon icon, boolean selected) 单选按钮与 ButtonGroup 对象配合使用,可创建一组单选按钮,用户一次只能选择其中的一个。 * 单选按钮JRadioButton 例如:创建性别的两个单选按钮对象并用ButtonGroup 对象逻辑上分为一组. maleButton = new JRadioButton( "男", true ); womenButton = new JRadioButton( "女", false ); ButtonGroup radioGroup = new ButtonGroup(); radioGroup.add( maleButton ); radioGroup.add( womenButton ); Container container = getContentPane(); container.add( maleButton ); container.add( womenButton ); * JCheckBox和JRadioButton 复选框或单选按钮对象的常用方法 (1)boolean isSelected():返回复选框的状态,是否被选中。 (2)void setSelected(boolean):设置复选框是否被选中。 * 标签JLabel JLabel标签是用户不能修改只能

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值