import java.awt.*; import java.applet.*; import java.net.*; import java.lang.*; import java.awt.image.MemoryImageSource; public class button extends Applet { int x=0,y=0,StrPosX,StrPosY,picw,pich; Color White; Font MyFont; Image img; FontMetrics Fo; String ButtonText,Width,Height,Link; URL url; public void init() { White = new Color(255,255,255); setBackground(White); ButtonText = getParameter("text"); Width = getParameter("width"); Height = getParameter ("height"); Link = getParameter ("link"); picw = java.lang.Integer.parseInt(Width); pich = java.lang.Integer.parseInt(Height); int pix[] = new int[picw * pich]; int index = 0; int blue; int green; 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)); // To correct for area not within circle if (blue<0) blue=100; if (green<0) green=0; pix[index++] = (255<<24) | (0<<16) | (green<<8) | blue; } } img = createImage(new MemoryImageSource(picw, pich, pix, 0, picw)); MyFont = new Font("Helvetica",Font.BOLD,(pich/2)); repaint(); } 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; g.drawImage(img,x,y,picw,pich,this); g.setFont(MyFont); g.setColor(White); g.drawString(ButtonText,StrPosX,StrPosY); } public boolean mouseUp(Event e, int posx, int posy) { try { url = new URL(Link); } catch (Exception MalformedURLException) { ; } showNewPage(url); return false; } }