import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class Rectangle extends Applet implements MouseListener
{
private static final long serialVersionUID = 1L;
int xpos, ypos, rectxco, rectyco, rectwidth, rectheight, ovalxco, ovalyco, ovalwidth, ovalheight,
arcxco, arcyco, arcwidth, archeight, time, score = 0;
int[] polycox = new int[4];
int[] polycoy = new int[4];
int click = 0;
Random rnd = new Random();
Font font;
public void init()
{
addMouseListener(this);
font = new Font("Arial", Font.BOLD, 16);
java.util.Timer timerUtil = new java.util.Timer();
timerUtil.scheduleAtFixedRate(new TimerTask()
{
public void run()
{
time++;
if(score>0 && score<40 && score!=1)
{
Graphics g = getGraphics();
g.setFont(font);
g.setColor(Color.blue);
g.fillRect(55, 350, 40, 20);
g.setColor(Color.black);
g.drawString("Zeit: "+time, 20, 370);
}
}
}, 0, 1000);
}
public void paint(Graphics g)
{
paint();
}
public void paint()
{
Graphics g = getGraphics();
setBackground(Color.blue);
g.drawString("Klicken Sie auf das rote Viereck, um Punkte zu bekommen!", 20, 20);
g.setColor(Color.blue);
g.fillRect(0, 0, 350, 350);
rectxco = rnd.nextInt(200)+40;
rectyco = rnd.nextInt(200)+40;
rectwidth = rnd.nextInt(30)+10;
rectheight = rnd.nextInt(30)+2;
ovalxco = rnd.nextInt(200)+40;
ovalyco = rnd.nextInt(200)+40;
ovalwidth = rnd.nextInt(30)+10;
ovalheight = rnd.nextInt(30)+2;
arcxco = rnd.nextInt(200)+40;
arcyco = rnd.nextInt(200)+40;
arcwidth = rnd.nextInt(30)+10;
archeight = rnd.nextInt(30)+2;
for(int i=0; i<polycox.length; i++)
{
polycox[i] = rnd.nextInt(100)+1;
}
for(int j=0; j<polycoy.length; j++)
{
polycoy[j] = rnd.nextInt(100)+1;
}
g.setFont(font);
g.setColor(Color.black);
g.drawString("Klicken Sie auf das rote Viereck, um Punkte zu bekommen!", 20, 20);
g.setColor(Color.red);
g.fillRect(rectxco, rectyco, rectwidth, rectheight);
if(score==0)
{
time = 0;
}
if(score>=9)
{
g.setColor(Color.red);
g.fillOval(ovalxco, ovalyco, ovalwidth, ovalheight);
}
if(score==9)
{
g.setColor(Color.black);
g.drawString("Sie erreichen Level 2", 20, 40);
}
if(score>=19)
{
g.setColor(Color.red);
g.fillArc(arcxco, arcyco, arcwidth, archeight, 300, 300);
}
if(score==19)
{
g.setColor(Color.black);
g.drawString("Sie erreichen Level 3", 20, 40);
}
if(score>=29)
{
g.setColor(Color.red);
g.fillPolygon(polycox, polycoy, 4);
}
if(score==29)
{
g.setColor(Color.black);
g.drawString("Sie erreichen Level 4", 20, 40);
}
if(score==39)
{
g.setColor(Color.gray);
g.fillRect(0, 0, 640, 640);
g.setColor(Color.black);
g.drawString("Fertig!", 20, 40);
g.drawString("Ihre Zeit: "+time+" Sekunden", 20, 60);
g.drawString("Klicken, um fortzufahren ...", 20, 100);
score=0;
}
if(click==1)
{
score++;
g.setColor(Color.black);
g.drawString("Punkte: "+score, 20, 350);
}
else if(click==2)
{
score--;
g.setColor(Color.black);
g.drawString("Punkte: "+score, 20, 350);
}
}
public void mouseClicked(MouseEvent me)
{
xpos = me.getX();
ypos = me.getY();
if (xpos > rectxco && xpos < rectxco+rectwidth && ypos >rectyco && ypos < rectyco+rectheight)
{
click = 1;
}
else
{
click = 2;
}
paint();
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
}