/* Aufgabe1.java */ import java.applet.*; import java.awt.*; import java.awt.event.*; /** * @author Karlheinz Wurm */ public class Aufgabe1 extends Applet { Font f; String name; public void init () { f = new Font("Helvetica",Font.BOLD,48); this.name = getParameter("name"); if (this.name == null) { this.name = "Nobody"; } this.name = "Hallo " + this.name; } public void paint(Graphics g) { // Oval mit Farbe pink g.setColor(Color.pink); g.fillOval(10,10,330,100); // Roter Umfassungsrahmen, da Java keine Linienbreite // verarbeitet, wird die Linienbreite durch 4 Ovale // unterschliedlicher Pixelbreite simuliert g.setColor(Color.red); g.drawOval(10,10,330,100); g.drawOval(9,9,332,102); g.drawOval(8,8,334,104); g.drawOval(7,7,336,106); // Textausgabe g.setColor(Color.black); g.setFont(f); g.drawString(this.name,30,75); } } /* Aufgabe2.java */ import java.applet.*; import java.awt.*; import java.awt.event.*; /** * @author Karlheinz Wurm */ public class Aufgabe2 extends Applet { public void init() { } public void paint(Graphics g) { Dimension d = getSize(); g.setColor(Color.yellow); g.fillRect(0,0,d.width-1,d.height-1); // Zeichnen der Tasse // Blaue Untertasse g.setColor(Color.blue); // fillOval(x,y,hoehe,breite) g.fillOval(10,110,150,40); g.setColor(Color.black); // drawOval(x,y,hoehe,breite) g.drawOval(10,110,150,40); g.drawOval(60,122,50,16); // rote Tasse g.setColor(Color.red); // Henkel // drawArc(x,y,hoehe,breite,startwinkel,bogen) g.drawArc(130,30,40,50,-120,210); g.fillArc(20,-70,130,200,180,180); g.setColor(Color.black); g.fillOval(20,20,130,20); // Beschriftung g.drawString("Kaffetasse",60,170); } } /* Aufgabe3.java */ import java.applet.*; import java.awt.*; import java.awt.event.*; /** * @author Benjamin Kormann */ public class Aufgabe3 extends Applet { private Polygon p; private int count, width, rad; public void init() { Dimension d = getSize(); width = d.width - 1; rad = (int) (0.4*width); count = Integer.valueOf(getParameter("count")).intValue(); generatePolygon(); } private void generatePolygon() { int pointX[] = new int[count]; int pointY[] = new int[count]; ; for(int i = 0; i < 360; i+=(360/count)) { pointX[i*count/360] = width/2 + (int)(rad*Math.cos(i*Math.PI/180)); pointY[i*count/360] = width/2 (int)(rad*Math.sin(i*Math.PI/180)); } p = new Polygon(pointX, pointY, count); } public void paint(Graphics g) { g.drawPolygon(p); } } /* Aufgabe4.java */ import java.applet.*; import java.awt.*; import java.awt.event.*; /** * @author Prof. Juergen Sauer */ public class Aufgabe4 extends Applet { /* Abmessungen des Fensters */ private static int hoehe; private static int breite; /* Applet-Verarbeitungsmethoden */ public void init() { Dimension d = getSize(); hoehe = d.height - 1; breite = d.width - 1; } public void paint(Graphics g) { // setBackground g.setColor(Color.yellow); g.fillRect(0,0,breite,hoehe); g.setColor(Color.black); double b; int rx = breite / 2; int ry = hoehe / 2; for (int i = 0;i < 360; i++) { b = i * Math.PI / 180; int x = (int) (breite / 2 * Math.sin(12*b)); int y = (int) (hoehe / 2 * Math.sin(12*b)); int rx1 = (int)(breite/2 + (x * Math.cos(b))); int ry1 = (int)(hoehe/2 + (y * Math.sin(b))); g.drawLine(rx,ry,rx1,ry1); rx = rx1; ry = ry1; } } }