import java.awt.*;import java.applet.Applet;public class LissaApplet extends Applet {	protected double a, b, f1, f2, d, dt;	protected boolean valid;	public void init() {		setBackground(new Color(0, 64, 0));		//setParams(1, 1, 1, 2, Math.PI/4, .02);		//setParams(5, 4, 3, 5, Math.PI/2, .01);		setParams(getParameter("a"), getParameter("b"), getParameter("f1"), getParameter("f2"), getParameter("d"), getParameter("dt"));	}		public void embeddedInit() {		setBackground(new Color(0, 64, 0));		valid = false;	}		public void setParams(double aa, double bb, double ff1, double ff2, double dd, double dtt) {		a = aa; b = bb; f1 = ff1; f2 = ff2; d = dd; dt = dtt;		valid = true;		repaint();	}		public void setParams(String aa, String bb, String ff1, String ff2, String dd, String dtt) {		if (aa == null || bb == null || ff1 == null || ff2 == null || dd == null || dtt == null) valid = false;		else {			try {				a = Double.valueOf(aa).doubleValue();				b = Double.valueOf(bb).doubleValue();				f1 = Double.valueOf(ff1).doubleValue();				f2 = Double.valueOf(ff2).doubleValue();				if (dd.toLowerCase().indexOf("pi") == -1) d = Double.valueOf(dd).doubleValue();				else d = Double.valueOf(dd.substring(0, dd.toLowerCase().indexOf("pi")).trim()).doubleValue() * Math.PI;				dt = Double.valueOf(dtt).doubleValue();				valid = true;			}			catch (NumberFormatException e) {				valid = false;			}		}		repaint();	}		public void paint(Graphics g) {		int w = getSize().width, h = getSize().height, hw = w/2, hh = h/2;		g.setFont(new Font("dialog", Font.PLAIN, 9));		FontMetrics fm = g.getFontMetrics();		g.setColor(new Color(0, 128, 0));		g.drawLine(0, hh, w, hh); //x		g.drawLine(hw, 0, hw, h); //y		g.drawString("x", w-10, hh-5);		g.drawString("y", hw+5, 10);		if (valid) {			double sfact = min((hw-fm.stringWidth(Double.toString(-b))-6)/a, (hh-fm.getAscent()-6)/b);			int xmax = (int)(sfact*a), ymax = (int)(sfact*b);			g.drawLine(hw-xmax, hh-ymax, hw+xmax, hh-ymax); //oben			g.drawLine(hw-xmax, hh+ymax, hw+xmax, hh+ymax); //unten			g.drawLine(hw-xmax, hh-ymax, hw-xmax, hh+ymax); //links			g.drawLine(hw+xmax, hh-ymax, hw+xmax, hh+ymax); //rechts			g.drawString(Double.toString(a), hw+xmax-fm.stringWidth(Double.toString(a))/2, hh+ymax+fm.getAscent()+3);			g.drawString(Double.toString(-a), hw-xmax-fm.stringWidth(Double.toString(-a))/2, hh+ymax+fm.getAscent()+3);			g.drawString(Double.toString(b), hw-xmax-fm.stringWidth(Double.toString(b))-3, hh-ymax+fm.getAscent()/2-1);			g.drawString(Double.toString(-b), hw-xmax-fm.stringWidth(Double.toString(-b))-3, hh+ymax+fm.getAscent()/2-1);			g.setColor(new Color(128, 255, 64));			int sx = hw+(int)(a*sfact);			int sy = hh-(int)(b*Math.cos(d)*sfact);			int osx, osy;			for (double t = 0; t < 2*Math.PI + dt; t += dt) { //fŸr ganzzahlige f1, f2 wird so die ganze Figur mindestens einmal durchlaufen				osx = sx; osy = sy;				sx = hw+(int)(a*Math.cos(f1*t)*sfact);				sy = hh-(int)(b*Math.cos(f2*t+d)*sfact);				g.drawLine(osx, osy, sx, sy);			}		}		else {			g.setColor(new Color(128, 255, 64));			g.drawString("Invalid Parameters", hw-fm.stringWidth("Invalid Parameters")/2, hh+fm.getAscent()/2);		}	}		private static double min(double a, double b) { return (a < b) ? a : b; }	}