简体   繁体   English

如何在Java中创建ActionEvent类的对象?

[英]How to create object of ActionEvent class in java?

Anyone please told me How to create object of ActionEvent class in java ?? 有人告诉我如何在Java中创建ActionEvent类的对象吗? and how to use method of the ActionEvent Class 以及如何使用ActionEvent类的方法

Please do be more descriptive on what you are trying to do. 请对您要执行的操作进行更多描述。

But here is a sample of two different types of using an ActionEvent 但这是使用ActionEvent的两种不同类型的示例

If you are using JComponents and you want to add it to a button and maybe other things i have clue just do 如果您使用的是JComponents,并且想将其添加到按钮中,也许我知道的其他事情就是这样做

component.addActionListener(new ActionListener()
{
   //import the ActionListener and then you will be prompted to add an actionPerformed method
});

If you want to make a class of it just do something like this. 如果要对其进行分类,请执行以下操作。

private class Listener1 implements ActionListener
{
 //again it will ask that you import it if not already imported and add the method actionPerformed(ActionEvent e) which is where you will put your code
}

Then somewhere in your code do 然后在代码中的某处

object.addActionListener(new Listener1());

No clue what you are asking for so i hope some of the above code helps 不知道你在问什么,所以我希望上面的一些代码能对你有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM