Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] AspectJ with Applet

I'm a newbie to aspectJ.  I'm trying to make AspectJ work with a simple HelloWorld Java Applet.  My applet basically displays a box and each mouse click changes the background color, it works fine.
public class HelloWorldApp extends Applet
    implements MouseListener, MouseMotionListener
{
    int width, height;
    int mx, my;  
    boolean isButtonPressed = false;

    public void init() {
        width = getSize().width;
        height = getSize().height;
        setBackground( Color.black );

        mx = width/2;
        my = height/2;
       
        addMouseListener( this );
        addMouseMotionListener( this );
    }
   
   public void paint( Graphics g ) {
      if ( isButtonPressed ) {
         g.setColor( Color.black );
      }
      else {
         g.setColor( Color.gray );
      }
      g.fillRect( mx-20, my-20, 40, 40 );
   }

    public void mouseClicked( MouseEvent e )
    {
        isButtonPressed = !isButtonPressed;
        repaint();
        e.consume();
    }
    // ... no other Mouse actions are defined
}

Now i defined this aspect:
public aspect MyAppAspect
{
    pointcut callMouse() : call(* *..HelloWorldApp.mouse*(..));
   
    before() : callMouse()
    {
        System.out.println("mouse action");
    }
}
I added the aspectjrt.jar into ARCHIVE in html source code:
<APPLET
   CODE="HelloWorldApp.class"
   WIDTH=150
   HEIGHT=25>
      <PARAM NAME="ARCHIVE" VALUE="/scratch/yxie/aspectj1.2/lib/aspectjrt.jar">
      <PARAM NAME="type" VALUE="application/x-java-applet;version=1.5">
      <PARAM NAME="scriptable" VALUE="false">
</APPLET>

After compiled all these and when I click the mouse, the aspect didn't have any affect on the applet, nothing was printed in standard output.  I'd really appreciate if anyone can help me out with this.

Or if anyone has a simple working HelloWorld example of using AspectJ on applet, i'd really appreciate it too.  Thanks a lot in advance.

Joanne

Sent from the AspectJ - users forum at Nabble.com.

Back to the top