PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : [Java] FunApplet - Jeder kann mit programmieren.


Gast
2006-07-27, 23:03:30
Ich hab mal ein kleines Applet als Basis geschrieben. Jeder hier kann den Code verändern und erweitern. Mal sehen was daraus wird.


import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class FunApplet extends Applet implements Runnable {
private static final long serialVersionUID = 1250301926801856113L;

Image image;
int xPos = 0;
int yPos = 0;
private boolean stop = false;

Color bgrColor = new Color(0, 0, 0);
Color paintColor = new Color(255, 0, 0);

private int height = 500;
private int width = 500;

public void start() {
image = createImage(width, height);
this.resize(width, height);
Thread thread = new Thread(this);
thread.start();
}

public void paint(Graphics graphics) {
Graphics g = image.getGraphics();
g.setColor(bgrColor);
g.fillRect(0,0, width, height);
g.setColor(paintColor);
g.drawRect(xPos, yPos, xPos + 20, yPos + 20);

SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
String time = dateFormat.format(Calendar.getInstance().getTime());
g.drawString(time, 20, 20);

graphics.drawImage(image, 0, 0, null);
}

public void update(Graphics g) {
paint(g);
}

public void run() {
while(!stop) {
paintColor = new Color(255, yPos, xPos);
xPos += 3;
yPos += 7;
xPos %= 240;
yPos %= 240;
repaint();
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}

Gast
2006-07-28, 18:14:13
Gar nichts, wer will das schon machen?

Gast
2006-07-28, 19:15:45
Niemand.