2014-04-02 89 views
0

任何人都請告訴我如何創建對象ActionEvent class java ??以及如何使用方法的ActionEvent如何在java中創建ActionEvent類的對象?

+0

什麼是你想達到什麼地方?您需要對您面臨的問題進行更具描述性的分析,並分享您的嘗試,以便我們能夠更好地爲您提供幫助! – Ritikesh

+0

'ActionEvent e = ActionEvent(source,ActionEvent.ACTION_PERFORMED,「command」);'是答案。但我不確定問題是什麼。你應該清楚地說明你將如何處理這個事件。 – Marco13

回答

0

請做更多描述性的你想做什麼。

但這裏是兩種不同類型的使用一個ActionEvent

如果您正在使用JComponents的樣本,並希望將其添加到按鈕,也許其他的東西,我有線索只是做

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

如果你想創建一個類,只需要做這樣的事情。

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 
} 

然後在你的代碼做

object.addActionListener(new Listener1()); 

不知道你問的,所以我希望上面的一些代碼有助於