Results 1 to 4 of 4

Thread: flicker

  1. #1
    angel_eyez is offline Member
    Join Date
    Jan 2008
    Posts
    2
    Rep Power
    0

    Default 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?

  2. #2
    tim's Avatar
    tim
    tim is offline Senior Member
    Join Date
    Dec 2007
    Posts
    435
    Rep Power
    7

    Default 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:
    Java 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. :D
    Eyes dwelling into the past are blind to what lies in the future. Step carefully.

  3. #3
    afsina is offline Member
    Join Date
    Jan 2008
    Posts
    24
    Rep Power
    0

    Default

    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 06:54 PM.

  4. #4
    tim's Avatar
    tim
    tim is offline Senior Member
    Join Date
    Dec 2007
    Posts
    435
    Rep Power
    7

    Default

    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 ;)
    Eyes dwelling into the past are blind to what lies in the future. Step carefully.

Similar Threads

  1. Alpha Fade Flicker
    By jamesfrize in forum Java Applets
    Replies: 3
    Last Post: 04-02-2008, 02:02 PM
  2. Flicker flicker!
    By angel_eyez in forum Java 2D
    Replies: 1
    Last Post: 01-13-2008, 07:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •