import java.awt.*; import java.applet.*; import java.net.*; import java.lang.*; import java.awt.image.*; public class button extends Applet { int x=0,y=0,StrPosX,StrPosY,picw=200,pich=30; Color White; Font MyFont=new Font("Helvetica",Font.BOLD,(pich/2)); Image img,shadowedImg; FontMetrics Fo; String ButtonText,Width,Height,Link=null; URL url; boolean mouseIn=false; boolean isLink=false; public void init() { White = new Color(255,255,255); setBackground(White); ButtonText = getParameter("text"); Width = getParameter("width"); Height = getParameter ("height"); Link = getParameter ("link"); if (Link!=null) isLink=true; try { url = new URL(Link); } catch (Exception MalformedURLException) { ; } picw = java.lang.Integer.parseInt(Width); pich = java.lang.Integer.parseInt(Height); int pix[] = new int[picw * pich]; int index = 0; int red=0; int blue; int green; int border=5; int row=0; int column=0; int lowShadowStart=pich-border; int rightShadowStart=picw-border; for (int y = 0; y < pich; y++) { int Offset = (int)Math.sqrt( ((picw)*(picw)) + ((y-pich)*(y-pich)) ); for (int x = 0; x < picw; x++) { blue = 255 - (int)((Offset-x)*(155/(float)picw)); green = 200 - (int)((Offset-x) * (200/(float)picw)); row=index/picw; column=index%picw; //upper shadow if (isLink) { if ( (rowrow) && (column<(picw-row)) ) { green-=40; blue-=40; } //lower shadow else if ( (row>=(lowShadowStart)) && (column>(border-(row%lowShadowStart))) && (column<(picw-(pich%row))) ) { green+=60; blue+=60; } else if ( column>=rightShadowStart ) { //right shadow green+=20; blue+=20; } else if ( column255) blue=255; if (green>255) green=255; pix[index++] = (255<<24) | (red<<16) | (green<<8) | blue; } } img = createImage(new MemoryImageSource(picw, pich, pix, 0, picw)); ImageFilter shadower = new DarkFilter(); shadowedImg = createImage(new FilteredImageSource(img.getSource(),shadower)); } public void showNewPage (URL u) { getAppletContext().showDocument(u); } public void paint(Graphics g) { Fo = g.getFontMetrics(MyFont); StrPosX = (picw - Fo.stringWidth(ButtonText))/2; StrPosY = pich/2 + Fo.getAscent()/2; if (mouseIn) g.drawImage(shadowedImg,x,y,picw,pich,this); else { g.drawImage(img,x,y,picw,pich,this); } g.setFont(MyFont); g.setColor(White); g.drawString(ButtonText,StrPosX,StrPosY); } public void update(Graphics g) { paint(g); } public boolean mouseUp(Event e, int posx, int posy) { showNewPage(url); return false; } public boolean mouseEnter(Event e, int posx, int posy) { if (isLink) { mouseIn=true; repaint(); } getAppletContext().showStatus(Link); return false; } public boolean mouseMove(Event e, int posx, int posy) { getAppletContext().showStatus(Link); return false; } public boolean mouseExit(Event e, int posx, int posy) { mouseIn=false; if (isLink) { repaint(); } return false; } public void stop() { destroy(); } public void start() { init(); for(int k=0;k<20;k++) System.out.println("At " + k + " netscape's bug!"); repaint(); } }