jbuttons
单击可以将通用代码应用于一个框架中的多个代码jbutton
。就像当我单击说jbutton80
,然后:
从jbutton1
到jbutton75
{
// common code that applies to all jbutton in loop
}
我正在用Java制作测验应用程序,并且在中有大约70-80个按钮jframe
。每个按钮对应一个问题。问题分为几部分。所以我想要:
//如果用户选择(或点击jbutton
)截面的setvisible(true)
从jbutton1
到jbutton20
和调用setVisible(假)从jbutton21
到jbutton 80
。
抱歉,如果之前曾有人问过这个问题。我试图搜索任何相关的帖子,但是找不到。
您是否尝试过制作动作监听器
ActionListener l = new ActionListener() { /* code here */ };
然后将相同的添加到所有JButton中吗?
for (JButton b : buttons) {
b.addActionListener(l);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句