在Java中以编程方式为按钮创建事件
我有一个JButton数组。我想在jbutton的mousePressed事件中添加在Java中以编程方式为按钮创建事件,java,swing,netbeans,jbutton,Java,Swing,Netbeans,Jbutton,我有一个JButton数组。我想在jbutton的mousePressed事件中添加Home\u MouseDown过程。下面是我创建的JButton数组 代码: Jbutton[][] home = new JButton[8][8]; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { home[j][i] = new JB
Home\u MouseDown
过程。下面是我创建的JButton数组
代码:
Jbutton[][] home = new JButton[8][8];
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
home[j][i] = new JButton();
this.add(home[j][i]);
}
}
Jbutton[]home=newjbutton[8][8];
对于(int i=0;i<8;i++){
对于(int j=0;j<8;j++){
home[j][i]=新的JButton();
本条增补(首页[j][i]);
}
}
问题是什么?/你尝试过什么?为什么家庭从资本开始?这是一节课吗?
Home[j][i].addActionListener(new ActionListener(){
@Override
ActionPerformed(ActionEvent evt){
//w.e function u wanna add here on mouse click
}
});