Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-20-2008, 07:43 PM
Member
 
Join Date: Mar 2008
Posts: 2
pcman is on a distinguished road
the code dosent work
i try to do a animation....
all 10 minutes i need to repaint and drew the oval again after some of time
i think the problam here
Code:
t.sleep( 1000 );
the code:
Code:
import java.applet.*; import java.awt.*; public class ok extends Applet implements Runnable { int y; Thread t = null; public void paint(Graphics g) { while(y > 500) { g.fillOval(100, y, 50, 50); y = y+10; t.sleep( 1000 ); repaint(); } } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-20-2008, 09:20 PM
Senior Member
 
Join Date: Jul 2007
Posts: 910
hardwired is on a distinguished road
Code:
// <applet code="OkAnimation" width="300" height="300"></applet> // use: >appletviewer OkAnimation.java import java.applet.*; import java.awt.*; public class OkAnimation extends Applet implements Runnable { int y; int dy = 10; Thread t = null; boolean isRunning = false; /** Applet method override */ public void paint(Graphics g) { Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.fillOval(100, y, 50, 50); } /** Applet method override */ public void start() { if(!isRunning) { isRunning = true; t = new Thread(this); t.start(); } } /** Applet method override */ public void stop() { isRunning = false; if(t != null) t.interrupt(); // wake up t = null; } /** Runnable interface implementation */ public void run() { while(isRunning) { try { t.sleep( 1000 ); } catch(InterruptedException e) { stop(); } if(y + dy < 0 || y + 50 + dy > getHeight()) { // if the next move puts us out of bounds // reverse direction. dy *= -1; } y = y+dy; repaint(); } } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pass by ref. A work around? diRisig New To Java 0 02-05-2008 08:25 PM
how would i get this to work...? deeadeed New To Java 6 12-06-2007 03:58 AM
what do I have to install to work with JSP boy22 JavaServer Pages (JSP) and JSTL 1 08-05-2007 05:08 AM
My own ClassLoader didn't work. snooze-g Advanced Java 1 07-17-2007 12:12 PM
Generating Code Automatically Using Custom code Template In Eclipse JavaForums Eclipse 1 04-26-2007 04:52 PM


All times are GMT +3. The time now is 11:59 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org