1)新建一个项目actionlist---》主类名设置为:org.netbeans.swing.actionlist.ActionList-à添加一个Jframe Form模板创建的ActionListFrame类
2)在这个ActionListFrame中添加JsplitPane ,拆分格命名:jSplitPaneGlobal,并
将dividerLocation设置为100,dividerSize设置为: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)功能开发
事件:
(1)ValueChanged事件:jListSport的ValueChanged事件,名:jListSportValueChanged
(2)ItemStateChanged事件:
jRadioButtonDislike的ItemStateChanged事件,名:jRadioButtonDislikeItemStateChanged, jRadioButtonCommon的ItemStateChanged事件,名:jRadioButtonCommonItemStateChanged
jRadioButtonFavor的ItemStateChanged事件,名:jRadioButtonFavorItemStateChanged
jCheckBoxBeakHam的ItemStateChanged事件,名:jCheckBoxBeakHamItemStateChanged
jCheckBoxBaggio的ItemStateChanged事件,名:jCheckBoxBaggioItemStateChanged
jCheckBoxFigo的ItemStateChanged事件,名:jCheckBoxFigoItemStateChanged
(3)ActionPerformed事件
jTextFieldAddress的ActionPerformed 名:jTextFieldAddressActionPerformed
jButtonEnter的ActionPerformed事件,名:jButtonEnterActionPerformed
jButtonCancel的ActionPerformed事件,名: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);
}
(2)ItemStateChanged事件:
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("你不喜欢费戈!");
}
}
(3)ActionPerformed事件
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);
}
});
}