java swing JCheckBox怎么加监听

Java Swing太恶心了,到处坑。


JCheckBox[] boxs;

boxs = new JCheckBox[oList.size()];// 创建控件数组

for (int i = 0; i < boxs.length; i++) {// 遍历控件数组

boxs[i] = new JCheckBox(oList.get(i).get(2).toString());// 初始化数组中的复选框组件

panel.add(boxs[i]);// 把数组元素(即每个复选框)添加到面板中

}

请问,boxs的监听怎么加


海绵宝宝撒
浏览 1950回答 2
2回答

慕侠2389804

就写在迭代里好了:JCheckBox[] boxs;boxs = new JCheckBox[oList.size()];// 创建控件数组for (int i = 0; i < boxs.length; i++) {// 遍历控件数组&nbsp; &nbsp; boxs[i] = new JCheckBox(oList.get(i).get(2).toString());// 初始化数组中的复选框组件&nbsp; &nbsp; panel.add(boxs[i]);// 把数组元素(即每个复选框)添加到面板中&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; boxs[i].addActionListener(new ActionListener() {&nbsp; &nbsp; &nbsp; &nbsp; @Override&nbsp; &nbsp; &nbsp; &nbsp; public void actionPerformed(ActionEvent e) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //TBD&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; });}

德玛西亚99

addActionListener
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java