Animate 2 images on the click of a button

I'm working on a script to display a short animation once the user has clicked a button; however I currently have the following error;
Cannot find method; animateTransform()
All I need is for plate1 to move South East whilst plate2 is moving North West for only a matter of seconds.
I've never worked with animation in Java so apologies in advance for the state of the code shown below;
import java.net.URISyntaxException;
import java.net.URL;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.imageio.ImageIO;
public class TransformFault2 implements ActionListener
    private static final String IMAGE_PATH = "img/transform_screen.gif";
     private static final String plate1_IMAGE_PATH = "img/transform_plate1.gif";
     private static final String plate2_IMAGE_PATH = "img/transform_plate2.gif";
     private ImageIcon animateBtn, boundsBtn;
     private JButton animateOption, boundsOption;
     private int x_1 = 225; // horiz
     private int y_1 = 265; // vert
     private int x_2 = 290;
     private int y_2 = 165;
     private boolean transformFault = false;
     private Timer timer;
     private ActionListener timerListener;
    private BufferedImage myImage = null;
     private BufferedImage plate1 = null;
     private BufferedImage plate2 = null;
    private JPanel imagePanel = new JPanel(null)
        protected void paintComponent(Graphics g)
            super.paintComponent(g);
            if (myImage != null)
                g.drawImage(myImage, 0, 0, this);
               if (plate1 != null)
                g.drawImage(plate1, x_1, y_1, this);
               if (plate2 != null)
                g.drawImage(plate2, x_2, y_2, this);
          public void animateTransform()
                    do
                         x_1 = +1;
                         y_1 = +1;
                         x_2 = -1;
                         y_2 = -1;
                    while (transformFault = true);
               repaint();     
               try
                    Thread.sleep(4000);
               catch (InterruptedException e)
    public TransformFault2()
          timerListener = new ActionListener()
           public void actionPerformed(ActionEvent actionEvent)
                    transformFault = false;
                    timer.stop();
          timer = new Timer(4000, timerListener);
          timer.setRepeats(false);
          animateBtn = new ImageIcon(getClass().getResource("img/animate.gif"));
          animateOption = new JButton(animateBtn);
          animateOption.setBorder(null);
          animateOption.setContentAreaFilled(false);
          animateOption.setSize(164,66);
          animateOption.setLocation(500,500);
          animateOption.setOpaque(false);
          animateOption.addActionListener(this);
          animateOption.setActionCommand("animate");
          boundsBtn = new ImageIcon(getClass().getResource("img/boundaries.gif"));
          boundsOption = new JButton(boundsBtn);
          boundsOption.setBorder(null);
          boundsOption.setContentAreaFilled(false);
          boundsOption.setSize(164,66);
          boundsOption.setLocation(200,500);
          boundsOption.setOpaque(false);
          boundsOption.addActionListener(this);
          boundsOption.setActionCommand("boundaries");
        imagePanel.setPreferredSize(new Dimension(800, 600));
        imagePanel.add(animateOption);
          imagePanel.add(boundsOption);
          imagePanel.setBackground(Color.WHITE);
        try
            myImage = createImage(IMAGE_PATH);
        catch (IOException e)
            e.printStackTrace();
        catch (URISyntaxException e)
            e.printStackTrace();
          try
            plate1 = createImage(plate1_IMAGE_PATH);
        catch (IOException e)
            e.printStackTrace();
        catch (URISyntaxException e)
            e.printStackTrace();
          try
            plate2 = createImage(plate2_IMAGE_PATH);
        catch (IOException e)
            e.printStackTrace();
        catch (URISyntaxException e)
            e.printStackTrace();
     public void actionPerformed(ActionEvent e)
      if(e.getActionCommand().equals("animate")) 
               timer.start();
               animateTransform();
     else if(e.getActionCommand().equals("boundaries")) 
         WOT2.contentCardLayout.show(WOT2.contentCard, "Boundaries Screen");
    private BufferedImage createImage(String path) throws IOException,
            URISyntaxException
        URL imageURL = getClass().getResource(path);
        if (imageURL != null)
            return ImageIO.read(new File(imageURL.toURI()));
        else
            return null;
    public JPanel getImagePanel()
        return imagePanel;
}Any help would be much appreciated!

When using JLabel to place the images I receive no errors when compiling or in the console upon execution; however the images do not appear on-screen.
When the animate button is clicked nothing happens but Java is crashing, so I assume there must be a problem with the loop?
Amended code can be seen below;
public class TransformFault implements ActionListener
    private static final String IMAGE_PATH = "img/transform_screen.gif";
     private ImageIcon animateBtn, boundsBtn, plate1img, plate2img;
     private JButton animateOption, boundsOption;
     private JLabel plate1, plate2;
     private int x_1 = 225; // horiz
     private int y_1 = 265; // vert
     private int x_2 = 290;
     private int y_2 = 165;
     private boolean transformFault = true;
     private Timer timer;
     private ActionListener timerListener;
    private BufferedImage myImage = null;
    private JPanel imagePanel = new JPanel(null)
        protected void paintComponent(Graphics g)
            super.paintComponent(g);
            if (myImage != null)
                g.drawImage(myImage, 0, 0, this);
    public TransformFault()
          timerListener = new ActionListener()
           public void actionPerformed(ActionEvent actionEvent)
                    transformFault = false;
                    timer.stop();
          timer = new Timer(4000, timerListener);
          timer.setRepeats(false);
          animateBtn = new ImageIcon(getClass().getResource("img/animate.gif"));
          animateOption = new JButton(animateBtn);
          animateOption.setBorder(null);
          animateOption.setContentAreaFilled(false);
          animateOption.setSize(164,66);
          animateOption.setLocation(500,500);
          animateOption.addActionListener(this);
          animateOption.setActionCommand("animate");
          boundsBtn = new ImageIcon(getClass().getResource("img/boundaries.gif"));
          boundsOption = new JButton(boundsBtn);
          boundsOption.setBorder(null);
          boundsOption.setContentAreaFilled(false);
          boundsOption.setSize(164,66);
          boundsOption.setLocation(200,500);
          boundsOption.addActionListener(this);
          boundsOption.setActionCommand("boundaries");
          plate1img = new ImageIcon(getClass().getResource("img/transform_plate1.gif"));
          plate1 = new JLabel(plate1img);
          plate1.setBorder(null);
          plate1.setOpaque(false);
          plate1.setLocation(x_1, y_1);
          plate2img = new ImageIcon(getClass().getResource("img/transform_plate2.gif"));
          plate2 = new JLabel(plate2img);
          plate2.setBorder(null);
          plate2.setOpaque(false);
          plate2.setLocation(x_2, y_2);
        imagePanel.setPreferredSize(new Dimension(800, 600));
        imagePanel.add(animateOption);
          imagePanel.add(boundsOption);
          imagePanel.add(plate1);
          imagePanel.add(plate2);
          imagePanel.setBackground(Color.WHITE);
        try
            myImage = createImage(IMAGE_PATH);
        catch (IOException e)
            e.printStackTrace();
        catch (URISyntaxException e)
            e.printStackTrace();
     public void actionPerformed(ActionEvent e)
      if(e.getActionCommand().equals("animate")) 
               timer.start();
               animateTransform();
     else if(e.getActionCommand().equals("boundaries")) 
         WOT2.contentCardLayout.show(WOT2.contentCard, "Boundaries Screen");
    private BufferedImage createImage(String path) throws IOException,
            URISyntaxException
        URL imageURL = getClass().getResource(path);
        if (imageURL != null)
            return ImageIO.read(new File(imageURL.toURI()));
        else
            return null;
    public JPanel getImagePanel()
        return imagePanel;
     public void animateTransform()
               do
                         x_1 = +1;
                         y_1 = +1;
                         x_2 = -1;
                         y_2 = -1;
               while (transformFault = true);
               imagePanel.repaint();     
               try
                    Thread.sleep(4000);
               catch (InterruptedException e)
}

Similar Messages

  • I have Pages 09 and I have  created a business card using the template but can't figure out how to duplicate it to the other 9 on the page Am and sure I am going to look daft coz its only the click of a button but I can't work it out Thanks

    I have Pages 09 and I have  created a business card using the template but can't figure out how to duplicate it to the other 9 spaces on the page. I am and sure I am going to look daft coz its only the click of a button but I can't work it out Thanks

    I do the following: Hold down the command key and highlight all the items to be reproduced. Then hold down option and drag the items from the first to each subsequent card.

  • How to Validate a User on the click of a button in Oracle APEX

    Hi,
    How to Validate a User on the click of a button in Oracle APEX.
    say for e.g: I want to allow only a specific user to go beyond after clicking on a button and restrict all the other Users. Any ideas please.
    Thanks in Advance,
    Af

    Well , the actual idea was to hide the button for specific users and show the button only for some specific users... is this possible...?
    @ AndyH: yeah, what you have suggested also fits well for my requirement... Could you please let me know how can i achieve it...
    Regards,
    Af

  • How to make an animation play on the click of a button

    Hi,
    I am trying to find an advanced action that allows me to PLAY an animation (swf) on the click of a button. Currently I am showing a swf but this does not allow the animation to play out.
    Thanks in advance,
    Liam

    Hi Lilybiri,
    Thank you for the information.
    However what I mean to say is that if you insert a standard button and try to excute "Apply effect" option on button th option will be greyed out.
    Also you can apply the "Apply effect" option on Slide either "On Slide Enter" or "On Slide Exit" option. As what i understand from "Apply effect" option is to create an event based animation triggers using the following steps:
    Select the object that is the base for the event. For example, to apply an effect to an object after a specific slide begins, select the slide.
    In the Actions panel, select Apply Effect in the On Enter or On Success drop-down lists.
    In the Object Name drop-down list, select the object to which you want to apply an effect.
    Thank you again for providing us the useful information.
    Thanks and Regards
    Loveesh

  • I want to refresh my jsf page on the click of command button.

    Hi all,
    i m using JDEV 11.1.2.1.0
    i have created one jsf page with fragment i want to refresh my whole page on the click of command button which is present in fragment page.Besause i want to refresh some field but those are present in jsf page so i cant apply partial trigger because command button property in fragment page backing bean class and those attribute which i want to refresh its property in other class.
    thanks.
    Rafat

    i didnt get you from your content so i go with subject for giving your answer
    refreshing some of the fields
    BindingContainer bindings = getBindings();
    DCIteratorBinding dciter = (DCIteratorBinding)bindings.get("xIterator");
    ViewObject vo = dciter.getViewObject();
    Row row = vo.getCurrentRow();
    vo.executeQuery();or else drop execute operation as button to execute vo.
    to refresh a page
    partial trigger nice options.
    to performs instant refresh
    af:poll component
    so if you don mine give me some scenario using hrschema i may give a liitle try to my small brain :)

  • Launching Splash Screen on the click of a button

    Situation: I have an application running, and when the user clicks a button on the main menu, a new dialog opens.
    Problem: This dialog takes awhile to load as it is retreiving information from the database etc ... hence I would like to launch a splash screen in one thread and the other dialog in a second thread.
    Following is the Splash Screen class:
    public class SplashScreen extends JWindow {
        public SplashScreen(int d) {
            duration = d;
            this.launchSplash();
        public void launchSplash() {
            JPanel content = (JPanel) getContentPane();
            content.setBackground(Color.white);
            // Set the window's bounds, centering the window
            int width = 350;
            int height = 255;
            Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
            int x = (screen.width - width) / 2;
            int y = (screen.height - height) / 2;
            setBounds(x, y, width, height);
            // Build the splash screen
            JLabel label = new JLabel();
            label.setIcon(new ImageIcon(getClass().getResource("loading.gif")) );         
            label.setHorizontalAlignment(JLabel.CENTER);    
            content.add(label, BorderLayout.CENTER);          
            // Display it
            this.setVisible(true);
            // Wait a little while, maybe while loading resources
            try {
                Thread.sleep(duration);
            } catch (Exception e) {
            this.setVisible(false);
    //        System.exit(0);
    //    public static void main(String[] args) {
    //        // Throw a nice little title page up on the screen first
    //        SplashScreen splash = new SplashScreen(10000);
    //        // Normally, we'd call splash.launchSplash() and get on
    //        // with the program. But, since this is only a test...
    //        System.exit(0);
    //    }When I run this as a standalone, it works fine (i.e. uncomment the 'main' function). But when I try to call it from another function, it doesn't launch.
    Eg: I am calling it when a button has been clicked. Code is as follows:
        public void actionPerformed(ActionEvent e) {
         SplashScreen sd = new SplashScreen(10000);
         // Calling the dialog (that takes a long time to load) here
    }Would like to know whether
    [1] is it possible to launch a splash screen on the click of a button? As usually a splash screen is done at the beginning of an application before anything is loaded. In my case an application is already running, during which a splash screen needs to be launched.
    [2] Would using the new splashscreen class of Java 6.0 support this?
    [3] If not what is the best way to approach this problem
    Appreciate any input.
    Thanks,
    Edited by: mnr on Feb 20, 2008 9:47 AM

    Thanks Michael_Dunn, I see what you mean.
    I know this is not exactly as you suggested, but when I tried the following I got a partial solution. Just wanted to know whether I am on the right track.
    I wrote a small class for the thread
    public class cSplashScreenThread extends Thread {
        public volatile boolean finished = false;
        public cSplashScreenThread(){       
    // override run() method in interface
        public void run() {
           SplashScreen sd = new SplashScreen(10000);
        }This calls the SplashScreen(code encl in earlier post).
    In the main application I added the following
    public void actionPerformed(ActionEvent e) {
    // SPLASH SCREEN
    //                    SwingUtilities.invokeLater(new Runnable() {
    //                        public void run() {
                                cSplashScreenThread sd = new cSplashScreenThread();
                                sd.start();
                                sd.finished = true;
    // DIALOG
                        SwingUtilities.invokeLater(new Runnable() {
                            public void run() {
                          DialogToCall tempDialolog = new DialogToCall(.......);
                                tempDialolog .setVisible(true);
    :When I run this in the application, the SplashScreen does indeed appear(earlier I wasn't able to see the splashScreen), and I notice (when I put a breakpoint at the pt where it calls the dialog), that it is going and creating the dialog etc, but the dialog never appears ...... after the splash screen closes, nothing else happens!
    Could you please guide me on what best to do?
    Thanks,
    Edited by: mnr on Feb 21, 2008 11:19 AM

  • Action is no getting triggered on the click of a button in an Adobe form.

    Hi All,
    I have created a Form using ALD 8.1.
    I have created a connction with the SAP using WSDL.
    The connection is getting established and it is ahowing SOAP Binding also,
    I am passing a input parameter. on the click of the button  the function module should return some values.
    But there is no effect on the execute button.
    No action is getting triggered.
    Tried establishing connection through JavaScript also.

    Cross post locked
    Rob

  • How do you get one Button to raise the Clicking of another Button?

    Hello,
    I have a hide/show region that is controlled by a button (ButtonA). This button and region is pretty far down in the page.
    So the client has requested that I created a second button (ButtonB) and place it at the very top of the page, and wants for this button (ButtonB) when clicked to 'click' the hide/show button below (ButtonA).
    Can you please advise how to do this, ex:
    <INPUT type="button" value="Show All Regions" name="ButtonB" onClick="what do I place here to raise the 'click' of button A ">.
    Any advice would be appreciated as I must demo this feature to the client tomorrow morning.
    Many thanks,
    Laura
    Edited by: user8936524 on Apr 19, 2010 4:35 AM

    Depends what type of button it is.
    If it's a button in a region position, use the optional redirect section
    Set the Target to "URL" and enter URL TArget as something like:
    javascript:function_to_call();Alternatively if its a region item button, it's a bit more tricky.
    What I did was create a new button template (copied from the standard "Button" template, called "Button - link to attribute") and replaced the
    <a href="#LINK#">bits with
    <a href="#BUTTON_ATTRIBUTES#">you can then add the code (as above) to the attribute property of the button.

  • Column going from Readonly to Editable with the click of a button.

    Hi,
    I am building an app where users will have to input some data in certain colunms, once the user finishes the data entry he will have an option to finalyze his report by clicking on a button. I am having trouble with the part of switching from a textfield to a readonly field. I ave tried to do ti through a select SQL with the APEX_ITEM.HIDDEN and APEX_ITEM.TEXT but i keep getting an missing expression error.
    Here is the code:
    SELECT
    APEX_ITEM.HIDDEN (1,a."VueR") || a."VueR" Condition,
    CASE (a."VUER")
    WHEN "-1" THEN APEX_ITEM.HIDDEN(2,a."ID_ELE15") || a."ID_ELE15" TESTLABEL
    ELSE APEX_ITEM.TEXT(2,a."ID_ELE15") TESTLABEL
    END
    FROM Budget_Main a
    WHERE upper(a."User_Director") = :APP_USER
    OR upper(a."User_Line_Manager") = :APP_USER
    With the column attributes i was able to make the column disappear once the button is clicked, but i want the user to be able to see his work .
    Thank you for the help.

    Hello:
    I am assuming that the query you posted is for a tabular form. With that said, you can use the query below
    SELECT
    APEX_ITEM.HIDDEN (1,a."VueR") || a."VueR" Condition,
    CASE
    WHEN a."VUER" ='-1' THEN APEX_ITEM.DISPLAY_AND_SAVE (2,a."ID_ELE15")  --- Display Only
    ELSE APEX_ITEM.TEXT(2,a."ID_ELE15")                                                        --- Allow Edit
    END TESTLABEL
    FROM Budget_Main a
    WHERE upper(a."User_Director") = :APP_USER
    OR upper(a."User_Line_Manager") = :APP_USERVarad

  • I have Firefox web browser but I have lost the click on Firefox " button" at the top of the monitor screen and can't get it back. How do I do that?

    I have Mozilla Firefox as my web browser. However I have just lost my Firefox "button" on the top of my monitor screen and can't get it back. How do I do that?

    Hello andytuveson, right-click on an empty section of the Tab Strip and uncheck Menu Bar in the pop-up menu.
    see : [https://support.mozilla.org/en-US/kb/display-firefox-button-menu-instead-menu-toolbar Display the Firefox button menu instead of the menu toolbar]
    thank you

  • Reset the html:messages during the click of clear button ???

    Hi,
    When i click the clear button i need to clear the <html:messages>
    that has been populated below the form??? How to do this???
    Please provide a solution for this???
    Thanks,
    JavaCrazyLover

    No replies as yet....

  • How do I remove a mouse action listener on the click of a button so it ..

    doesnt work anymore when I click on a certain area on the screen.??

    To remove all MouseListeners, call getMouseListeners () which returns an array of MouseListener objects.
    Then loop through that array and call removeMouseListener (...) passing the array element as the parameter.
    If you need to remove only one specific MouseListener added by your program, you will have to retain a reference to it, possibly as an instance field.
    db

  • Is there a way of transitioning to a random state on the click of a button?*

    Hello I'm in need of some help here with coding a button to play a transition to a random state... is this possible? I read up on a math action script that looked like it might work but I'm basically uneducated in coding. The idea is to play a random swf video I designed in aftereffects. Any help would be much appreciated. Small reward if someone can help me make it fully work!

    How are the videos laid out in your Catalyst project? Is each one in a different state? Or do you have single state that you use as your video player state?

  • Email a created text file by the click of a button

    Hi
    What I am trying to do it that: In the Front Panels, All the data is collected via String Control and other Control, then when a press saved, a text file is created and stored in the path that I specified.
    It is possible in LabView to using a Button called 'Email Created File' to then e-mail that file as an attachment.
    What VIs or example does such a thing?
    P.S. I'm deploying it to a PDA.
    Cheers

    VI below
    Attachments:
    email.vi ‏36 KB

  • Error after the click on 'reply' button

    I have an error when trying to post the reply with screenshots here. Advanced editor works fine, use it instead if you having the same issue.
    Safari 6.0.2 (8536.26.17)
    Mountain Lion 10.8.2

    even without screenshots posting, after replying to my own previous message i got this error

Maybe you are looking for