Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7966983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:34:44+00:00 2026-06-04T06:34:44+00:00

I need one colour fading example which is written in Java. My requirement is

  • 0

I need one colour fading example which is written in Java.
My requirement is I have two rectangles. One is filled up with colour red and another is filled up with white. When I click any button, I want that red colour to start fading and moving green colour. Once it is reached to green position then automatically another rectangle should start from yellow blue. Could anybody help me on this? If any example got which is written in Javaswing or SWT will be good. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T06:34:45+00:00Added an answer on June 4, 2026 at 6:34 am

    Checkout Trident animation library. It allows you to easily interpolate properties in your class. Also check these original tutorials from Kirill Grouchnikov (the author of Trident).

    EDIT: animation example w/o Trident

    The following sample is based on AnimatedGraphics example in Filthy Rich Clients:

    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.SwingUtilities;
    import javax.swing.Timer;
    
    public class AnimatedGraphics extends JComponent implements ActionListener {
    
        Color startColor = Color.RED;   // where we start
        Color endColor = Color.GREEN;         // where we end
        Color currentColor = startColor;
        int animationDuration = 2000;   // each animation will take 2 seconds
        long animStartTime;         // start time for each animation
    
        public AnimatedGraphics() {
            Timer timer = new Timer(30, this);
            // initial delay while window gets set up
            timer.setInitialDelay(1000);
            animStartTime = 1000 + System.nanoTime() / 1000000;
            timer.start();
        }
    
        public void paintComponent(Graphics g) {
            g.setColor(getBackground());
            g.fillRect(0, 0, getWidth(), getHeight());
            g.setColor(currentColor);
            g.fillOval(0, 0, getWidth(), getHeight());
        }
    
        public void actionPerformed(ActionEvent ae) {
            // calculate elapsed fraction of animation
            long currentTime = System.nanoTime() / 1000000;
            long totalTime = currentTime - animStartTime;
            if (totalTime > animationDuration) {
                animStartTime = currentTime;
            }
            float fraction = (float)totalTime / animationDuration;
            fraction = Math.min(1.0f, fraction);
            // interpolate between start and end colors with current fraction
            int red = (int)(fraction * endColor.getRed() + 
                    (1 - fraction) * startColor.getRed());
            int green = (int)(fraction * endColor.getGreen() + 
                    (1 - fraction) * startColor.getGreen());
            int blue = (int)(fraction * endColor.getBlue() + 
                    (1 - fraction) * startColor.getBlue());
            // set our new color appropriately
            currentColor = new Color(red, green, blue);
            // force a repaint to display our oval with its new color
            repaint();
        }
    
        private static void createAndShowGUI() {    
            JFrame f = new JFrame("Animated Graphics");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setSize(200, 200);
            f.add(new AnimatedGraphics());
            f.setVisible(true);
        }
    
        public static void main(String args[]) {
            Runnable doCreateAndShowGUI = new Runnable() {
                public void run() {
                    createAndShowGUI();
                }
            };
            SwingUtilities.invokeLater(doCreateAndShowGUI);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Flex button. I need one color on the left and another
I have a class that contains objects of two other classes. I need one
need some help with this one. I have some reflectance values for a colour
I have two spreadsheets, one is a backup from an ecommerce store which contains
Someone have any sample of Comet app .net? I need one sample how to
I need from one JSP open another JSP, and send POST parameters to this
I need two methods one to encrypt and one to decrypt an xml file
I am creating a colour chooser and need to modify one of the colour
I have a narrow header in corporate colour, bright red, with the content below
I have data with a best fit line draw. I need to draw two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.