a1.html
<applet code="zzz" width=520 height = 480> <param name=pict value="jim.graham.gif"> <param name=area1 value="NameArea,260,180,120,60,Hi!!!"> <param name=area2 value="NameArea,265,125,45,20,That is my right eye"> <param name=area3 value="NameArea,335,130,100,20,Hello ...."> </applet>
import java.applet.*; import java.awt.*; import java.awt.image.*; import java.util.*; public class zzz extends Applet { Image b; aaa a[]; public void init() { a = new aaa[3]; b = getImage(getDocumentBase(),getParameter("pict")); int n = 1; String s; while (n <= 3) { s=getParameter("area"+n); s = s.substring(8); a[n-1]= new aaa(this , s); n++; } } public void update(Graphics g) { paint(g); } public void paint(Graphics g) { g.drawImage(b,0,0,this); for(int i = a.length; --i >= 0;) { if (a[i].v && !a[i].r) a[i].setState(g,false); if(a[i].r) a[i].setState(g,true); } } public boolean mouseMove(Event e,int x, int y) { for(int i=0; i<3; i++) { if(a[i].inside(x,y)) a[i].r = true; else a[i].r = false; if(a[i].v != a[i].r) repaint(); } return true; } } class aaa { zzz p; int X,Y,W,H; boolean r=false,v = false; String c; Image h; public aaa(zzz m, String d) { System.out.println(d); p=m; StringTokenizer z = new StringTokenizer(d,", "); X = Integer.parseInt(z.nextToken()); Y = Integer.parseInt(z.nextToken()); W = Integer.parseInt(z.nextToken()); H = Integer.parseInt(z.nextToken()); c = z.nextToken(""); Image o = p.createImage( new FilteredImageSource(p.b.getSource(), new CropImageFilter(X,Y,W,H))); h = p.createImage(new FilteredImageSource(o.getSource(),new rrr())); } public boolean inside(int x, int y) { if (x >= X && x < (X+W) && y >= Y && y < (Y+H)) return true; else return false; } public void setState(Graphics g, boolean l) { if(l) { g.drawImage(h,X,Y,p); p.getAppletContext().showStatus(c); } v = l; } } class rrr extends RGBImageFilter { public int filterRGB(int x, int y, int r) { return(r & 0xffffff00); } }Try the above code .It has been simplified to understand it better. The expalnation for the program and many more details will be coming up on this page very soon.
Thanks for visiting this page and let us know of your feedback, comments, suggestion.