Color fading animation : Color « 2D Graphics GUI « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » 2D Graphics GUI » ColorScreenshots 
Color fading animation
      

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Rectangle2D;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class ColorFadingAnimation extends JPanel {
  private Rectangle2D rect = new Rectangle2D.Float(20f20f80f50f);

  private float alpha_rectangle = 1f;

  public ColorFadingAnimation() {
    new RectRunnable();
  }

  public void paint(Graphics g) {
    super.paint(g);
    Graphics2D g2d = (Graphics2Dg;
    g2d.setColor(new Color(505050));
    RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2d.setRenderingHints(rh);
    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha_rectangle));
    g2d.fill(rect);
  }

  public static void main(String[] args) {
    JFrame frame = new JFrame("Color fading aniamtion");
    frame.add(new ColorFadingAnimation());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(250150);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }

  class RectRunnable implements Runnable {
    private Thread runner;

    public RectRunnable() {
      runner = new Thread(this);
      runner.start();
    }

    public void run() {
      while (alpha_rectangle >= 0) {
        repaint();
        alpha_rectangle += -0.01f;

        if (alpha_rectangle < 0) {
          alpha_rectangle = 0;
        }
        try {
          Thread.sleep(50);
        catch (Exception e) {
        }
      }
    }
  }
}

   
    
    
    
    
    
  
Related examples in the same category
1. Color class is used to work with colors in Java 2D
2. Color Utilities: common color operations
3. Color Difference
4. Rainbow ColorRainbow Color
5. XOR colorXOR color
6. Color Gradient
7. Common color utilities
8. Drawing with Color
9. 140 colors - defined for X Window System listed in O'Reilly html pocket reference 87pp
10. Color Util
11. Color Factory
12. An efficient color quantization algorithm
13. Utility for checking colors given either hexa or natural language string descriptions.
14. Derives a color by adding the specified offsets to the base color's hue, saturation, and brightness values
15. Map colors into names and vice versa.
16. Converts a given string into a color.
17. If the color is equal to one of the defined constant colors, that name is returned instead.
18. Converts the String representation of a color to an actual Color object.
w__ww__.__j_av___a_2___s_.co__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.