I do not believe that AspectJ is the right technology for this task.
I recommend simply using a separate ActionListener for each button or finding the activated button using the ActionEvent getSource() method.
However, if you like to do this with AspectJ, here is the solution:
public static JButton j1; @Pointcut("execution(* *.actionPerformed(*)) && args(actionEvent) && if()") public static boolean button1Pointcut(ActionEvent actionEvent) { return (actionEvent.getSource() == j1); } @Before("button1Pointcut(actionEvent)") public void beforeButton1Pointcut(ActionEvent actionEvent) {
The only solution is to run a run-time check because the static signatures are the same for both JButton objects.
I declared an if() condition in a pointcut. This requires the annotated @Pointcut method to @Pointcut a public static method and return a boolean value.
Espen source share