不仅可以将这两个部分分开,而且还建议这样做(请参阅MVC模式-非常有关分离屏幕控件(如按钮)和程序逻辑)
我想到的最简单的方法是编写一个实现
ActionListener接口的命名类,如下所示:
public class SomeActionListener implements ActionListener{ private JTextField textField1; private JComboBox combo1; private JTextField textField2; //... public SomeActionListener(JTextField textField1, JComboBox combo1, JTextField textField2){ this.textField1=textField1; this.combo1=combo1; this.textField2=textField2; //... } public void actionPerformed(ActionEvent e) { //cmd }}
然后将其添加到您的按钮:
ActionListener actionListener = new SomeActionListener(textField1, combo1, textField2);someButton.addActionListener(actionListener);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)