0

I'm currently working with AspectJ the first time to get "my feet wet". I would like to add a new Button on my Main frame (class Main extends JFrame). This is what I have so far:

public aspect MainWipe {

  public static final String Main.wipeText = "Wipe";
  public Button Main.wipeButton;

  pointcut initAtoms() : execution(void Main.initAtoms());

  after() returning() : initAtoms() 
  {
      // Does not work, eclipse error message "wipeButton / wipeText can not be resolved to a variable"
      wipeButton = new Button(wipeText);
  }
}

The "Static crosscutting" of the String- as well of the Button-field works fine, but i would like to extend my initAtoms method which is defined in Main with the button's initialization. For this i would have to access the fields defined in the same aspect, which doesn't work for me.

How can I achieve this? Somehow I'm not able to access the String and the Button.

Thanks!

EDIT:

Here is some part of my Main class:

public class Main extends JFrame{
    private static final String lineText = "Line";
    Button lineButton;

    // Removed other methods / fields / controls

    public void initAtoms() {
        lineButton = new Button(lineText);
    }

    public void initContentPane() {
        toolPanel.add(lineButton);
    }
}
Markus Weninger
  • 11,931
  • 7
  • 64
  • 137
  • Can you be more specific than "Does not work"? – BadZen May 05 '15 at 19:02
  • Are you expecting the button to show up in the UI after that? Or what is not working? Note that you haven't actually added it to the frame, just assigned it to a field... – BadZen May 05 '15 at 19:04
  • Sorry for not being specific enough. Both variables get stated with " can not be resolved to a variable" by eclipse. And I know that this won't add it on the frame, but I cannot extend my aspect to add the button to the frame as long as it is not initialized. It's all about how to access the fields which got specified in my aspect in the same aspect. – Markus Weninger May 05 '15 at 19:43
  • Well, do those inter-type decls actually corrspond to variables in your class? Perhaps post that one, too (your Main). – BadZen May 05 '15 at 19:46
  • No, they yet don't exist in the Main-class, they should only get added when the aspect gets added. I will try to post a part of my Main, i think it would be to big... – Markus Weninger May 05 '15 at 19:48
  • The basic idea behind all of this is: Depending on which aspects I choose in my configuration, my Main frame should contain different buttons. – Markus Weninger May 05 '15 at 19:54
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/77038/discussion-between-markus-weninger-and-badzen). – Markus Weninger May 05 '15 at 20:00

0 Answers0