Java 您能让jFrame中的jButton将其代码生成到另一个类中吗?

Java 您能让jFrame中的jButton将其代码生成到另一个类中吗?,java,button,Java,Button,您可以让jframe中的按钮将其事件>动作>动作执行代码生成到jframe类之外的另一个类中吗。如果您不能,您可以手动在不同的类中生成代码以使按钮执行某些操作。是的,您可以 基本上,您可以使用myJbutton.setActionListener(新的MyButtonActionListener()) 您有一个类MyButtonActionListener实现ActionListener。将自动调用ActionExecuted方法 编辑:在下面添加代码 public class MyButton

您可以让jframe中的按钮将其事件>动作>动作执行代码生成到jframe类之外的另一个类中吗。如果您不能,您可以手动在不同的类中生成代码以使按钮执行某些操作。

是的,您可以

基本上,您可以使用
myJbutton.setActionListener(新的MyButtonActionListener())

您有一个
类MyButtonActionListener实现ActionListener
。将自动调用ActionExecuted方法

编辑:在下面添加代码

public class MyButtonActionListener implements ActionListener {
    @Override
    public void actionPerformed(EventListener e){
        // Do stuff
    }
}
然后设置按钮:

JButton myButton = new JButton("mybutton");
myButton.setActionListener(new MyButtonActionListener());

生成其代码…?是否要在其他应用程序中执行某些操作?或者在同一应用程序中的另一个类中?是的,当您右键单击同一应用程序中的另一个类中jframein上的按钮时application@Daniel,
不是我要找的
-然后你需要清楚地解释你要找的是什么。