I was thinking about that but i'm new to this.. If i was to attempt to convert my code to a Jframe it would take my hours even days.. Have a look at it how long roughly should it take
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.Timer;
public class CatchThecreature extends Applet implements Runnable, MouseListener
{
protected static int playWidth = 500;
protected static int playHeight = 500;
protected static int Xstart = 50;
protected static int Ystart = 50;
private Dimension appletSize;
private Image offscreenBuffer;
public Graphics g1, g2;
public int level = 0;
private Image creature;
private Thread creatureLoop;
public Creature mycreature;
//Timer timer = new timer();
public void init()
{
g2 = getGraphics();
appletSize = getSize();
offscreenBuffer = createImage(appletSize.width = 2000 , appletSize.height = 2000 );
g1 = offscreenBuffer.getGraphics();
creature = getImage(getDocumentBase(), "europe.gif");
mycreature = new Creature(0, 0, creature);
creatureLoop = new Thread(this);
creatureLoop.start();
this.addMouseListener(this);
}
public void run()
{
int delay = 0,i = 0;
while (true)
{
if(i < 120)
{
//level 1
delay = (int)(.01 * 2000) + 500;
}
else
{
//level 2
delay = (int)(.2 * 2000) + 500;
}
i++;
mycreature.newLocation();
paint(g2);
try {creatureLoop.sleep(delay);
}
catch (InterruptedException e) {}
if (mycreature.visible)
{
mycreature.visible = false;
}
else
{
mycreature.visible = true;
//calls the attempt function in the Creature Class
mycreature.attempts();
//calls the per function in the Creature Class
mycreature.percentage();
}
}
}
public void paint(Graphics g)
{
// Clear the drawing area
g1.setColor(Color.BLACK);
g1.fillRect(0, 0, appletSize.width, appletSize.height);
// Outline the playfield
g1.setColor(Color.white);
g1.drawRect(Xstart, Ystart, playWidth, playHeight);
// Display the hitcount
mycreature.displayCount(g1);
// Display the creature if it's visible
if (mycreature.visible)
mycreature.display(g1);
// Blit the buffer
g.drawImage(offscreenBuffer, 0, 0, null);
}
//listens for the mouse click to determine if the creature was hit
public void mouseClicked(MouseEvent e)
{
if (mycreature.checkClick(e.getX(), e.getY()))
{
paint(g2);
}
}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
}
class Creature
{
private int x, y;
private static float hits = 0;
private static float attempts = 0;
private static float percentage = 0;
private Image creature;
public boolean visible = true;
public int time = 0;
public Creature(int x, int y, Image creature)
{
this.x = x;
this.y = y;
this.creature = creature;
}
public void display(Graphics g)
{
g.drawImage(creature, CatchThecreature.Xstart + x, CatchThecreature.Xstart + y, null);
}
public void displayCount(Graphics g)
{
g.setColor(Color.red);
g.drawString("Hits: " + hits, 200, 28);
g.drawString("Attempts: " + attempts, 50, 28);
g.drawString("Percentage of hits: " + percentage, 50, 48);
}
public void newLocation()
{
x = (int)(Math.random() * (CatchThecreature.playWidth-50));
y = (int)(Math.random() * (CatchThecreature.playHeight-50));
}
public boolean checkClick(int clickX, int clickY)
{
int checkX = clickX - CatchThecreature.Xstart;
int checkY = clickY - CatchThecreature.Ystart;
if (( checkX < x + 50) && ( checkX > x) && (checkY > y) && (checkY < y + 50) && (visible))
{
hits++;
visible = false;
return true;
}
else
{
return false;
}
}
public void attempts()
{
attempts++;
}
public void percentage()
{
percentage = (hits/attempts)*100;
}
}