Wab*_*age 5 java user-interface swing
在我的程序中,我希望用户:
在我的代码中,我有一个类,它做这样的事情:
mntmOpenDatabase.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//open the database
//display tables as buttons
tableButton.addActionListener(new ActionListener() { // select a table
public void actionPerformed(ActionEvent e) {
//display the columns of the table selected as buttons
colButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {// add to the list of columns to be exported }
Run Code Online (Sandbox Code Playgroud)
这导致了一个非常大的代码块.有更清洁,更简单的方法吗?
Hov*_*els 10
解决方案是重构:
请看一下这个类似但更完整的问题和答案:如何才能最好地避免编写臃肿的GUI代码?.答案是最好的,我希望我可以向他们投票数十亿次.
例如,您的上述代码可能非常简单:
mntmOpenDatabase.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
control.openDatabase();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
114 次 |
| 最近记录: |