w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How do I call methods when actionPerformed is called in GUI

If I understand it, you should do the following (just an example):

class X{

  JButton firstButton;
  JButton secondButton;

  public X(){

   firstButton=new JButton("first");firstButton.setActionCommand("FB");
   secondButton=new JButton("second");secondButton.setActionCommand("SB");

  }//constructor closing

  public void method1(){}
  public void method2(){}

  class EventHandler extends ActionListener{

     public void ActionPerformed(ActionEvent e){

      String action=e.getActionCommand();

     if(action.equals("FB"))method1();
     else if(action.equals("SB"))method2();

    }//



  }//inner-class closing

}//calss closing




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.