import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Borders extends Applet
{
String Name = new String("Tim Bell");
Font serifItalic = new Font("Serif", Font.ITALIC, 20);
int leading, ascent, height, width;
int x = 40, y = 60;
static final int BORDER = 5;
public void paint(Graphics gr)
{
gr.setFont(serifItalic);
gr.drawString(Name,x,y);
leading = gr.getFontMetrics().getLeading();
ascent = gr.getFontMetrics().getAscent();
height = gr.getFontMetrics().getHeight();
width = gr.getFontMetrics().stringWidth(Name);
gr.setColor(Color.red);
gr.drawRect((x - BORDER) - 10, (y - (ascent + leading + BORDER))-10, (width + 2 * BORDER)+20, (height + 2 * BORDER)+20);
gr.setColor(Color.green);
gr.drawRect((x - BORDER) - 20, (y - (ascent + leading + BORDER))-20, (width + 2 * BORDER)+40, (height + 2 * BORDER)+40);
gr.setColor(Color.yellow);
gr.drawRect((x - BORDER) - 30, (y - (ascent + leading + BORDER))-30, (width + 2 * BORDER)+60, (height + 2 * BORDER)+60);
gr.setColor(Color.blue);
gr.drawRect((x - BORDER) - 40, (y - (ascent + leading + BORDER))-40, (width + 2 * BORDER)+80, (height + 2 * BORDER)+80);
}
}
=====================================
fireworks:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class BoxAround extends Applet
{
String companyName = new String("Event Handlers Incorporated");
Font serifItalic = new Font("Serif", Font.ITALIC, 20);
int leading, ascent, height, width;
int x = 40, y = 60;
static final int BORDER = 5;
public void paint(Graphics gr)
{
gr.setFont(serifItalic);
gr.drawString(companyName,x,y);
leading = gr.getFontMetrics().getLeading();
ascent = gr.getFontMetrics().getAscent();
height = gr.getFontMetrics().getHeight();
width = gr.getFontMetrics().stringWidth(companyName);
gr.drawRect(x - BORDER, y - (ascent + leading + BORDER), width + 2 * BORDER, height + 2 * BORDER);
}
}