Skip to main content

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

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I thitnk the problem is that you are advising *calls* to mouse*-methods.
However those calls are all made outside the class HelloWorldApp, which is
presumably the only one you are weaving into. Hence, the pointcut does not
apply (don'T you get a warning?). Try an execution-Pointcut instead. This
should work.
 
Eric

- --
Eric Bodden
Chair I2 for Programming Languages and Program Analysis
RWTH Aachen University 

 

  _____  

From: aspectj-users-bounces@xxxxxxxxxxx
[mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Joanne (sent by
Nabble.com)
Sent: Samstag, 17. September 2005 01:39
To: aspectj-users@xxxxxxxxxxx
Subject: [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 -
<http://www.nabble.com/AspectJ-with-Applet-t316734.html#a884848> users forum
at Nabble.com. 

-----BEGIN PGP SIGNATURE-----
Version: PGP Desktop 9.0.2 (Build 2424)

iQA/AwUBQytlKswiFCm7RlWCEQKyvgCg0sTAKWFtJSnLBcaihclKpOjLdVwAoLLS
LbVLXAtpfB06mglgb/MDErY2
=FDUu
-----END PGP SIGNATURE-----
I thitnk the problem is that you are advising *calls* to mouse*-methods. However those calls are all made outside the class HelloWorldApp, which is presumably the only one you are weaving into. Hence, the pointcut does not apply (don'T you get a warning?). Try an execution-Pointcut instead. This should work.
 
Eric

--
Eric Bodden
Chair I2 for Programming Languages and Program Analysis
RWTH Aachen University

 


From: aspectj-users-bounces@xxxxxxxxxxx [mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Joanne (sent by Nabble.com)
Sent: Samstag, 17. September 2005 01:39
To: aspectj-users@xxxxxxxxxxx
Subject: [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.

Attachment: PGPexch.htm.sig
Description: Binary data


Back to the top