My last post today

I have an applet created. I want it to open in full size when i run it with my IDE and if possible how can i add a 2min timer?CL
[142 byte] By [ChrisLyncha] at [2007-10-2 6:37:00]
# 1
> how can i add a 2min timer?Coddled eggs? Try java.util.Timer or javax.swing.Timer. I use the latter if I have to do gui stuff when the timer goes off.
BigDaddyLoveHandlesa at 2007-7-16 13:39:33 > top of Java-index,Java Essentials,Java Programming...
# 2
Ya i want to timer to appear on the screen and count down from 2:00 to 0 when it gets to zero i'm going to reset it to start again but also change a variable.ThanksCL
ChrisLyncha at 2007-7-16 13:39:33 > top of Java-index,Java Essentials,Java Programming...
# 3
> I have an applet created. I want it to open in full> size when i run it with my IDE and if possible how> can i add a 2min timer?Applets appear at the size defined by the appropriate tags in the embedding HTML.
ChristianMennea at 2007-7-16 13:39:33 > top of Java-index,Java Essentials,Java Programming...
# 4
> Applets appear at the size defined by the appropriate> tags in the embedding HTML.Welcome back, old-timer.
yawmarka at 2007-7-16 13:39:33 > top of Java-index,Java Essentials,Java Programming...
# 5
So it not possible for me to have it open at a larger size, without puutin it on the HTML page..
ChrisLyncha at 2007-7-16 13:39:33 > top of Java-index,Java Essentials,Java Programming...
# 6
> Welcome back, old-timer.Heya. Only in town for a short visit.
ChristianMennea at 2007-7-16 13:39:33 > top of Java-index,Java Essentials,Java Programming...
# 7
> So it not possible for me to have it open at a larger> size, without puutin it on the HTML page..I don't know what your IDE does, but usually, there is no way to run it at all without putting it into an HTML page. That's what applets are there for.
ChristianMennea at 2007-7-16 13:39:33 > top of Java-index,Java Essentials,Java Programming...
# 8
If you do not plan to put it in an HTML page you have no reason to use an applet. Use a JFrame instead, and run it as a normal application. Then you can define the size of the frame when you start your program.
happy_hippoa at 2007-7-16 13:39:33 > top of Java-index,Java Essentials,Java Programming...
# 9

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;

}

}

ChrisLyncha at 2007-7-16 13:39:33 > top of Java-index,Java Essentials,Java Programming...
# 10
This page explains how to convert an applet to a frame: http://www.faqs.org/docs/javap/c7/s7.html
happy_hippoa at 2007-7-16 13:39:33 > top of Java-index,Java Essentials,Java Programming...
# 11
Tip: Try to use more specific subject lines. The more meaningful your subject, the more meaningful your replies.
Dick_Adamsa at 2007-7-16 13:39:33 > top of Java-index,Java Essentials,Java Programming...
# 12
> > Welcome back, old-timer.> > Heya. Only in town for a short visit.Too short! :(
annie79a at 2007-7-16 13:39:33 > top of Java-index,Java Essentials,Java Programming...