【发布时间】:2014-02-28 10:55:14
【问题描述】:
我正在为个人项目创建一个程序,我最终创建了许多 JButton,它们在项目中占用了相当多的行,是否可以减少仍然产生相同数量的 JButton 的行数?
JButton button1 = new JButton("Empty");
JButton button2 = new JButton("Empty");
JButton button3 = new JButton("Empty");
JButton button4 = new JButton("Empty");
JButton button5 = new JButton("Empty");
JButton button6 = new JButton("Empty");
JButton button7 = new JButton("Empty");
JButton button8 = new JButton("Empty");
JButton button9 = new JButton("Empty");
JButton button10 = new JButton("Empty");
JButton button11 = new JButton("Empty");
and about 5 more
【问题讨论】:
-
你能给我举个例子吗?
-
JButton[] btnBtns = new JButton[n];
-
+1 用于寻找更有效的解决方案:)我真的很喜欢这种思维方式;)