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 01-12-2008, 09:12 PM
Member
 
Join Date: Jan 2008
Posts: 2
angel_eyez is on a distinguished road
flicker
//christmas tree
window.setColor(Color.green);
int[] tCoordinates = {210, 190, 200, 189, 195, 185, 175, 180, 165, 175, 155};
int[] sCoordinates = {230, 210, 210, 195, 195, 185, 195, 195, 210, 210, 230};
window.fillPolygon(tCoordinates, sCoordinates, tCoordinates.length);

Color newColor1 = new Color(88,58,31);
window.setColor(newColor1);
window.fillRect(173, 230, 15, 27);

//christmas tree ornaments
window.setColor(Color.red);
window.fillOval(178, 200, 07, 05);

Color newColor2 = new Color(15,89,4);
window.setColor(newColor2);
window.fillOval(181, 210, 07, 05);


window.setColor(Color.red);
window.fillOval(184, 220, 07, 05);



How do I make the ornaments flicker a different color? (red, green, blue, yellow, etc. [animation]) Using Thread.sleep?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-13-2008, 07:29 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 334
tim is on a distinguished road
Threads
Hello angel_eyez

Let your window be extended from the Thread class. You will need to override (or implement) to run() method. In the constructor of your window, call the start() method:
Code:
public void run(){ try{ Thread.sleep(100); } catch (Exception e) { // we normally ignore these exceptions } // Add your animation code here: }
Just ask if you need more help.
__________________
If your ship has not come in yet then build a lighthouse.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-13-2008, 07:50 PM
Member
 
Join Date: Jan 2008
Posts: 24
afsina is on a distinguished road
tim: i think this is a bad idea to use Threads in Swing-AWT applications like that. you dont need to make your class extending a "Thread " for only using the sleep method. Thread.sleep() can be used arbitrarily in any class. Of course, this is not the best solution for the problem. Original pster may want to check the Swing Timers, or other timer facilities.

Last edited by afsina : 01-13-2008 at 07:54 PM.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-14-2008, 11:52 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 334
tim is on a distinguished road
Quote:
Originally Posted by afsina View Post
tim: i think this is a bad idea to use Threads in Swing-AWT applications like that. you dont need to make your class extending a "Thread " for only using the sleep method. Thread.sleep() can be used arbitrarily in any class. Of course, this is not the best solution for the problem. Original pster may want to check the Swing Timers, or other timer facilities.
It depends on the programmer's style how he or she wants to implement threading. Many other programmers and books use this method. I, however, prefer to implement the Runnable interface. I understand what you mean by extending swing or AWT components as I have encountered threading problems in other languages like Borland Delphi.

Thank you
__________________
If your ship has not come in yet then build a lighthouse.
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
Alpha Fade Flicker jamesfrize Java Applets 3 04-02-2008 03:02 PM
Flicker flicker! angel_eyez Java 2D 1 01-13-2008 08:52 AM


All times are GMT +3. The time now is 09:43 AM.


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