Swing高级控件综合例程

1)新建一个项目actionlist---》主类名设置为:org.netbeans.swing.actionlist.ActionList-à添加一个Jframe Form模板创建的ActionListFrame

2)在这个ActionListFrame中添加JsplitPane ,拆分格命名:jSplitPaneGlobal,并

dividerLocation设置为100dividerSize设置为:3

3)同5.3一样,在其右键部分添加一个JsplitPane 名为:jSplitPaneRight,其中orientation 属性设置为VERTICAL_SPLIT, dividerLocation设置为80 dividerSize设置为3 ,界面为:

 

这个就是设置后的。分割窗口界面

4)如上图,每个键部分都添加一个面板panel,即jSplitPaneGlobal的左键部分,jSplitPaneRight的左键和右键部分都分别添加一个panel,分别命名为:jPanelLeft,jPanelRightTop,jPanelRightBottom.

5)对于jPanelLeft,添加一个label,名:就jLabelList,test属性为“列表项”,再添加一个Jlist,名:jListSport,设置初始选项(属性model)为“中超

意甲,英超,德甲,西甲,法甲,J联赛”如图:

6)对于jPanelRightTop,添加一个label,名:jLabelMessage,test值:“这里将显示动作”

7)对于jPanelRightBottom,添加一个ButtonGroup,名为:ButtonGroupOne 这个要在查看器里修改,在面板上是看不到的,是用于在单选按钮中只能选中一个的作用

再添加以下控件:

控件类型          控件名称                     text属性值

jLabel                jLabelAddress                        地址:

JTextField             jTextFieldAddress                     

JRadioButton           jRadioButtonFavor                    喜欢

JRadioButton           JRadioButtonCommon                  一般

JRadioButton            JRadioButtonDislike                  讨厌

JCheckBox             JCheckBoxBaggio                    巴乔

JCheckBox             JCheckBoxBeakHam                 贝克汉姆

JCheckBox             JCheckBoxFigo                     费戈

JButton                JButtonEnter                       确定

JButton                 JButtonCancel                     取消

8)将jRadioButtonFavor JRadioButtonCommon  JradioButtonCommon buttonGroup属性设置为buttonGroupOne,且JRadioButtonCommon  selected属性设置为选中状态

最后的界面为:

 

9)功能开发

事件:

1ValueChanged事件:jListSportValueChanged事件,名:jListSportValueChanged

2ItemStateChanged事件:

jRadioButtonDislikeItemStateChanged事件,名:jRadioButtonDislikeItemStateChanged         jRadioButtonCommonItemStateChanged事件,名:jRadioButtonCommonItemStateChanged

jRadioButtonFavorItemStateChanged事件,名:jRadioButtonFavorItemStateChanged

jCheckBoxBeakHamItemStateChanged事件,名:jCheckBoxBeakHamItemStateChanged

jCheckBoxBaggioItemStateChanged事件,名:jCheckBoxBaggioItemStateChanged

jCheckBoxFigoItemStateChanged事件,名:jCheckBoxFigoItemStateChanged

3ActionPerformed事件

jTextFieldAddressActionPerformed 名:jTextFieldAddressActionPerformed

jButtonEnterActionPerformed事件,名:jButtonEnterActionPerformed

jButtonCancelActionPerformed事件,名:jButtonCancelActionPerformed

代码分别为:

(1)       ValueChanged事件

private void jListSportValueChanged(javax.swing.event.ListSelectionEvent evt) {

        // TODO add your handling code here:

        String sport = (String)this.jListSport.getSelectedValue();

        this.jLabelMessage.setText("你选择了"+sport);

}

2ItemStateChanged事件:

private void jRadioButtonDislikeItemStateChanged(java.awt.event.ItemEvent evt) {

        // TODO add your handling code here:

        this.jLabelMessage.setText("你选择了讨厌单选按钮!");

    }

 

private void jRadioButtonCommonItemStateChanged(java.awt.event.ItemEvent evt) {

        // TODO add your handling code here:

        this.jLabelMessage.setText("你选择了普通单选按钮!");

    }

 

private void jRadioButtonFavorItemStateChanged(java.awt.event.ItemEvent evt) {

        // TODO add your handling code here:

        this.jLabelMessage.setText("你选择了喜欢单选按钮!");

    }

 

private void jCheckBoxBeakHamItemStateChanged(java.awt.event.ItemEvent evt) {

        // TODO add your handling code here:

        if(this.jCheckBoxBeakHam.isSelected()){

            this.jLabelMessage.setText("你开始喜欢贝克汉姆!");

        } else {

            this.jLabelMessage.setText("你不喜欢贝克汉姆!");

        }

    }

 

private void jCheckBoxBaggioItemStateChanged(java.awt.event.ItemEvent evt) {

        // TODO add your handling code here:

        if(this.jCheckBoxBaggio.isSelected()){

            this.jLabelMessage.setText("你开始喜欢巴乔!");

        } else {

            this.jLabelMessage.setText("你不喜欢巴乔!");

        }

    }

 

 

private void jCheckBoxFigoItemStateChanged(java.awt.event.ItemEvent evt) {

        // TODO add your handling code here:

        if(this.jCheckBoxFigo.isSelected()){

            this.jLabelMessage.setText("你开始喜欢费戈!");

        } else {

           this.jLabelMessage.setText("你不喜欢费戈!");

        }

    }

 

3ActionPerformed事件

private void jTextFieldAddressActionPerformed(java.awt.event.ActionEvent evt) {

        // TODO add your handling code here:

        String address = this.jTextFieldAddress.getText();

        if(address!=null&&!address.equals("")){

            this.jLabelMessage.setText("你输入了"+address);

        } else {

            this.jLabelMessage.setText("你没有输入任何内容!");

        }

    }

 

private void jButtonEnterActionPerformed(java.awt.event.ActionEvent evt) {

        // TODO add your handling code here:

        this.jLabelMessage.setText("你按下了确定按钮!");

    }

 

  private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {

        // TODO add your handling code here:

        this.jLabelMessage.setText("你按下了取消按钮!");

    }

       

Mian函数:

public static void main(String args[]) {

        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {

                new ActionListFrame().setVisible(true);

            }

        });

    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值