Creating Java applet

I have to create a Java applet, but I don't know how. It should display a simulation of a running rabbit in 10 circles, explaining the For cycle in a programming language C. I tried to make it in NetBeans, but I couldn't. Can anubody please help me? Any hint, useful site or line of code... I would be very, very grateful.

Comments

  • This code is all I have:

    package org.me.hello;
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.Font;
    import java.awt.event.*;
    public class NewApplet extends Applet implements Runnable {
    int frameNumber = 0;
    int delay = 100;
    Thread animatorThread;
    boolean frozen = false;
    Color redColor;
    Color bgColor;
    Font f = new Font("TimesRoman", Font.BOLD, 20);
    public void init() {
    String str;
    addMouseListener(new MouseAdapter() {
    public void mousePressed(MouseEvent e) {
    if (frozen) {
    frozen = false;
    start();
    } else {
    frozen = true;
    stop();
    }
    }
    });
    }
    public void start() {
    if (!frozen) {
    if (animatorThread == null) {
    animatorThread = new Thread(this);
    }
    animatorThread.start();
    }
    }
    public void stop() {
    animatorThread = null;
    }
    public void run() {
    Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
    long startTime = System.currentTimeMillis();
    Thread currentThread = Thread.currentThread();
    while (currentThread == animatorThread) {
    frameNumber++;
    repaint();
    try {
    startTime += delay;
    Thread.sleep(1000);
    } catch (InterruptedException e) {
    break;
    }
    }
    }
    public void paint(Graphics g) {
    g.setFont(f);
    g.setColor(Color.red);
    g.drawString("FOR petlja", 120, 20);
    g.setColor(Color.black);
    setBackground( Color.white );
    g.drawOval(60, 60, 220, 140 );
    g.drawOval( 80, 80, 180, 100);
    g.drawString("Krug broj " + frameNumber, 20, 50);
    setBackground (Color.white);
    g.setColor (Color.blue);
    Dimension d = getSize();
    if (frameNumber % 2 == 1) {
    // On odd frames, draw the ball at the top.
    g.fillOval (70, 0, 20, 20);
    }
    else {
    g.fillOval (70, 90, 20, 20);
    }
    }
    }

    It should be made into a rabbit (instead of ball) which will ran on the drawn path and counter will count his circuits to simulate For loop. Can anybody help, please...?
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion