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, 08:23 PM
Member
 
Join Date: Jan 2008
Posts: 2
angel_eyez is on a distinguished road
Flicker 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?

Last edited by angel_eyez : 01-12-2008 at 08:26 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-13-2008, 08:52 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,189
hardwired is on a distinguished road
Code:
import java.awt.*; import java.util.Random; import javax.swing.*; public class FlickerTest extends JPanel implements Runnable { 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 }; Color[] colors = { Color.red, Color.orange, Color.blue, Color.yellow, new Color(15,89,4) }; Random seed = new Random(); int[] indices = { 1, 2, 3 }; protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.green); g2.fillPolygon(tCoordinates, sCoordinates, tCoordinates.length); g2.setColor(new Color(88,58,31)); g2.fillRect(173, 230, 15, 27); //christmas tree ornaments g2.setColor(colors[indices[0]]); g2.fillOval(178, 200, 07, 05); g2.setColor(colors[indices[1]]); g2.fillOval(181, 210, 07, 05); g2.setColor(colors[indices[2]]); g2.fillOval(184, 220, 07, 05); } private void updateIndices() { for(int j = 0; j < indices.length; j++) { int index = indices[j]; do { index = seed.nextInt(colors.length); } while(index == indices[j]); indices[j] = index; } } private void start() { new Thread(this).start(); } public void run() { boolean flickering = true; while(flickering) { try { Thread.sleep(1000); } catch(InterruptedException e) { flickering = false; } updateIndices(); repaint(); } } public static void main(String[] args) { FlickerTest test = new FlickerTest(); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(test); f.setSize(400,400); f.setLocation(200,200); f.setVisible(true); test.start(); } }
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 angel_eyez New To Java 3 01-14-2008 11:52 PM


All times are GMT +3. The time now is 02:22 AM.


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