Animation Trigger : Animation « Swing Components « 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 » Swing Components » AnimationScreenshots 
Animation Trigger
Animation Trigger


import java.awt.BorderLayout;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import org.jdesktop.animation.timing.triggers.ActionTrigger;
import org.jdesktop.animation.timing.triggers.FocusTrigger;
import org.jdesktop.animation.timing.triggers.FocusTriggerEvent;
import org.jdesktop.animation.timing.triggers.MouseTrigger;
import org.jdesktop.animation.timing.triggers.MouseTriggerEvent;
import org.jdesktop.animation.timing.triggers.TimingTrigger;
import org.jdesktop.animation.timing.triggers.TimingTriggerEvent;
/*
 * Triggers.java
 *
 * Created on May 3, 2007, 1:24 PM
 *
 * Copyright (c) 2007, Sun Microsystems, Inc
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above
 *     copyright notice, this list of conditions and the following
 *     disclaimer in the documentation and/or other materials provided
 *     with the distribution.
 *   * Neither the name of the TimingFramework project nor the names of its
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
import org.jdesktop.animation.timing.Animator;
import org.jdesktop.animation.timing.interpolation.PropertySetter;
/**
 *
 @author Chet
 */
public class Triggers extends JComponent {
    
    SpherePanel armed, over, action, focus, timing;
    static JButton triggerButton;
    
    /** Creates a new instance of Triggers */
    public Triggers() {
        setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
        action = new SpherePanel("yellow-sphere.png");
        focus = new SpherePanel("blue-sphere.png");
        armed = new SpherePanel("red-sphere.png");
        over = new SpherePanel("green-sphere.png");
        timing = new SpherePanel("gray-sphere.png");
        
        add(action);
        add(focus);
        add(armed);
        add(over);
        add(timing);
        
        // Add triggers for each sphere, depending on what we want to 
        // trigger them
        ActionTrigger.addTrigger(triggerButton, action.getAnimator());
        FocusTrigger.addTrigger(triggerButton,
                focus.getAnimator(), FocusTriggerEvent.IN);
        MouseTrigger.addTrigger(triggerButton, 
                armed.getAnimator(), MouseTriggerEvent.PRESS);
        MouseTrigger.addTrigger(triggerButton, 
                over.getAnimator(), MouseTriggerEvent.ENTER);
        TimingTrigger.addTrigger(action.getAnimator(),
                timing.getAnimator(), TimingTriggerEvent.STOP);
    }
    
    private static void createAndShowGUI() {
        JFrame f = new JFrame("Triggers");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setLayout(new BorderLayout());
        JPanel buttonPanel = new JPanel();
        buttonPanel.setLayout(new BorderLayout());
        // Note: "Other Button" exists only to provide another component to
        // move focus from/to, in order to show how FocusTrigger works
        buttonPanel.add(new JButton("Other Button"), BorderLayout.NORTH);
        triggerButton = new JButton("Trigger");
        buttonPanel.add(triggerButton, BorderLayout.SOUTH);
        f.add(buttonPanel, BorderLayout.NORTH);
        f.add(new Triggers(), BorderLayout.CENTER);
        f.pack();
        f.setVisible(true);
    }
    
    public static void main(String args[]) {
        Runnable doCreateAndShowGUI = new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        };
        SwingUtilities.invokeLater(doCreateAndShowGUI);
    }
    
}
/*
 * SpherePanel.java
 *
 * Created on February 19, 2007, 9:09 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */



/**
 * This class encapsulates both the rendering of a sphere, at a location
 * that may be animating, and the animation that drives the sphere
 * movement.
 *
 @author Chet
 */
class SpherePanel extends JPanel {
    
    BufferedImage sphereImage = null;
    private static final int PADDING = 5;
    private static final int PANEL_HEIGHT = 300;
    private int sphereX = PADDING, sphereY = 0;
    Animator bouncer;
    
    /**
     * The animation changes the location of the sphere over time through
     * this property setter. We force a repaint to display the sphere in
     * its new location.
     */
    public void setSphereY(int sphereY) {
        this.sphereY = sphereY;
        repaint();
    }
    
    /**
     * Load the named image and create the animator that will bounce the 
     * image down and back up in this panel.
     */
    SpherePanel(String filename) {
        try {
            URL url = getClass().getResource(filename);
            sphereImage = ImageIO.read(url);
        catch (Exception e) {
            System.out.println("Problem loading image " + filename + ": " + e);
            return;
        }
        setPreferredSize(new Dimension(sphereImage.getWidth() * PADDING, 
                PANEL_HEIGHT));
        bouncer = PropertySetter.createAnimator(2000, this, "sphereY",
                0(PANEL_HEIGHT - sphereImage.getHeight())0);
        bouncer.setAcceleration(.5f);
        bouncer.setDeceleration(.5f);
    }
    
    Animator getAnimator() {
        return bouncer;
    }
    
    @Override
    protected void paintComponent(Graphics g) {
        g.setColor(Color.white);
        g.fillRect(00, getWidth(), getHeight());
        g.drawImage(sphereImage, sphereX, sphereY, null);
    }
    
}



           
       
Filthy-Rich-Clients-Trigger.zip( 201 k)
Related examples in the same category
1. Pulse AnimationPulse Animation
2. Pulse Animation FieldPulse Animation Field
3. Fade In ButtonFade In Button
4. Fade In DemoFade In Demo
5. Morphing DemoMorphing Demo
6. Component Transition AnimationComponent Transition Animation
7. Animation By jdesktop animation
8. Animator Setup
9. Basic Race with AnimationBasic Race with Animation
10. Discrete Interpolation
11. Multi Step RaceMulti Step Race
12. NonLinear Race DemoNonLinear Race Demo
13. Setter Race AnimationSetter Race Animation
14. Spline Interpolator TestSpline Interpolator Test
15. Trigger Race AnimationTrigger Race Animation
16. Tumble Item Project
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.