Trying to add ActionListener to JButtons

后端 未结 6 1137
忘掉有多难
忘掉有多难 2020-12-21 23:50

I cannot figure out how to add Actionlisteners to the JButtons, any help would be much appreciated.

public class Translator extends         


        
6条回答
  •  梦毁少年i
    2020-12-22 00:28

    button.addActionListener();
    

    In your case, it'll be:

    french.addActionListener(this);
    

    If you want to use the same ActionListener for all the three buttons, you can use the getSource() function of ActionEvent e to detect which button was actually pressed.

提交回复
热议问题