Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Ron McLeod
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Beginning Java
How do I use the Timer?
Martin vanPutten
Ranch Hand
Posts: 124
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I don't know how to use the timer or where things have to be put. What I have set up already is this:
import java.applet.Applet;import java.awt.*;import java.awt.event.*;import java.util.*; /*God Slime VolleyballCreated By: Martin vanPuttenOriginal Slime Volleyball Created By: Quin Pendragon (Fractoid) and Daniel Wedge (Wedgey)*/ public class Slime extends Applet { // Slime Applet. int x = 150;int y = 440; public static void main (String [] args){MyTimerTask myTask = new MyTimerTask ();Timer myTimer = new Timer ();}public void init (){ // Initialize.setBackground (Color.red); // Background Color.addKeyListener (new KeyAdapter () // Key Listener.{ // Keys. public void keyPressed (KeyEvent ke) { // Keys Pressed. if (ke.getKeyCode () == KeyEvent.VK_LEFT) // Left. x -= 1; repaint (); if (ke.getKeyCode () == KeyEvent.VK_LEFT && x == 0) // Left Restriction. x += 1; if (ke.getKeyCode () == KeyEvent.VK_RIGHT) // Right. x += 1; repaint (); if (ke.getKeyCode () == KeyEvent.VK_RIGHT && x == 375) // Right Restriction. x -= 1; if (ke.getKeyCode () == KeyEvent.VK_UP) // Up. Timer.start (); Timer.stop (); repaint (); if (ke.getKeyCode () == KeyEvent.VK_UP && y == 330) // Up Restriction. y += 1; /* if (ke.getKeyCode () == KeyEvent.VK_LEFT && ke.getKeyCode () == KeyEvent.VK_UP) // Left && Up. x -= 1; y -= 1; if (ke.getKeyCode () == KeyEvent.VK_RIGHT && ke.getKeyCode () == KeyEvent.VK_UP) // Right && Up. x += 1; y -= 1; */ } // End Keys Pressed. } // End Keys. ); // End Key Listener. } // End Initialize. public void paint (Graphics g){ // Graphics.g.setColor (Color.black); // Ground.g.fillRect (0, 500, 1000, 100);g.setColor (Color.white); // Net.g.fillRect (495, 440, 10, 60);g.setColor (Color.black); // Controller Slime Body.g.fillArc (x, y, 120, 120, 0, 180);g.setColor (Color.yellow); // Controller Slime Eye.g.drawArc (x + 70, y + 20, 35, 20, 40, 65);/*// Computer Slime.g.setColor (Color.black); // Body.g.fillArc (730, 440, 120, 120, 0, 180);g.setColor (Color.yellow); // Eye.g.drawArc (725, 460, 70, 30, 65, 40);// End Computer Slime.g.setColor (Color.blue); // Ball.g.fillOval (195, 410, 30, 30);*/} // End Graphics.} // End Slime Applet.class MyTimerTask extends TimerTask {public void run (){ }}
I want y to stop at 330.
Live And Let Learn.
Justin Fox
Ranch Hand
Posts: 802
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I would try to help, but your code is all in one straight line,
when you fix that, I'll try and help you.
Im lazy..
-Justin-
You down with OOP? Yeah you know me!
It means our mission is in jeapordy! Quick, read this tiny ad!
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Making Y--
Problem with writing code.
Moving an object such as an arc.
slowing down movement in an applet.... doesn't have anything to do with the applet.
Computer Pad Not Stopping!
More...