java button监听,点击后setEnabled(false) 我想监听很多个按钮,点击一次后,把点击的那个按钮setEnabled(false)该怎样做啊 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public void actionPerformed(ActionEvent e) { for(int i=0;i<W;i++){ for(int j=0;j<H;j++){ if(e.getSource()==jb[i][j]){ jb[i][j].setEnabled(false); } } }总觉得怪怪的。 if(e.getSource()==点击的按钮){ 点击的按钮.setEnabled(false); } 所以才说你用循环做是对的啊public class DragFileTest extends JFrame implements ActionListener{ private static final long serialVersionUID = 1L; JButton[][] jb; public DragFileTest() { super("frame"); this.setLayout(new GridLayout(3,3)); jb = new JButton[3][3]; for(int i=0;i<3;i++){ for(int j=0;j<3;j++){ jb[i][j] = new JButton("b"+i+" "+j); jb[i][j].addActionListener(this); this.getContentPane().add(jb[i][j]); } } } public static void main(String[] args) { DragFileTest ts = new DragFileTest(); ts.setBounds(200, 200, 300, 200); ts.setVisible(true); } public void actionPerformed(ActionEvent e) { for(int i=0;i<3;i++){ for(int j=0;j<3;j++){ if(e.getSource()==jb[i][j]){ jb[i][j].setEnabled(false); } } } }} e.getSource()就是当前点击的按钮! button.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getSource() instanceof JButton) { JButton thisIsCurrentButton = (JButton) e.getSource(); thisIsCurrentButton.setEnabled(false); JOptionPane.showMessageDialog(null, thisIsCurrentButton.getText()); } } }); =============================================================我也想过把它(JButton)强转下。============================================================= 我该用哪种布局 求资源:JDK 7 以及能与之兼容的eclipse软件 一段简单的代码,大家能否看出错误 关于BASE64Decoder加密的问题,高手进。。。。 如何用键盘控制panel的焦点的移动 java klocwork issue: JD.SYNC.IN 请教一个小问题-继承 如何修改Swing默认风格? 编译出这个问题又是怎么回事? 如何解决在windows2k下用javamail发中文mail乱码的问题??(急) 求java类库中文版 如何仅知道class名,取得包括package的全名?
for(int i=0;i<W;i++){
for(int j=0;j<H;j++){
if(e.getSource()==jb[i][j]){
jb[i][j].setEnabled(false);
}
}
}
总觉得怪怪的。
点击的按钮.setEnabled(false);
}
private static final long serialVersionUID = 1L;
JButton[][] jb;
public DragFileTest() {
super("frame");
this.setLayout(new GridLayout(3,3));
jb = new JButton[3][3];
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
jb[i][j] = new JButton("b"+i+" "+j);
jb[i][j].addActionListener(this);
this.getContentPane().add(jb[i][j]);
}
}
} public static void main(String[] args) {
DragFileTest ts = new DragFileTest();
ts.setBounds(200, 200, 300, 200);
ts.setVisible(true);
} public void actionPerformed(ActionEvent e) {
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
if(e.getSource()==jb[i][j]){
jb[i][j].setEnabled(false);
}
}
}
}
}
public void mouseClicked(MouseEvent e) {
if (e.getSource() instanceof JButton) {
JButton thisIsCurrentButton = (JButton) e.getSource();
thisIsCurrentButton.setEnabled(false);
JOptionPane.showMessageDialog(null, thisIsCurrentButton.getText());
}
} });
我也想过把它(JButton)强转下。
=============================================================