Für diejenigen, die es interessiert, gibt es hier
den Java-Quelltext:
//
// ** Muehlen ** Anfang: etwa November 1998, letzte Änderung: später,
// Java Version 1.0
//
import java.awt.*;
import java.applet.*;
public class Muehlen extends Applet implements Runnable {
Thread r;
static Bild m[] = new Bild[3];
public void init() {
setBackground(Color.lightGray);
for(int i=0; i < 3; i++) {
m[i]=new Bild();
m[i].setBackground(Color.white); }
Knoepfe k = new Knoepfe();
GridBagConstraints c = new GridBagConstraints();
GridBagLayout gr = new GridBagLayout();
setLayout(gr);
c.insets=new Insets(1,1,1,1);
c.fill=c.BOTH;
c.weightx=1;
c.weighty=5;
gr.setConstraints(m[0],c);
add(m[0]);
gr.setConstraints(m[1],c);
add(m[1]);
c.gridwidth=c.REMAINDER;
gr.setConstraints(m[2],c);
add(m[2]);
c.weightx=1;
c.weighty=2;
gr.setConstraints(k,c);
add(k); }
public void start() {
if (r == null) { r = new Thread(this); r.start(); } }
public void stop() {
Frage f = new Frage();
if (r != null) { r.stop(); r=null; } }
public void run() {
while (true) {
for(int i=0; i < 3; i++) {
m[i].wa=m[i].wa+m[i].v;
m[i].buff(); }
try { Thread.sleep(10); }
catch (InterruptedException e) { }
} }
}
class Bild extends Canvas {
Color co = new Color(225,255,255); //Farbe der Mühlenflügel
int wa; //Winkel-Anfangswert
int wi = 25; //Winkel-Bogenlänge
int ho; //Höhe des Bildfenster
int br; //Breite des Bildfenster
int dm; //Durchmesser
int v = 1; //Geschwindigkeit
boolean es; //Schalter für den Punkt
Image off; //das Zwischenbild
Graphics o;
public void buff() {
Rectangle r = bounds();
if (ho != r.height || br != r.width) {
ho = r.height;
br = r.width;
off = createImage(br,ho);
o = off.getGraphics(); }
dm = (int)(br*0.7);
o.setColor(Color.white);
o.fillRect(br/2-dm/2, br/2-dm/2, dm, dm);
o.setColor(co);
o.fillArc(br/2-dm/2, br/2-dm/2, dm, dm, wa*(-1), wi);
o.fillArc(br/2-dm/2, br/2-dm/2, dm, dm, wa*(-1)+180, wi);
repaint(); }
public void update(Graphics g) {
if (es == true) g.clipRect(0,0,br,ho);
else g.clipRect(br/2-dm/2, br/2-dm/2, dm, dm);
es=false;
paint(g); }
public void paint(Graphics g) {
g.drawImage(off, 0, 0, this); }
public boolean mouseDown(Event ev, int x, int y) {
for(int i=0; i < 3; i++) {
if (this == Muehlen.m[i]) {
Knoepfe.mm = Muehlen.m[i];
Knoepfe.lb.setText(""+(i+1));
Muehlen.m[i].o.setColor(new Color(225,255,255)); }
else Muehlen.m[i].o.setColor(Color.white);
Muehlen.m[i].es=true;
Muehlen.m[i].o.fillOval(10, ho-25, 15, 15);
Muehlen.m[i].repaint(); }
Knoepfe.lw.setText(""+Knoepfe.mm.wi);
Knoepfe.lv.setText(""+Knoepfe.mm.v);
return true;
} }
class Knoepfe extends Panel {
static Bild mm;
static Label lv, lw, lb;
Button b1, b2;
Knoepfe() {
mm = Muehlen.m[0];
setLayout(new GridLayout(3,8,3,3));
add(new Label("Klaps -", Label.RIGHT));
add(new Label("Mühle "));
add(new Label("Nr.:"));
add(new Label());
lb=new Label("1");
add(lb);
add(new Label());
add(new Label());
add(new Label());
add(new Label("Farbe:"));
add(new Button("rot"));
add(new Button("blau"));
add(new Button("grün"));
add(new Button("orange"));
add(new Button("gelb"));
add(new Button("cyan"));
add(new Button("magenta"));
add(new Label("Speed:"));
lv=new Label("", Label.CENTER);
add(lv);
add(new Button("-"));
add(new Button("+"));
add(new Label("Breite:", Label.CENTER));
lw = new Label("", Label.CENTER);
add(lw);
b1 = new Button("-");
b2 = new Button("+");
add(b1);
add(b2); }
public boolean action(Event ev, Object arg) {
if (ev.target instanceof Button) {
String s = (String)arg;
if(s.equals("rot")) {mm.co=Color.red; }
if(s.equals("blau")) mm.co=Color.blue;
if(s.equals("grün")) mm.co=Color.green;
if(s.equals("orange")) mm.co=Color.orange;
if(s.equals("gelb")) mm.co=Color.yellow;
if(s.equals("+") && ev.target != b2) mm.v=mm.v+1;
if(s.equals("-") && ev.target != b1) mm.v=mm.v-1;
if(s.equals("cyan")) mm.co=Color.cyan;
if(s.equals("magenta")) mm.co=Color.magenta;
if(ev.target == b2) mm.wi=mm.wi+5;
if(ev.target == b1) mm.wi=mm.wi-5;
lw.setText(""+mm.wi);
lv.setText(""+mm.v); }
return true; }
}
class Frage extends Frame {
Frage() {
super(" ? ? ? ");
setBackground(Color.white);
setLayout(new GridLayout(2,1,20,20));
Canvas can = new C();
can.setBackground(Color.white);
can.setForeground(Color.red);
add(can);
Panel pan = new Panel();
pan.setBackground(Color.white);
add(pan);
pan.add(new Button(" N E I N ! ! ! "));
resize(450,300);
move(220,200);
show();
}
public boolean handleEvent (Event evt) {
if (evt.id == Event.ACTION_EVENT) { action(evt, evt.arg); }
if (evt.id == evt.WINDOW_DESTROY ) {
hide(); }
return false;
}
public boolean action(Event ev, Object arg) {
if (ev.target instanceof Button) {
String s = (String)arg;
if (s.equals(" N E I N ! ! ! ")) {
hide();
}
}
return true;
}
}
class C extends Canvas {
String s1 = "Möchtest du wirklich nicht mehr";
String s2 = "mit den schönen Mühlchen spielen ?";
Font f = new Font("Helvetica", Font.BOLD, 20);
int x1, x2, y1, y2;
int br;
public void paint(Graphics g) {
br = bounds().width;
FontMetrics fm = getFontMetrics(f);
int la = fm.stringWidth(s1);
x1 = (br-la)/2;
y1 = 40;
la = fm.stringWidth(s2);
x2 = (br-la)/2;
y2 = 80;
g.setFont(f);
g.drawString(s1, x1, y1);
g.drawString(s2, x2, y2);
}
}