Исходные тексты аплета Draw
Назад Вперед
Исходные тексты аплета Draw вы найдете в листинге 1.
Листинг 1. Файл draw.java
import java.applet.*; import java.awt.*;
public class draw extends Applet { Toolkit tk; String szFontList[]; FontMetrics fm; int yStart = 20; int yStep; String parm_TestString;
public void init() { tk = Toolkit.getDefaultToolkit(); szFontList = tk.getFontList(); parm_TestString = getParameter("TestString"); }
public String getAppletInfo() { return "Name: draw"; }
public void paint(Graphics g) { int yDraw; Dimension dimAppWndDimension = getSize();
g.clearRect(0, 0, dimAppWndDimension.width - 1, dimAppWndDimension.height - 1);
g.setColor(Color.yellow); g.fillRect(0, 0, dimAppWndDimension.width - 1, dimAppWndDimension.height - 1);
g.setColor(Color.black); g.drawRect(0, 0, dimAppWndDimension.width - 1, dimAppWndDimension.height - 1);
fm = g.getFontMetrics(); yStep = fm.getHeight();
for(int i = 0; i < szFontList.length; i++) { g.setFont(new Font("Helvetica", Font.PLAIN, 12)); g.drawString(szFontList[i], 10, yStart + yStep * i);
fm = g.getFontMetrics(); yStep = fm.getHeight();
g.setFont(new Font(szFontList[i], Font.PLAIN, 12)); g.drawString(parm_TestString, 100, yStart + yStep * i); }
yDraw = yStart + yStep * szFontList.length + yStep;
Polygon p = new Polygon();
p.addPoint(70, yDraw); p.addPoint(150, yDraw + 30); p.addPoint(160, yDraw + 80); p.addPoint(190, yDraw + 60); p.addPoint(140, yDraw + 30); p.addPoint(70, yDraw + 39);
g.drawPolygon(p);
g.setColor(Color.red); g.drawRect(10, yDraw + 85, 200, 100);
g.setColor(Color.black); g.drawArc(10, yDraw + 85, 200, 100, -50, 320); }
public String[][] getParameterInfo() { String[][] info = { { "TestString", "String", "Test string" } }; return info; } }