Animation Delay`

Hi,
I have a logo that I am animating here: http://agtdesigns.co.uk/logo.gif
Basically I want the man to spin inside the circle. However, on the last frame/state of the animation it appears to stop/delay before moving onto the next frame. To solve this I set the delay for the last state to 0. When palying back the animation in Fireworks it is perfectly smooth with no delay.
However when exporting the file the delay is still there, I have the 'include when exporting' option ticked for the last frame but it doesnt seem to be working.
I am using Fireworks CS5, any help would be greatly appreciated.
tia,
Andy

Nevermind, I realised I had a duplicate frame at the end.

Similar Messages

  • Animations delays 1 frame with gotoAndPlay() in CS3

    Hello people! Has anybody found this problem with timeline
    animations in Flash CS3?
    I have an animation that when it reaches frame 10 does a
    gotoAndPlay(5) but when the head goes to frame 5 it shows the frame
    twice and then goes to the next frame, so the animation delays 1
    frame.
    If you want to check it out, put the movie at 1fps to see the
    delay easily.
    This doesn't happen in Flash 8. But it does in Flash CS3.
    Anyone knows a solution?

    I posted this issue:
    http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?catid=288&threadid=1301078
    sounds like the same AS3 issue ; (

  • Animated GIF files, anyone had issues with the selected animation delay not saving as specified?

    I am working on PSE 9 for Mac and have created my psd file with the layers.
    Selected 'Save for Web' and chose GIF as the file format.
    Ticked 'Animation', then from the bottom right hand corner under 'Animation' I have ticked 'loop' and in the 'delay' drop down selected 2.0 (so 2 seconds).
    When I check the file in 'preview in' web it shows the file flashing faster than 2 seconds a frame. I also checked it by uploading it onto my website and it is flashing faster than 2 seconds.
    I have saved the file several times to check. It appears that even though you are given a choice that is automatically saves the delay at the auto-populated delay speed of 0.2 seconds.
    Thoughts anyone?

    As far as i know, the frame delay has been broken
    for several versions on the mac pse.
    Since version 4 maybe?
    You can comment on this post and hopefully adobe will fix it in pse 10.
    http://feedback.photoshop.com/photoshop_family/topics/photoshop_elements_9_mac_frame_delay _in_save_for_web
    MTSTUNER

  • Frame(sprite) animation delay problem

    import javax.microedition.lcdui.*;
    import javax.microedition.lcdui.game.*;
    public class ExampleTrialCanvas extends GameCanvas implements Runnable {
    private boolean isPlay; // Game Loop runs when isPlay is true
    private long delay; // To give thread consistency
    private int currentX, currentY; // To hold current position of the 'X'
    private int width; // To hold screen width
    private int height; // To hold screen height
    // Sprites to be used
    // private Sprite playerSprite;
    private Sprite backgroundSprite;
    private Sprite playerSprite;
    //private int i;
    // Layer Manager
    private LayerManager layerManager;
    // Constructor and initialization
    public ExampleTrialCanvas() throws Exception {
    super(true);
    width = getWidth();
    height = getHeight();
    currentX = 64;
    currentY = 150;
    delay = 100;
    // Load Images to Sprites
    Image playerImage = Image.createImage("/transparent.png");
    playerSprite = new Sprite (playerImage,32,32);
    Image backgroundImage = Image.createImage("/gillete.png");
    backgroundSprite = new Sprite(backgroundImage);
    layerManager = new LayerManager();
    layerManager.append(playerSprite);
    layerManager.append(backgroundSprite);
    // Automatically start thread for game loop
    long now, prev_time_moved;
    public void init(){
    now = System.currentTimeMillis();
    prev_time_moved = now;
    public void start() {
    isPlay = true;
    Thread t = new Thread(this);
    t.start();
    public void stop() { isPlay = false; }
    // Main Game Loop
    public void run() {
    Graphics g = getGraphics();
    while (isPlay == true) {
    input();
              drawScreen(g);
    try { Thread.sleep(delay); }
    catch (InterruptedException ie) {}
    // Method to Handle User Inputs
    private void input()
    int keyStates = getKeyStates();
    playerSprite.setFrame(0);
    // Up
    if ((keyStates & UP_PRESSED) != 0) {
         for(int i=0;i<5;i++)
         playerSprite.setFrame(i);
    // Method to Display Graphics
    private void drawScreen(Graphics g) {
    // updating player sprite position
    playerSprite.setPosition(currentX,currentY);
    // display all layers
    layerManager.paint(g,0,0);
    layerManager.setViewWindow(55,20,180,180);
    //layerManager.paint(g,20,20);
    flushGraphics();
    We want, on right click botton press the frame should animate.
    We have a player with 5 different poses, kicking a ball, "image width is 160, height is 32".
    the problem is that, the player does move through allthe frames. he starts from 0th p\frame and directly end at the last frame, withopur any delay between frames.
    we have used the for loop as follows.
    if ((keyStates & UP_PRESSED) != 0) {
         for(int i=0;i<5;i++)
         playerSprite.setFrame(i);
    we want a delay code between all the frames.

    Maybe this will help you!
    btnSignIn.addActionListener(new ActionListener()     
                                  public void actionPerformed(ActionEvent e)
                                      //display the glasspane first
                                      setGlassPane(new MyGlassPane(newAnimatedIcon("images/LoginWaitingIcon.png")));
                                      getupGlasPane.setVisible(true);        //expected the glassPane shows (it does), and the animation starts (it doesnt)
                                      Thread t1 = new Thread(new Runnable()    //The animation only starts when this thread finished
                                            public void run()
                                                 //DO THE REST
    t1.start();
    t1.join();
    setupGlasPane(false);   //finish, turning off
                       });

  • PSE8 for Mac Trying to create animated GIF.  Why can't I change the animation delay?

    I am trying to create an animated GIF for the first time.  Finally figured out most of it, but it won't let me change the speed from 0.2 which is waaaay too fast.

    Welcome to iMovie Discussions.
    See my 2nd reply to 'getzcreative', here.

  • Animated GIF image gets distorted while playing.

    Hi,
    I have some animated gif images which I need to show in a jLabel and a jTextPane. But some of these images are getting distorted while playing in the two components, though these images are playing properly in Internet Explorer. I am using the methods insertIcon() of jTextPane and setIcon() of jLabel to add or set the gif images in the two components. Can you please suggest any suitable idea of how I can get rid of this distortion? Thanks in advance.

    In the code below is a self contained JComponent that paints a series of BufferedImages as an animation. You can pause the animation, and you specify the delay. It also has two static methods for loading all the frames from a File or a URL.
    Feel free to add functionality to it, like the ability to display text or manipulate the animation. You may wan't the class to extend JLabel instead of JComponent. Just explore around with the painting. If you have any questions, then feel free to post.
    The downside to working with an array of BufferedImages, though, is that they consume more memory then a single Toolkit gif image.
    import javax.swing.JComponent;
    import java.awt.image.BufferedImage;
    import java.awt.Graphics;
    import javax.imageio.ImageIO;
    import javax.imageio.ImageReader;
    import javax.imageio.stream.ImageInputStream;
    public class JAnimationLabel extends JComponent {
        /**The default animation delay.  100 milliseconds*/
        public static final int DEFAULT_DELAY = 100;
        private BufferedImage[] images;
        private int currentIndex;
        private int delay;
        private boolean paused;
        private boolean exited;
        private final Object lock = new Object();
        //the maximum image width and height in the image array
        private int maxWidth;
        private int maxHeight;
        public JAnimationLabel(BufferedImage[] animation) {
            if(animation == null)
                throw new NullPointerException("null animation!");
            for(BufferedImage frame : animation)
                if(frame == null)
                    throw new NullPointerException("null frame in animation!");
            images = animation;
            delay = DEFAULT_DELAY;
            paused = false;
            for(BufferedImage frame : animation) {
                maxWidth = Math.max(maxWidth,frame.getWidth());
                maxHeight = Math.max(maxHeight,frame.getHeight());
            setPreferredSize(new java.awt.Dimension(maxWidth,maxHeight));
        //This method is called when a component is connected to a native
        //resource.  It is an indication that we can now start painting.
        public void addNotify() {
            super.addNotify();
            //Make anonymous thread run animation loop.  Alternative
            //would be to make the AnimationLabel class extend Runnable,
            //but this would allow innapropriate use.
            exited = false;
            Thread runner = new Thread(new Runnable() {
                public void run() {
                    runAnimation();
            runner.setDaemon(true);
            runner.start();
        public void removeNotify() {
            exited = true;
            super.removeNotify();
        /**Returns the animation delay in milliseconds.*/
        public int getDelay() {return delay;}
        /**Sets the animation delay between two
         * consecutive frames in milliseconds.*/
        public void setDelay(int delay) {this.delay = delay;}
        /**Returns whether the animation is currently paused.*/
        public boolean isPaused() {
            return exited?true:paused;}
        /**Makes the animation paused or resumes the painting.*/
        public void setPaused(boolean paused) {
            synchronized(lock) {
                this.paused = paused;
                lock.notify();
        private void runAnimation() {
            while(!exited) {
                repaint();
                if(delay > 0) {
                    try{Thread.sleep(delay);}
                    catch(InterruptedException e) {
                        System.err.println("Animation Sleep interupted");
                synchronized(lock) {
                    while(paused) {
                        try{lock.wait();}
                        catch(InterruptedException e) {}
        public void paintComponent(Graphics g) {
            if(g == null) return;
            java.awt.Rectangle bounds = g.getClipBounds();
            //center image on label
            int x = (getWidth()-maxWidth)/2;
            int y = (getHeight()-maxHeight)/2;
            g.drawImage(images[currentIndex], x, y,this);
            if(bounds.x == 0 && bounds.y == 0 &&
               bounds.width == getWidth() && bounds.height == getHeight()) {
                 //increment frame for the next time around if the bounds on
                 //the graphics object represents a full repaint
                 currentIndex = (currentIndex+1)%images.length;
            }else {
                //if partial repaint then we do not need to
                //increment to the the next frame
    }

  • Edge Commons to trigger CSS animation in SVG?

    Hi there,
    I have an SVG file that has a sequence of 2 CSS animations within it:
    <defs>
    <style type="text/css">
         .t1a {
    stroke-dasharray:537;
    stroke-dashoffset:537;
    -webkit-animation: t1a 2s linear forwards;
    <!-- Animation lines-->
    @-webkit-keyframes t1a {
    from {
    stroke-dashoffset: -537;
    to {
    stroke-dashoffset: 0;
         .t2a {
    stroke-dasharray:544;
    stroke-dashoffset:544;
    -webkit-animation: t2a 2s linear forwards;
    -webkit-animation-delay: 2s;
    <!-- Animation lines-->
    @-webkit-keyframes t2a {
    from {
    stroke-dashoffset: -544;
    to {
    stroke-dashoffset: 0;
    </style>
    </defs>
    The items touched by these CSS are 2 lines:
    <line id="t1a" fill="none" stroke="#000000" stroke-width="0.391" stroke-miterlimit="3.864" x1="282.5" y1="999" x2="423.2" y2="480.3"/>
    <line id="t2a" fill="none" stroke="#000000" stroke-width="0.391" stroke-miterlimit="3.864" x1="949.1" y1="622.2" x2="423.2" y2="480.3"/>
    I'd like to have 2 buttons on Animate to start the 2 animations. I mean that I was thinking to apply and remove the classes to the ids in some way. I think that maybe with Edge Commons this is possible. So, summarizing, I need to manipulate some ids in the SVG and apply those classes to them. Is it possible?

    Have you tried the Adobe forums also?  E.g. I saw
    http://forums.adobe.com/message/4718924

  • Help with "Exception in thread "Thread-4" java.lang.NullPointerException"

    I am new to Java and I am trying a simple bouncing ball example from Stanford. Here is their simple example that works.
    import acm.program.*;
    import acm.graphics.*;
    import java.awt.*;
    public class BouncingBallWorking extends GraphicsProgram {
    /** sets diameter */
    private static final int DIAM_BALL = 30;
    /** amount y velocity is increased each cycle */
    private static final double GRAVITY = 3;
    /** Animation delay or pause time between ball moves */
    private static final int DELAY = 50;
    /** Initial X and Y location ball*/
    private static final double X_START = DIAM_BALL / 2;
    private static final double Y_START = 100;
    private static final double X_VEL = 3;
    private static final double BOUNCE_REDUCE = 0.9;
    private double xVel = X_VEL;
    private double yVel = 0.0;
    private GOval BallA;
    public void run() {
    setup(X_START,Y_START);
    //         Simulation ends when ball goes off right hand
    //         end of screen
    while (BallA.getX() < getWidth()) {
    moveBall(BallA);
    checkForCollision(BallA);
    pause(DELAY);
    private void setup(double X_coor, double Y_coor) {
    BallA = new GOval(X_coor, Y_coor, DIAM_BALL, DIAM_BALL);
    add(BallA);
    private void moveBall(GOval BallObject) {
    yVel += GRAVITY;
    BallObject.move(xVel,yVel);
    private void checkForCollision(GOval BallObject) {
    if(BallObject.getY() > getHeight() - DIAM_BALL){
    yVel = - yVel * BOUNCE_REDUCE;
    double diff = BallObject.getY() - (getHeight() - DIAM_BALL);
    BallObject.move(0, -2 * diff);
    } Now I am trying to modify "setup" so it I can create several balls. I made a simple modification to "setup" and now I am getting an error.
    "Exception in thread "Thread-4" java.lang.NullPointerException
    at BouncingBallNotWorking.run(BouncingBallNotWorking.java:36)
    at acm.program.Program.runHook(Program.java:1592)
    at acm.program.Program.startRun(Program.java:1581)
    at acm.program.AppletStarter.run(Program.java:1939)
    at java.lang.Thread.run(Unknown Source)"
    Can you describe why I am getting an error? Thanks.
    Here is what I changed.
    Before:
         private void setup(double X_coor, double Y_coor) {
              BallA = new GOval(X_coor, Y_coor, DIAM_BALL, DIAM_BALL);
              add(BallA);
         }After:
         private void setup(double X_coor, double Y_coor, GOval BallObject) {
              BallObject = new GOval(X_coor, Y_coor, DIAM_BALL, DIAM_BALL);
              add(BallObject);
         }Here is the complete code.
    * File:BouncingBall.java
    * This program graphically simulates a bouncing ball
    import acm.program.*;
    import acm.graphics.*;
    import java.awt.*;
    public class BouncingBallNotWorking extends GraphicsProgram {
    /** sets diameter */
    private static final int DIAM_BALL = 30;
    /** amount y velocity is increased each cycle */
    private static final double GRAVITY = 3;
    /** Animation delay or pause time between ball moves */
    private static final int DELAY = 50;
    /** Initial X and Y location ball*/
    private static final double X_START = DIAM_BALL / 2;
    private static final double Y_START = 100;
    private static final double X_VEL = 3;
    private static final double BOUNCE_REDUCE = 0.9;
    private double xVel = X_VEL;
    private double yVel = 0.0;
    private GOval BallA;
    public void run() {
    setup(X_START,Y_START, BallA);
    //         Simulation ends when ball goes off right hand
    //         end of screen
    while (BallA.getX() < getWidth()) {
    moveBall(BallA);
    checkForCollision(BallA);
    pause(DELAY);
    private void setup(double X_coor, double Y_coor, GOval BallObject) {
    BallObject = new GOval(X_coor, Y_coor, DIAM_BALL, DIAM_BALL);
    add(BallObject);
    private void moveBall(GOval BallObject) {
    yVel += GRAVITY;
    BallObject.move(xVel,yVel);
    private void checkForCollision(GOval BallObject) {
    if(BallObject.getY() > getHeight() - DIAM_BALL){
    yVel = - yVel * BOUNCE_REDUCE;
    double diff = BallObject.getY() - (getHeight() - DIAM_BALL);
    BallObject.move(0, -2 * diff);
    } Edited by: TiredRyan on Mar 19, 2010 1:47 AM

    TiredRyan wrote:
    That is great! Thanks. I've got two question though.
    1.) Now I want to have 100 bouncing balls. Is the best way to achieve this is through an array of GOvals? I haven't gotten to the lecture on arrays on Stanford's ITunesU site yet so I am not sure what is possible with what I know now.An array would work, or a List. But it doesn't matter much in this case.
    2.) Are references being passed by value only applicable to Java or is that common to object-oriented programming? Also is there a way to force Java to pass in "BallA" instead of the value "null"?I can't say about all OO languages as a whole, but at least C++ can pass by reference.
    And no, there's no way to pass a reference to the BallA variable, so the method would initialize it and it wouldn't be null anymore.
    When you call the method with your BallA variable, the value of the variable is examined and it's passed to the method. So you can't pass the name of a variable where you'd want to store some object you created in the method.
    But you don't need to either, so there's no harm done.

  • Painting Graphics from an Array

    I have a GUI that displays the Towers of Hanoi solution in a JPanel. Everything actually works except for a slight repainting issue.
    Currently I am overriding the paint() function, I know that for my purpose using paintComponent() would probably be the better route, however that's not my issue...
    The images (disks) in my JPanel are not redrawing properly, and I have no idea why...
    Basically:
    - I call setup() to set the number of disks and the co ordinates they should be drawn. (store them in an array)
    - I call moveDisk() to change the co ordinates of each disk as they are being moved.
    - then drawDisk() is called to go through the array of disks and print them.
    currently paint() calls drawDisk() in order to display the current position of all the disks.
    It seems to work fine for the first 2 moves, then disks start disappearing until there is one (the last disk) left...BUT if I print the co ordinates of the disks they seem to be correct, just not drawing.
    could someone take a look at my code and see what is wrong?
    below is the meat of the code, minus the GUI:
        public class HanoiFrame extends javax.swing.JFrame {
        private static final int STATE_SETUP = 0;
        private static final int STATE_ANIMATE = 1;
        private static final int POLE_AREA_HEIGHT = 356;
        private static final int POLE_AREA_WIDTH = 205;
        private static final int DISK_ARC_HEIGHT = 15;
        private static final int DISK_ARC_WIDTH = 15;
        private static final int DISK_HEIGHT = 23;
        private static final int MAX_DISKS = 10;
        private static final int MAX_ANIMATION_DELAY = 30000;
        private static final int MAX_PHYSICAL_DELAY = 100000;
        private static final int MIN_DISKS = 1;
        private static final int MIN_ANIMATION_DELAY = 1;
        private static final int MIN_PHYSICAL_DELAY = 1;
        private static final int EMPTY_CELL_VALUE = -1;
        private static final int CELL_HEIGHT = 25;
        private static final int COLUMNS = 3;
        private static final int ROW = 11;
        private  static final int MILLISECONDS_PER_SECOND = 1000;
        private final static String newline = "\n";
        private static Disk[] disks;
        private static Disk newDisk;
        private static int[][] diskCells;
        public static  int startX = 2;
        public static  int startY = 340;
        public static int setDiskAmount = 0;
        public static int setAnimationDelay = 0;
        public static int  setPhysicalDelay = 0;
        public static int  moveNumber = 0;
        public static int intMovesLeft = 0;
        private boolean  buttonPressed = false;
        private double movesLeft = 0;
        private int windowState = 0;
        /** Creates new form HanoiFrame */
        public HanoiFrame() {
            initComponents();
            /* initialize the "poles" to hold a certain number of "cells */
            this.diskCells = new int[ROW][COLUMNS];
            for (int row = ROW - 1;row >= 0; row--) {
                for (int col = 0;col < COLUMNS ; col++) {
                    diskCells[row][col] = EMPTY_CELL_VALUE;
        private void resetButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           
            /* reset all the variable to original state */
            setDiskAmount = 0;
            setAnimationDelay = 0;
            setPhysicalDelay = 0;
            moveNumber = 0;
            movesLeft = 0;
            intMovesLeft = 0;
            buttonPressed = false;
            windowState = 0;
            this.startButton.setEnabled(true);
            this.diskAmount.setEditable(true);
            this.animationDelay.setEditable(true);
            this.physicalDelay.setEditable(true);
            /* reset all the cell vales to empty (this could be its own function) */
            for (int row = ROW - 1;row >= 0; row--) {
                for (int col = 0;col < COLUMNS ; col++) {
                    diskCells[row][col] = EMPTY_CELL_VALUE;
            /* reset the content of the TextFields and Area */
            this.diskAmount.setText("");
            this.animationDelay.setText("");
            this.physicalDelay.setText("");
            this.outTextArea.setText("");
            /* repaint the display panel */
            this.hanoiPanel.repaint();
        /* i have no idea why this is here...It was generated by Netbeans when I
         *made the reset button.  As you can see it made 2.  The one above it the same
         *except it contains code.  Since it was automatically generated
         *I cannot delete it.
        private void resetButtonMouseReleased(java.awt.event.MouseEvent evt) {                                         
        /* is executed when the start button is pressed.
         *also executes a field check and intializes key variables. Finally,
         *it executes the solution and generates the solve time
        private void startButtonMouseReleased(java.awt.event.MouseEvent evt) {                                         
            /* check if the program has already been run (without being reset) */
            if (!buttonPressed){
                /* check the fields to ensure the input is correct and useable */
                if (checkFields()){
                    /* give button a pressed status if all info valid */
                    buttonPressed = true;
                    windowState = 1;
                    /* disable the button */
                    this.startButton.setEnabled(false);
                    /* disable the fields */
                    this.diskAmount.setEditable(false);
                    this.animationDelay.setEditable(false);
                    this.physicalDelay.setEditable(false);
                    /* setup the disks on the starting pole */
                    setup();
                    /* initialize the number of moves required. 2 to the power of n minus 1 */
                    movesLeft = Math.pow(2, setDiskAmount) - 1;
                    /* convert the number to an integer */
                    intMovesLeft = (int)movesLeft;
                    /* set the physical delay */
                    setPhysicalDelay = Integer.parseInt(this.physicalDelay.getText());
                    /* create and start a new thread.  This is EXTREMELY important
                     *as it allows for GUI to be repainted while the soulution
                     *is animated */
                    SolveEngine s = new SolveEngine();
                    s.start();               
         * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new HanoiFrame().setVisible(true);
        /*returns the Animation panel area graphics
         *@return Animation area graphics
        public static Graphics getAnimationArea(){
            /* get the usable area of poleA */
            Container clientArea = hanoiPanel;
            //Container clientArea = this.getContentPane();
            /* get the graphics to the display panel*/
            Graphics gfx = clientArea.getGraphics();
            return gfx;
         *set up the requested amount of disks on the first pole
         *@param diskAmount the amount of disks entered by the user
        public void setup(){
            int numberOfDisks = setDiskAmount;
            this.disks = new Disk[numberOfDisks];
            int diskNumber = 0;
            int diskWidth = POLE_AREA_WIDTH - 4;
            int arcH = DISK_ARC_HEIGHT;
            int arcW = DISK_ARC_WIDTH;
            int x = startX;
            int y = startY;
            int row = 0;
            int col = 0;
            /* get the graphics to the display panel*/
            //Graphics gfx = getAnimationArea();
            /* set the color of the disks */
            //gfx.setColor(Color.MAGENTA);
            /* draw the specified number of disks */
            while (diskNumber < numberOfDisks){
                /* reduce the y position */
                y = startY - diskNumber * CELL_HEIGHT;
                /* draw the disk */
                //gfx.fillRoundRect(x, y, diskWidth, DISK_HEIGHT, arcH, arcW);
                /* create a new instance of disk */
                newDisk = new Disk(x, y, diskWidth);
                /* give the new disk an id */
                this.disks[diskNumber] = newDisk;
                /* add the id to the cell array of poleA */
                this.diskCells[row][col] = diskNumber;
                /* make the disk smaller and center */
                x = x + 8;
                diskWidth = diskWidth - 16;
                /* increase disk number */
                diskNumber++;
                /* move to the next row */
                row++;
            repaint();
         *move the disk from a source pole to the destination pole.
         *this should take the source col and destination col to determine where to draw the
         *disk.  It will also need to know to draw the disk in the first available cell
         *in a col
         *@param source the starting pole of the next move
         *@param destination the end pole of the next move
        public void moveDisk(int src, int dest){
            /* the lines below would not be necessary if I were to pass the Graphics
             *gfx object as a parameter.  I may have to use this option in order
             *to work around the current repainting issue */
            /* get the graphics to the display panel*/
            Graphics gfx = getAnimationArea();
            /* get the id of the disk to be moved */
            int disk = getDiskId(src);
            /* get the to and from rows */
            int sourceRow = getRow(src);
            int destinationRow = getRow(dest);
            /* set the co ordintates of the destination */
            int col = dest * POLE_AREA_WIDTH;
            int x = disks[disk].getStartX() + col;
            int y = startY - (destinationRow * CELL_HEIGHT);
            int width = disks[disk].getDiskWidth();
            disks[disk].setStartX(x);
            disks[disk].setStartY(y);
            disks[disk].setDiskWidth(width);
            //System.out.println("startX " + x);
            //System.out.println("startY " + y);
            //System.out.println("destination row " + destinationRow);
            //System.out.println("disk " + disk);
            //System.out.println("Width " + width);
            diskCells[sourceRow - 1][src] = EMPTY_CELL_VALUE;
            /* set the destination row to the disk id */
            diskCells[destinationRow][dest] = disk;
            drawDisk();
            repaint();
        public void drawDisk(){
            int diskNum = setDiskAmount -1;
            int i = 0;
            Graphics gfx = getAnimationArea();
            gfx.setColor(Color.MAGENTA);
            while(diskNum >= 0){
                //System.out.println("here is the disk IDs " + diskNum);
                //System.out.println("the startY during draw " + disks[diskNum].getStartY());
                gfx.fillRoundRect(disks[diskNum].getStartX(), disks[diskNum].getStartY(), disks[diskNum].getDiskWidth(), DISK_HEIGHT, DISK_ARC_WIDTH, DISK_ARC_HEIGHT);
                diskNum--;
        public void paint(Graphics gfx){
            if(windowState == 0){
                super.paint(gfx);
                setup();
            } else if (windowState == 1){
                super.paint(gfx);
                drawDisk();
         *returns the id of the disk
         *@param col the the designated column
         *@return the disk identification number
        public static int getDiskId(int col){
            int diskIdent = 0;
            /* initialize the row number to max -1, because the array start at 0 */
            int row = MAX_DISKS - 1;
            /* do a cell check while row is greater than 0
             *this is done so that is starts at the top row
             *and moves down
            while (row > EMPTY_CELL_VALUE){
                /* when the first cell that is not -1 is reached get the disk number
                 *that disk will be the smallest in the stack */
                if(diskCells[row][col] != -1){
                    //diskIdent = this.diskCells[row][col];
                    diskIdent =diskCells[row][col];
                    break;
                row--;
            return diskIdent;
         *returns the first available row
         *@param col the designated col
         *@return the first available row number
        public static int getRow(int col){
            int rowNumber = 0;
            /* cycle through the cells until it finds an empty one */
            while (diskCells[rowNumber][col] != -1){
                rowNumber++;
            return rowNumber;
         *calculate the total time it takes for the tower of hanoi game to be
         *solved, given the amount of disk and the amount of time it takes
         *to physically move a disk from one pole to the other.
        public static void totalTime(){
            int timeInSeconds = setPhysicalDelay * intMovesLeft;
            int i = 0;
            int seconds = 0;
            int minute = 0;
            int hour = 0;
            int day = 0;
            int month = 0;
            int year = 0;
            while (i < timeInSeconds){
                if(seconds > 60){
                    minute++;
                    seconds = 0;
                if(minute > 60){
                    hour++;
                    minute = 0;
                if(hour > 24){
                    day++;
                    hour = 0;
                if(day > 30){
                    month++;
                    day = 0;
                if(month > 12){
                    year++;
                    month = 0;
                seconds++;
                i++;
            updateMessageCenter("It would take:" + year + " years " + month + " months " + day +
                    " days " + hour + " hours " + minute + " minutes and " + seconds + " seconds, to move " + setDiskAmount +
                    " disks at " + setPhysicalDelay + " seconds per move");
       

    Sorry if my post was a little too cryptic...
    "How do you know? You have a problem you can't solve. Anything could be your issue." Agreed. However, using the process of elimination and debug statments I have been able to narrow the scope of the issue.
    "If you can't solve it by executing the code and adding debug statements how to you expect us to help."If I could solve but "executing code and adding debug statements" there would be no need to post the problem here.
    "We don't know exactly what you are attempting to do."Trying to paint my graphics to a JPanel based on a set of co ordinates.
    "We don't know why you are passing the Graphics object around."Why not? is it impossible to do it this way?
    "The big problem is in the alogorithm you use to determine the location of each component."Who said you couldn't read minds?
    "If you are using some kind of animation then I would use a Timer to schedule the moving of components. I don't even see how you are doing this in your code."Sorry I guess stating that I didn't post my entire code may have threw things off...I do use a timer in a seperate class. I will include it in the next post.
    "I can't tell if you are using Threads of not."guess you overlooked these lines of code:
                    /* create and start a new thread.  This is EXTREMELY important
                     *as it allows for GUI to be repainted while the soulution
                     *is animated */
                    SolveEngine s = new SolveEngine();
                    s.start();   Here is the code once again:
    public class HanoiFrame extends javax.swing.JFrame {
        private static final int STATE_SETUP = 0;
        private static final int STATE_ANIMATE = 1;
        private static final int POLE_AREA_HEIGHT = 356;
        private static final int POLE_AREA_WIDTH = 205;
        private static final int DISK_ARC_HEIGHT = 15;
        private static final int DISK_ARC_WIDTH = 15;
        private static final int DISK_HEIGHT = 23;
        private static final int MAX_DISKS = 10;
        private static final int MAX_ANIMATION_DELAY = 30000;
        private static final int MAX_PHYSICAL_DELAY = 100000;
        private static final int MIN_DISKS = 1;
        private static final int MIN_ANIMATION_DELAY = 1;
        private static final int MIN_PHYSICAL_DELAY = 1;
        private static final int EMPTY_CELL_VALUE = -1;
        private static final int CELL_HEIGHT = 25;
        private static final int COLUMNS = 3;
        private static final int ROW = 11;
        private  static final int MILLISECONDS_PER_SECOND = 1000;
        private final static String newline = "\n";
        private static Disk[] disks;
        private static Disk newDisk;
        private static int[][] diskCells;
        public static  int startX = 2;
        public static  int startY = 340;
        public static int setDiskAmount = 0;
        public static int setAnimationDelay = 0;
        public static int  setPhysicalDelay = 0;
        public static int  moveNumber = 0;
        public static int intMovesLeft = 0;
        private boolean  buttonPressed = false;
        private double movesLeft = 0;
        private int windowState = 0;
        /** Creates new form HanoiFrame */
        public HanoiFrame() {
            initComponents();
            /* initialize the "poles" to hold a certain number of "cells */
            this.diskCells = new int[ROW][COLUMNS];
            for (int row = ROW - 1;row >= 0; row--) {
                for (int col = 0;col < COLUMNS ; col++) {
                    diskCells[row][col] = EMPTY_CELL_VALUE;
        private void resetButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           
            /* reset all the variable to original state */
            setDiskAmount = 0;
            setAnimationDelay = 0;
            setPhysicalDelay = 0;
            moveNumber = 0;
            movesLeft = 0;
            intMovesLeft = 0;
            buttonPressed = false;
            windowState = 0;
            this.startButton.setEnabled(true);
            this.diskAmount.setEditable(true);
            this.animationDelay.setEditable(true);
            this.physicalDelay.setEditable(true);
            /* reset all the cell vales to empty (this could be its own function) */
            for (int row = ROW - 1;row >= 0; row--) {
                for (int col = 0;col < COLUMNS ; col++) {
                    diskCells[row][col] = EMPTY_CELL_VALUE;
            /* reset the content of the TextFields and Area */
            this.diskAmount.setText("");
            this.animationDelay.setText("");
            this.physicalDelay.setText("");
            this.outTextArea.setText("");
            /* repaint the display panel */
            this.hanoiPanel.repaint();
        /* i have no idea why this is here...It was generated by Netbeans when I
         *made the reset button.  As you can see it made 2.  The one above it the same
         *except it contains code.  Since it was automatically generated
         *I cannot delete it.
        private void resetButtonMouseReleased(java.awt.event.MouseEvent evt) {                                         
        /* is executed when the start button is pressed.
         *also executes a field check and intializes key variables. Finally,
         *it executes the solution and generates the solve time
        private void startButtonMouseReleased(java.awt.event.MouseEvent evt) {                                         
            /* check if the program has already been run (without being reset) */
            if (!buttonPressed){
                /* check the fields to ensure the input is correct and useable */
                if (checkFields()){
                    /* give button a pressed status if all info valid */
                    buttonPressed = true;
                    windowState = 1;
                    /* disable the button */
                    this.startButton.setEnabled(false);
                    /* disable the fields */
                    this.diskAmount.setEditable(false);
                    this.animationDelay.setEditable(false);
                    this.physicalDelay.setEditable(false);
                    /* setup the disks on the starting pole */
                    setup();
                    /* initialize the number of moves required. 2 to the power of n minus 1 */
                    movesLeft = Math.pow(2, setDiskAmount) - 1;
                    /* convert the number to an integer */
                    intMovesLeft = (int)movesLeft;
                    /* set the physical delay */
                    setPhysicalDelay = Integer.parseInt(this.physicalDelay.getText());
                    /* create and start a new thread.  This is EXTREMELY important
                     *as it allows for GUI to be repainted while the soulution
                     *is animated */
                    SolveEngine s = new SolveEngine();
                    s.start();
         *Check all the fields at once to ensure that they are valid
        private boolean checkFields(){
            String numberOfDisks = null;
            String animationDelay = null;
            String physicalDelay = null;
            numberOfDisks = this.diskAmount.getText();
            animationDelay = this.animationDelay.getText();
            physicalDelay = this.physicalDelay.getText();
            /* initiate my array of error messages */
            ArrayList errMsg = new ArrayList(0);
            /* check if the number of disks was left blank */
            if (numberOfDisks.equals("")){
                errMsg.add("Please enter the Number of Disks (MAX " + MAX_DISKS + ")");
            }else{
                /* check if the input given is valid */
                try {
                    /* parse the disk amount entered into an integer */
                    setDiskAmount = Integer.parseInt(numberOfDisks);
                    /* check the # of disks entered is greater than 0 and less than 10 */
                    if (setDiskAmount < MIN_DISKS){
                        errMsg.add("Number of Disks must be greater than " + MIN_DISKS);
                    } else if (setDiskAmount > MAX_DISKS){
                        errMsg.add("Number of Disks must be less than" + MAX_DISKS);
                } catch (NumberFormatException ex) {
                    errMsg.add("Number of Disks must be a Number");
            /* check if animation delay was left blank */
            if (animationDelay.equals("")){
                errMsg.add("Please enter disk Animation Delay");
            } else {
                /* check if the input given is valid */
                try {
                    /* parse the animation delay entered into an integer */
                    setAnimationDelay = Integer.parseInt(animationDelay);
                    /* check range of animation delay */
                    if (setAnimationDelay < MIN_ANIMATION_DELAY){
                        errMsg.add("Animation Delay must be greater than 0");
                    } else if (setAnimationDelay > MAX_ANIMATION_DELAY){
                        errMsg.add("Animation Delay must be less than " + MAX_ANIMATION_DELAY);
                } catch (NumberFormatException ex) {
                    errMsg.add("Animation Delay must be a Number");
            /* check if physical delay was left blank */
            if (physicalDelay.equals("")){
                errMsg.add("Please enter the Physical disk delay");
            } else {
                /* check if the input given is valid */
                try {
                    /* parse the physical delay entered into an integer */
                    setPhysicalDelay = Integer.parseInt(physicalDelay);
                    /* check check the range of the physical delay */
                    if (setPhysicalDelay < MIN_PHYSICAL_DELAY){
                        errMsg.add("Physical Delay must be greater than 0");
                    } else if (setPhysicalDelay > MAX_PHYSICAL_DELAY){
                        errMsg.add("Physical Delay must be less than " + MAX_PHYSICAL_DELAY);
                } catch (NumberFormatException ex) {
                    errMsg.add("Physical Delay must be a Number");
            /* if there is any problem, add the message to the popup and display */
            if (!errMsg.isEmpty()){
                JOptionPane.showMessageDialog(this, errMsg.toArray());
                return false;
            return true;
         * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new HanoiFrame().setVisible(true);
        /*returns the Animation panel area graphics
         *@return Animation area graphics
        public static Graphics getAnimationArea(){
            /* get the usable area of poleA */
            Container clientArea = hanoiPanel;
            //Container clientArea = this.getContentPane();
            /* get the graphics to the display panel*/
            Graphics gfx = clientArea.getGraphics();
            return gfx;
         *set up the requested amount of disks on the first pole
         *@param diskAmount the amount of disks entered by the user
        public void setup(){
            int numberOfDisks = setDiskAmount;
            this.disks = new Disk[numberOfDisks];
            int diskNumber = 0;
            int diskWidth = POLE_AREA_WIDTH - 4;
            int arcH = DISK_ARC_HEIGHT;
            int arcW = DISK_ARC_WIDTH;
            int x = startX;
            int y = startY;
            int row = 0;
            int col = 0;
            /* get the graphics to the display panel*/
            //Graphics gfx = getAnimationArea();
            /* set the color of the disks */
            //gfx.setColor(Color.MAGENTA);
            /* draw the specified number of disks */
            while (diskNumber < numberOfDisks){
                /* reduce the y position */
                y = startY - diskNumber * CELL_HEIGHT;
                /* draw the disk */
                //gfx.fillRoundRect(x, y, diskWidth, DISK_HEIGHT, arcH, arcW);
                /* create a new instance of disk */
                newDisk = new Disk(x, y, diskWidth);
                /* give the new disk an id */
                this.disks[diskNumber] = newDisk;
                /* add the id to the cell array of poleA */
                this.diskCells[row][col] = diskNumber;
                /* make the disk smaller and center */
                x = x + 8;
                diskWidth = diskWidth - 16;
                /* increase disk number */
                diskNumber++;
                /* move to the next row */
                row++;
            repaint();
         *move the disk from a source pole to the destination pole.
         *this should take the source col and destination col to determine where to draw the
         *disk.  It will also need to know to draw the disk in the first available cell
         *in a col
         *@param source the starting pole of the next move
         *@param destination the end pole of the next move
        public void moveDisk(int src, int dest){
            /* the lines below would not be necessary if I were to pass the Graphics
             *gfx object as a parameter.  I may have to use this option in order
             *to work around the current repainting issue */
            /* get the graphics to the display panel*/
            Graphics gfx = getAnimationArea();
            /* get the id of the disk to be moved */
            int disk = getDiskId(src);
            /* get the to and from rows */
            int sourceRow = getRow(src);
            int destinationRow = getRow(dest);
            /* set the co ordintates of the destination */
            int col = dest * POLE_AREA_WIDTH;
            int x = disks[disk].getStartX() + col;
            int y = startY - (destinationRow * CELL_HEIGHT);
            int width = disks[disk].getDiskWidth();
            disks[disk].setStartX(x);
            disks[disk].setStartY(y);
            disks[disk].setDiskWidth(width);
            //System.out.println("startX " + x);
            //System.out.println("startY " + y);
            //System.out.println("destination row " + destinationRow);
            //System.out.println("disk " + disk);
            //System.out.println("Width " + width);
            diskCells[sourceRow - 1][src] = EMPTY_CELL_VALUE;
            /* set the destination row to the disk id */
            diskCells[destinationRow][dest] = disk;
            drawDisk();
            repaint();
            String output = "";
            //must initialize row to max - 1 and increment 'til = 0
            //since the array position starts at 0
            //this will print the array from the top down
            for (int row = ROW - 1;row >= 0; row--) {
                for (int colm = 0;colm < COLUMNS ; colm++) {
                    output = output + diskCells[row][colm];
                output = output + "\n";
            System.out.println(output);
            System.out.println(newline);
        public void drawDisk(){
            int diskNum = setDiskAmount -1;
            int i = 0;
            Graphics gfx = getAnimationArea();
            gfx.setColor(Color.MAGENTA);
            while(diskNum >= 0){
                //System.out.println("here is the disk IDs " + diskNum);
                //System.out.println("the startY during draw " + disks[diskNum].getStartY());
                gfx.fillRoundRect(disks[diskNum].getStartX(), disks[diskNum].getStartY(), disks[diskNum].getDiskWidth(), DISK_HEIGHT, DISK_ARC_WIDTH, DISK_ARC_HEIGHT);
                diskNum--;
        public void paint(Graphics gfx){
            if(windowState == 0){
                super.paint(gfx);
                setup();
            } else if (windowState == 1){
                super.paint(gfx);
                drawDisk();
         *returns the id of the disk
         *@param col the the designated column
         *@return the disk identification number
        public static int getDiskId(int col){
            int diskIdent = 0;
            /* initialize the row number to max -1, because the array start at 0 */
            int row = MAX_DISKS - 1;
            /* do a cell check while row is greater than 0
             *this is done so that is starts at the top row
             *and moves down
            while (row > EMPTY_CELL_VALUE){
                /* when the first cell that is not -1 is reached get the disk number
                 *that disk will be the smallest in the stack */
                if(diskCells[row][col] != -1){
                    //diskIdent = this.diskCells[row][col];
                    diskIdent =diskCells[row][col];
                    break;
                row--;
            return diskIdent;
         *returns the first available row
         *@param col the designated col
         *@return the first available row number
        public static int getRow(int col){
            int rowNumber = 0;
            /* cycle through the cells until it finds an empty one */
            while (diskCells[rowNumber][col] != -1){
                rowNumber++;
            return rowNumber;
         *calculate the total time it takes for the tower of hanoi game to be
         *solved, given the amount of disk and the amount of time it takes
         *to physically move a disk from one pole to the other.
        public static void totalTime(){
            int timeInSeconds = setPhysicalDelay * intMovesLeft;
            int i = 0;
            int seconds = 0;
            int minute = 0;
            int hour = 0;
            int day = 0;
            int month = 0;
            int year = 0;
            while (i < timeInSeconds){
                if(seconds > 60){
                    minute++;
                    seconds = 0;
                if(minute > 60){
                    hour++;
                    minute = 0;
                if(hour > 24){
                    day++;
                    hour = 0;
                if(day > 30){
                    month++;
                    day = 0;
                if(month > 12){
                    year++;
                    month = 0;
                seconds++;
                i++;
            updateMessageCenter("It would take:" + year + " years " + month + " months " + day +
                    " days " + hour + " hours " + minute + " minutes and " + seconds + " seconds, to move " + setDiskAmount +
                    " disks at " + setPhysicalDelay + " seconds per move");
         *add the message to the diplay window
         *currently this is not necessary, but may be required to
         *dynamically display the contents of message into the text area
         *@param message the message to be added/appended the the text area
        public static void updateMessageCenter(String message){
            /* append text to the message */
            outTextArea.append(message + newline);
            /* ensure the the most recent line is viewable - auto scroll */
            outTextArea.setCaretPosition(outTextArea.getDocument().getLength());
        public class SolveEngine extends Thread {
            /** Creates a new instance of SolveEngine */
            public SolveEngine() {
            public void run(){
                /* start the engine/animation */
                solutionEngine(HanoiFrame.setDiskAmount,0, 2, 1);
                /* calculate and print the total time after the solution is complete */
                HanoiFrame.totalTime();
         *the recursive solution to the Towers of Hanoi problem
         *@param diskAmount the number of disks that need to be moved
         *@param start the identity of the starting column
         *@param end the identity of the ending column
         *@param temp the identity of the temporary column
            public void solutionEngine(int diskAmount,int start, int end, int temp){
                int disks = diskAmount;
                int startPole = start;
                int endPole = end;
                int tempPole = temp;
                try {
                    if ( disks == 1 ) {
                        HanoiFrame.moveNumber++;
                        HanoiFrame.updateMessageCenter("Moving disk from  "+ startPole + " to "+ endPole + " Move #: " + HanoiFrame.moveNumber + " of " + HanoiFrame.intMovesLeft);
                        /* delay the movement of the disk */
                        Thread.sleep(HanoiFrame.setAnimationDelay);
                        /* move the disk */
                        moveDisk(startPole, endPole);
                    } else {
                        solutionEngine( disks - 1, startPole, tempPole, endPole);
                        HanoiFrame.moveNumber++;
                        HanoiFrame.updateMessageCenter("Moving disk from  "+ startPole + " to "+ endPole + " Move #: " + HanoiFrame.moveNumber + " of " + HanoiFrame.intMovesLeft);
                        /* delay the movement of the disk */
                        Thread.sleep(HanoiFrame.setAnimationDelay);
                        moveDisk(startPole, endPole);
                        solutionEngine( disks - 1, tempPole, endPole, startPole);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
        }

  • Please take a look?

    Hello :) My friend is doing his thesis & he's stuck with this program. Unfortunately I don't have Java installed on this comp (in work) so I'm not much use but I was hoping someone here could point him in the right direction. Here goes...
    Description: Basic paddle ball type game.
    This example midlet demonstrates how to use threads and the Canvas class. It implements
    a simple paddle ball type game. It demonstrates how to use a clipping region to implement
    graphics more effeciently.
    It should animate at a constant speed on all phones, although it may appear
    jerky on devices with very restricted processing resources.
    @created den 21 mars 2002
    COPYRIGHT All rights reserved Sony Ericsson Mobile Communications AB 2003.
    The software is the copyrighted work of Sony Ericsson Mobile Communications AB.
    The use of the software is subject to the terms of the end-user license
    agreement which accompanies or is included with the software. The software is
    provided "as is" and Sony Ericsson specifically disclaim any warranty or
    condition whatsoever regarding merchantability or fitness for a specific
    purpose, title or non-infringement. No warranty of any kind is made in
    relation to the condition, suitability, availability, accuracy, reliability,
    merchantability and/or non-infringement of the software provided herein.
    package midp.demo;
    import java.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    * Basic Ball and Paddle game. Use arrow keys to move paddle.
    * Demonstrates multi-threading, animation, event handling.
    * @see MIDlet
    public class PaddleBall extends MIDlet implements CommandListener {
    * Constant for white color
    private static final int COLOR_WHITE = 0xFFFFFF;
    * Constant for black color
    private static final int COLOR_BLACK = 0x000000;
    * The game speed (in milliseconds)
    private final int GAME_SPEED = 5;
    * The main game screen
    private GameFrame mainFrame;
    * The title screen
    private Form titleScreen;
    * The results screen
    private Form statsScreen;
    * The number of milliseconds the user has been playing this game
    private long elapsedTime;
    * The ball object for this game
    private Ball myBall;
    * The paddle object for this game
    private Paddle myPaddle;
    * True if game has not started or player lost
    private boolean gameOver = true;
    * How many games have been played
    private int numGames;
    * Reference to Display
    private Display myDisplay;
    public PaddleBall() {
    myDisplay = Display.getDisplay(this);
    * Create main game screen
    mainFrame = new GameFrame();
    * Create title screen
    titleScreen = new Form("Paddle Ball");
    titleScreen.append(new StringItem(null,
    "The classic arcade game, now on your mobile device!"));
    titleScreen.setCommandListener(this);
    titleScreen.addCommand(new Command("START", Command.OK, 1));
    * Create results screen
    statsScreen = new Form("Results");
    statsScreen.setCommandListener(PaddleBall.this);
    statsScreen.addCommand(new Command("AGAIN?", Command.OK, 1));
    * Begin the application, show its frame
    protected void startApp() {
    myDisplay.setCurrent(titleScreen);
    * Application is being terminated, kill threads
    protected void pauseApp() {
    gameOver = true;
    myBall = null;
    myPaddle = null;
    * Clean up application
    protected void destroyApp(boolean unconditional) {
    gameOver = true;
    * Start the game
    public void commandAction(Command c, Displayable d) {
    * Create ball and paddle threads
    myBall = new Ball();
    myPaddle = new Paddle();
    * Get the starting time
    elapsedTime = System.currentTimeMillis();
    * Set the initial ball and paddle positions
    myBall.setUp();
    myPaddle.setUp();
    * Set the screen
    myDisplay.setCurrent(mainFrame);
    * Start the thread
    gameOver = false;
    myBall.start();
    myPaddle.start();
    * The main Screen for this game
    class GameFrame extends Canvas {
    * Canvas receives all key events
    public void keyPressed(int keyCode) {
    int gameAction = 0;
    try {
    gameAction = getGameAction(keyCode);
    } catch (Exception e) {
    if (gameAction == LEFT) {
    myPaddle.move(-2 * GAME_SPEED);
    } else if (gameAction == RIGHT) {
    myPaddle.move(2 * GAME_SPEED);
    return;
    * Clear the game screen
    private void clear(Graphics g) {
    g.setColor(0xFFFFFF);
    g.fillRect(0, 0, getWidth(), getHeight());
    * Paint the game screen
    public void paint(Graphics g) {
    synchronized (g) {
    * Clear the screen
    clear(g);
    g.setColor(0x000000);
    * Paint the ball and paddle
    g.fillRect(myPaddle.x, myPaddle.y, myPaddle.WIDTH,
    myPaddle.HEIGHT);
    g.fillArc(myBall.x, myBall.y, myBall.SIZE,
    myBall.SIZE, 0, 360);
    * The ball thread
    class Ball extends Thread {
    * The ball diameter
    public final int SIZE = mainFrame.getHeight() / 15;
    * The sign of the x component of the velocity
    private int xDir = 1;
    * The sign of the y component of the velocity
    private int yDir = 1;
    * X position of ball
    int x;
    * Y position of ball
    int y;
    * Create a ball
    public Ball() {
    setUp();
    * Set starting position
    void setUp() {
    x = mainFrame.getWidth() / 2;
    y = mainFrame.getHeight() / 10;
    * Loop to run thread, loops until game over
    public void run() {
    while (!gameOver) {
    * Sleep for animation delay
    try {
    Thread.sleep(150 - 10 * GAME_SPEED);
    } catch (Exception e) {
    return;
    int oldX = x;
    int oldY = y;
    * Recalculate x position
    int xPos = x + xDir * GAME_SPEED;
    if (((xPos+SIZE) <= mainFrame.getWidth())
    && (xPos >= 0)) {
    x = xPos;
    } else {
    xDir *= -1;
    AlertType.WARNING.playSound(myDisplay);
    * Recalculate y position
    int yPos = y + yDir * GAME_SPEED;
    if ((yPos >= 0) &&
    ((yPos + SIZE) <=
    (mainFrame.getHeight() - myPaddle.HEIGHT))) {
    y = yPos;
    } else if ((yPos + SIZE) >
    (mainFrame.getHeight() - myPaddle.HEIGHT)) {
    * Bounce off paddle
    if ((xPos <= (myPaddle.x + myPaddle.WIDTH))
    && ((xPos + SIZE) >= myPaddle.x)) {
    yDir *= -1;
    AlertType.INFO.playSound(myDisplay);
    * Player loses
    } else {
    gameOver = true;
    * Get statistic information
    elapsedTime = System.currentTimeMillis()
    - elapsedTime;
    numGames++;
    statsScreen.append(new StringItem("Game " +
    numGames + " over", "Time: " +
    (elapsedTime/1000) + " seconds"));
    * Show the statistics screen
    myDisplay.setCurrent(statsScreen);
    return;
    } else if (yPos < 0) {
    yDir *= -1;
    AlertType.WARNING.playSound(myDisplay);
    mainFrame.repaint(Math.min(oldX, x), Math.min(oldY, y),
    Math.abs(x-oldX) + SIZE,
    Math.abs(y-oldY) + SIZE);
    * The game paddle thread
    class Paddle extends Thread {
    * Paddle width
    public final int WIDTH = mainFrame.getWidth() / 6;
    * Paddle height
    public final int HEIGHT = mainFrame.getHeight() / 15;
    * X position
    int x;
    * Y position
    int y;
    * Create a new paddle
    public Paddle() {
    setUp();
    * Initialize starting position
    void setUp() {
    x = mainFrame.getWidth() / 2 - WIDTH / 2;
    y = mainFrame.getHeight() - HEIGHT;
    * Loop to run paddlethread, loops until game over
    public void run() {
    while (!gameOver) {
    try {
    Thread.sleep(10);
    } catch (Exception e) {
    return;
    * Move paddle right/left
    void move(int delta) {
    int oldX = x;
    int xPos = x + delta;
    if (((xPos + WIDTH) <= mainFrame.getWidth())
    && (xPos >= 0)) {
    x = xPos;
    mainFrame.repaint(Math.min(oldX, x), y,
    Math.abs(x-oldX) + WIDTH, HEIGHT);
    }

    Let me do you a favor. With this, even you don't have JDK installed, you can help your friend.
    PaddleBall.java:4: package javax.microedition.lcdui does not exist
    import javax.microedition.lcdui.*;
    ^
    PaddleBall.java:5: package javax.microedition.midlet does not exist
    import javax.microedition.midlet.*;
    ^
    PaddleBall.java:13: cannot resolve symbol
    symbol  : class MIDlet
    location: class midp.demo.PaddleBall
    public class PaddleBall extends MIDlet implements CommandListener {
                                    ^
    PaddleBall.java:13: cannot resolve symbol
    symbol  : class CommandListener
    location: class midp.demo.PaddleBall
    public class PaddleBall extends MIDlet implements CommandListener {
                                                      ^
    PaddleBall.java:165: cannot resolve symbol
    symbol  : class Canvas
    location: class midp.demo.PaddleBall.GameFrame
    class GameFrame extends Canvas {
                            ^
    PaddleBall.java:191: cannot resolve symbol
    symbol  : class Graphics
    location: class midp.demo.PaddleBall.GameFrame
    private void clear(Graphics g) {
                       ^
    PaddleBall.java:200: cannot resolve symbol
    symbol  : class Graphics
    location: class midp.demo.PaddleBall.GameFrame
    public void paint(Graphics g) {
                      ^
    PaddleBall.java:38: cannot resolve symbol
    symbol  : class Form
    location: class midp.demo.PaddleBall
    private Form titleScreen;
            ^
    PaddleBall.java:43: cannot resolve symbol
    symbol  : class Form
    location: class midp.demo.PaddleBall
    private Form statsScreen;
            ^
    PaddleBall.java:73: cannot resolve symbol
    symbol  : class Display
    location: class midp.demo.PaddleBall
    private Display myDisplay;
            ^
    PaddleBall.java:130: cannot resolve symbol
    symbol  : class Command
    location: class midp.demo.PaddleBall
    public void commandAction(Command c, Displayable d) {
                              ^
    PaddleBall.java:130: cannot resolve symbol
    symbol  : class Displayable
    location: class midp.demo.PaddleBall
    public void commandAction(Command c, Displayable d) {
                                         ^
    PaddleBall.java:77: cannot resolve symbol
    symbol  : variable Display
    location: class midp.demo.PaddleBall
    myDisplay = Display.getDisplay(this);
                ^
    PaddleBall.java:87: cannot resolve symbol
    symbol  : class Form
    location: class midp.demo.PaddleBall
    titleScreen = new Form("Paddle Ball");
                      ^
    PaddleBall.java:88: cannot resolve symbol
    symbol  : class StringItem
    location: class midp.demo.PaddleBall
    titleScreen.append(new StringItem(null,
                           ^
    PaddleBall.java:91: cannot resolve symbol
    symbol  : class Command
    location: class midp.demo.PaddleBall
    titleScreen.addCommand(new Command("START", Command.OK, 1));
                               ^
    PaddleBall.java:91: cannot resolve symbol
    symbol  : variable Command
    location: class midp.demo.PaddleBall
    titleScreen.addCommand(new Command("START", Command.OK, 1));
                                                ^
    PaddleBall.java:96: cannot resolve symbol
    symbol  : class Form
    location: class midp.demo.PaddleBall
    statsScreen = new Form("Results");
                      ^
    PaddleBall.java:98: cannot resolve symbol
    symbol  : class Command
    location: class midp.demo.PaddleBall
    statsScreen.addCommand(new Command("AGAIN?", Command.OK, 1));
                               ^
    PaddleBall.java:98: cannot resolve symbol
    symbol  : variable Command
    location: class midp.demo.PaddleBall
    statsScreen.addCommand(new Command("AGAIN?", Command.OK, 1));
                                                 ^
    PaddleBall.java:175: cannot resolve symbol
    symbol  : method getGameAction (int)
    location: class midp.demo.PaddleBall.GameFrame
    gameAction = getGameAction(keyCode);
                 ^
    PaddleBall.java:179: cannot resolve symbol
    symbol  : variable LEFT
    location: class midp.demo.PaddleBall.GameFrame
    if (gameAction == LEFT) {
                      ^
    PaddleBall.java:182: cannot resolve symbol
    symbol  : variable RIGHT
    location: class midp.demo.PaddleBall.GameFrame
    } else if (gameAction == RIGHT) {
                             ^
    PaddleBall.java:194: cannot resolve symbol
    symbol  : method getWidth ()
    location: class midp.demo.PaddleBall.GameFrame
    g.fillRect(0, 0, getWidth(), getHeight());
                     ^
    PaddleBall.java:194: cannot resolve symbol
    symbol  : method getHeight ()
    location: class midp.demo.PaddleBall.GameFrame
    g.fillRect(0, 0, getWidth(), getHeight());
                                 ^
    PaddleBall.java:362: cannot resolve symbol
    symbol  : method getWidth ()
    location: class midp.demo.PaddleBall.GameFrame
    public final int WIDTH = mainFrame.getWidth() / 6;
                                      ^
    PaddleBall.java:367: cannot resolve symbol
    symbol  : method getHeight ()
    location: class midp.demo.PaddleBall.GameFrame
    public final int HEIGHT = mainFrame.getHeight() / 15;
                                       ^
    PaddleBall.java:229: cannot resolve symbol
    symbol  : method getHeight ()
    location: class midp.demo.PaddleBall.GameFrame
    public final int SIZE = mainFrame.getHeight() / 15;
                                     ^
    PaddleBall.java:264: cannot resolve symbol
    symbol  : method getWidth ()
    location: class midp.demo.PaddleBall.GameFrame
    x = mainFrame.getWidth() / 2;
                 ^
    PaddleBall.java:265: cannot resolve symbol
    symbol  : method getHeight ()
    location: class midp.demo.PaddleBall.GameFrame
    y = mainFrame.getHeight() / 10;
                 ^
    PaddleBall.java:291: cannot resolve symbol
    symbol  : method getWidth ()
    location: class midp.demo.PaddleBall.GameFrame
    if (((xPos+SIZE) <= mainFrame.getWidth())
                                 ^
    PaddleBall.java:297: package AlertType does not exist
    AlertType.WARNING.playSound(myDisplay);
             ^
    PaddleBall.java:306: cannot resolve symbol
    symbol  : method getHeight ()
    location: class midp.demo.PaddleBall.GameFrame
    (mainFrame.getHeight() - myPaddle.HEIGHT))) {
              ^
    PaddleBall.java:310: cannot resolve symbol
    symbol  : method getHeight ()
    location: class midp.demo.PaddleBall.GameFrame
    (mainFrame.getHeight() - myPaddle.HEIGHT)) {
              ^
    PaddleBall.java:318: package AlertType does not exist
    AlertType.INFO.playSound(myDisplay);
             ^
    PaddleBall.java:332: cannot resolve symbol
    symbol  : class StringItem
    location: class midp.demo.PaddleBall.Ball
    statsScreen.append(new StringItem("Game " +
                           ^
    PaddleBall.java:345: package AlertType does not exist
    AlertType.WARNING.playSound(myDisplay);
             ^
    PaddleBall.java:347: cannot resolve symbol
    symbol  : method repaint (int,int,int,int)
    location: class midp.demo.PaddleBall.GameFrame
    mainFrame.repaint(Math.min(oldX, x), Math.min(oldY, y),
             ^
    PaddleBall.java:391: cannot resolve symbol
    symbol  : method getWidth ()
    location: class midp.demo.PaddleBall.GameFrame
    x = mainFrame.getWidth() / 2 - WIDTH / 2;
                 ^
    PaddleBall.java:392: cannot resolve symbol
    symbol  : method getHeight ()
    location: class midp.demo.PaddleBall.GameFrame
    y = mainFrame.getHeight() - HEIGHT;
                 ^
    PaddleBall.java:417: cannot resolve symbol
    symbol  : method getWidth ()
    location: class midp.demo.PaddleBall.GameFrame
    if (((xPos + WIDTH) <= mainFrame.getWidth())
                                    ^
    PaddleBall.java:421: cannot resolve symbol
    symbol  : method repaint (int,int,int,int)
    location: class midp.demo.PaddleBall.GameFrame
    mainFrame.repaint(Math.min(oldX, x), y,
             ^
    42 errors

  • Please take a look? (Pong)

    Hello :) My friend is doing his thesis & he's stuck with this program. Apparently it's not compiling. Unfortunately I don't have Java installed on this comp (in work) so I'm not much use but I was hoping someone here could point him in the right direction. Here goes...
    Description: Basic paddle ball type game.
    This example midlet demonstrates how to use threads and the Canvas class. It implements
    a simple paddle ball type game. It demonstrates how to use a clipping region to implement
    graphics more effeciently.
    It should animate at a constant speed on all phones, although it may appear
    jerky on devices with very restricted processing resources.
    @created den 21 mars 2002
    COPYRIGHT All rights reserved Sony Ericsson Mobile Communications AB 2003.
    The software is the copyrighted work of Sony Ericsson Mobile Communications AB.
    The use of the software is subject to the terms of the end-user license
    agreement which accompanies or is included with the software. The software is
    provided "as is" and Sony Ericsson specifically disclaim any warranty or
    condition whatsoever regarding merchantability or fitness for a specific
    purpose, title or non-infringement. No warranty of any kind is made in
    relation to the condition, suitability, availability, accuracy, reliability,
    merchantability and/or non-infringement of the software provided herein.
    package midp.demo;
    import java.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    * Basic Ball and Paddle game. Use arrow keys to move paddle.
    * Demonstrates multi-threading, animation, event handling.
    * @see MIDlet
    public class PaddleBall extends MIDlet implements CommandListener {
    * Constant for white color
    private static final int COLOR_WHITE = 0xFFFFFF;
    * Constant for black color
    private static final int COLOR_BLACK = 0x000000;
    * The game speed (in milliseconds)
    private final int GAME_SPEED = 5;
    * The main game screen
    private GameFrame mainFrame;
    * The title screen
    private Form titleScreen;
    * The results screen
    private Form statsScreen;
    * The number of milliseconds the user has been playing this game
    private long elapsedTime;
    * The ball object for this game
    private Ball myBall;
    * The paddle object for this game
    private Paddle myPaddle;
    * True if game has not started or player lost
    private boolean gameOver = true;
    * How many games have been played
    private int numGames;
    * Reference to Display
    private Display myDisplay;
    public PaddleBall() {
    myDisplay = Display.getDisplay(this);
    * Create main game screen
    mainFrame = new GameFrame();
    * Create title screen
    titleScreen = new Form("Paddle Ball");
    titleScreen.append(new StringItem(null,
    "The classic arcade game, now on your mobile device!"));
    titleScreen.setCommandListener(this);
    titleScreen.addCommand(new Command("START", Command.OK, 1));
    * Create results screen
    statsScreen = new Form("Results");
    statsScreen.setCommandListener(PaddleBall.this);
    statsScreen.addCommand(new Command("AGAIN?", Command.OK, 1));
    * Begin the application, show its frame
    protected void startApp() {
    myDisplay.setCurrent(titleScreen);
    * Application is being terminated, kill threads
    protected void pauseApp() {
    gameOver = true;
    myBall = null;
    myPaddle = null;
    * Clean up application
    protected void destroyApp(boolean unconditional) {
    gameOver = true;
    * Start the game
    public void commandAction(Command c, Displayable d) {
    * Create ball and paddle threads
    myBall = new Ball();
    myPaddle = new Paddle();
    * Get the starting time
    elapsedTime = System.currentTimeMillis();
    * Set the initial ball and paddle positions
    myBall.setUp();
    myPaddle.setUp();
    * Set the screen
    myDisplay.setCurrent(mainFrame);
    * Start the thread
    gameOver = false;
    myBall.start();
    myPaddle.start();
    * The main Screen for this game
    class GameFrame extends Canvas {
    * Canvas receives all key events
    public void keyPressed(int keyCode) {
    int gameAction = 0;
    try {
    gameAction = getGameAction(keyCode);
    } catch (Exception e) {
    if (gameAction == LEFT) {
    myPaddle.move(-2 * GAME_SPEED);
    } else if (gameAction == RIGHT) {
    myPaddle.move(2 * GAME_SPEED);
    return;
    * Clear the game screen
    private void clear(Graphics g) {
    g.setColor(0xFFFFFF);
    g.fillRect(0, 0, getWidth(), getHeight());
    * Paint the game screen
    public void paint(Graphics g) {
    synchronized (g) {
    * Clear the screen
    clear(g);
    g.setColor(0x000000);
    * Paint the ball and paddle
    g.fillRect(myPaddle.x, myPaddle.y, myPaddle.WIDTH,
    myPaddle.HEIGHT);
    g.fillArc(myBall.x, myBall.y, myBall.SIZE,
    myBall.SIZE, 0, 360);
    * The ball thread
    class Ball extends Thread {
    * The ball diameter
    public final int SIZE = mainFrame.getHeight() / 15;
    * The sign of the x component of the velocity
    private int xDir = 1;
    * The sign of the y component of the velocity
    private int yDir = 1;
    * X position of ball
    int x;
    * Y position of ball
    int y;
    * Create a ball
    public Ball() {
    setUp();
    * Set starting position
    void setUp() {
    x = mainFrame.getWidth() / 2;
    y = mainFrame.getHeight() / 10;
    * Loop to run thread, loops until game over
    public void run() {
    while (!gameOver) {
    * Sleep for animation delay
    try {
    Thread.sleep(150 - 10 * GAME_SPEED);
    } catch (Exception e) {
    return;
    int oldX = x;
    int oldY = y;
    * Recalculate x position
    int xPos = x + xDir * GAME_SPEED;
    if (((xPos+SIZE) <= mainFrame.getWidth())
    && (xPos >= 0)) {
    x = xPos;
    } else {
    xDir *= -1;
    AlertType.WARNING.playSound(myDisplay);
    * Recalculate y position
    int yPos = y + yDir * GAME_SPEED;
    if ((yPos >= 0) &&
    ((yPos + SIZE) <=
    (mainFrame.getHeight() - myPaddle.HEIGHT))) {
    y = yPos;
    } else if ((yPos + SIZE) >
    (mainFrame.getHeight() - myPaddle.HEIGHT)) {
    * Bounce off paddle
    if ((xPos <= (myPaddle.x + myPaddle.WIDTH))
    && ((xPos + SIZE) >= myPaddle.x)) {
    yDir *= -1;
    AlertType.INFO.playSound(myDisplay);
    * Player loses
    } else {
    gameOver = true;
    * Get statistic information
    elapsedTime = System.currentTimeMillis()
    - elapsedTime;
    numGames++;
    statsScreen.append(new StringItem("Game " +
    numGames + " over", "Time: " +
    (elapsedTime/1000) + " seconds"));
    * Show the statistics screen
    myDisplay.setCurrent(statsScreen);
    return;
    } else if (yPos < 0) {
    yDir *= -1;
    AlertType.WARNING.playSound(myDisplay);
    mainFrame.repaint(Math.min(oldX, x), Math.min(oldY, y),
    Math.abs(x-oldX) + SIZE,
    Math.abs(y-oldY) + SIZE);
    * The game paddle thread
    class Paddle extends Thread {
    * Paddle width
    public final int WIDTH = mainFrame.getWidth() / 6;
    * Paddle height
    public final int HEIGHT = mainFrame.getHeight() / 15;
    * X position
    int x;
    * Y position
    int y;
    * Create a new paddle
    public Paddle() {
    setUp();
    * Initialize starting position
    void setUp() {
    x = mainFrame.getWidth() / 2 - WIDTH / 2;
    y = mainFrame.getHeight() - HEIGHT;
    * Loop to run paddlethread, loops until game over
    public void run() {
    while (!gameOver) {
    try {
    Thread.sleep(10);
    } catch (Exception e) {
    return;
    * Move paddle right/left
    void move(int delta) {
    int oldX = x;
    int xPos = x + delta;
    if (((xPos + WIDTH) <= mainFrame.getWidth())
    && (xPos >= 0)) {
    x = xPos;
    mainFrame.repaint(Math.min(oldX, x), y,
    Math.abs(x-oldX) + WIDTH, HEIGHT);
    }

    Cross-post
    http://forum.java.sun.com/thread.jspa?threadID=5160243&tstart=0

  • Code for NSImageView

    Using Project Builder, I have made an appleScript application that selects photos with a browser then tells Photoshop to make a series of changes to them using actions. I would like to have an NSImageView as part of the interface window but it seems to need code for many handlers. Is there a sample of workable code for these handlers anywhere? Thanks...

    Hi HerbA
    Some of this code may be of use to you, it's plucked straight out of one of my projects that im working on, it works fine for me in my project. (im open to improvement suggestions also).
    global the_image
    on clicked theObject
    --CLOSES THE VIEWER PANEL--
    if name of theObject is "cancel" then
    delete image of image view "image" of window "VIEWER"
    delete contents of text field "pathto" of (window "VIEWER")
    close panel (window "VIEWER")
    end if
    --OPENS THE VIEWER PANEL--
    if name of theObject is "getviewer" then
    display (window "VIEWER") attached to window "MAIN"
    end if
    --DELET IMAGE FROM IMAGE VIEWER --
    if name of theObject is "delete" then
    delete image of image view "image" of window "VIEWER"
    delete contents of text field "pathto" of (window "VIEWER")
    end if
    --RUNS THE BARBER POLE or spinning ICON--
    tell window "VIEWER"
    set indeterminate of progress indicator "bar_Progress" to true
    set uses threaded animation of progress indicator "bar_Progress" to true
    set animation delay of progress indicator "bar_Progress" to 1
    tell progress indicator "bar_Progress" to start
    end tell
    --GETS THE IMAGE AND OPENS THE IMAGE IN ITS APPLICATION--
    tell window of theObject
    if name of theObject is "userpick" then tell me to get_picture()
    if name of theObject is "openfile" then tell me to open_picture()
    end tell
    end clicked
    on get_picture()
    set the_image to (choose file without invisibles)
    set new_image to load image the_image
    set image of image view "image" of window "VIEWER" to new_image
    set text color of text field "pathto" of window "VIEWER" to {0, 0, 65535}
    set contents of text field "pathto" of window "VIEWER" to the_image as string
    end get_picture
    on open_picture()
    if content of text field "pathto" of window "VIEWER" is not "" then
    tell application "Finder" to open the_image
    else
    display dialog "Please use - Select item to view - first." with icon caution
    end if
    end open_picture
    tell progress indicator "bar_Progress" to stop
    end clicked
    hope this helps
    Budgie

  • Question: Design help Epub FXL

    Hello friends.
    I'm building a fixed layout epub with the newest version of indesign. So far it's pretty amazing, but there are a couple of things I would like to do, but don't know how. Any help would be GREATLY appreciated.
    1. I'm adding a video to some spreads. They autoplay on page load and I've added a 2 second appear animation to avoid the reader seeing the load and play button on the video player before it actually starts playing. Can I add another event to the same element -the video- on the same spread? For instance a disappear animation delayed five seconds? (so the video appears, plays and disappears again)
    2. Can I make audio play across several spreads (and not be cut off on page turn)?
    All the best,
    //Thue

    So, I figured the first question out myself. It's resolved here.
    The second question remains:
    Can I make an audio-clip continue after page turn?
    I found the "Stop on page turn" - but it doesn't seem to work. It's not clicked and the music still stops on page turn. I've tried both options, and it doesn't change anything.

  • Don't understand the code, about boucing ball

    this is a program intends to create a ball and let the ball bouncing until it reaches the right side of the console. It's in the stanford cs106a course.
    I don't the part:
    // assume bounce will move ball an amount above the
    // floor equal to the amount it would have dropped
    // below the floor.
    double diff = ball.getY() - (getHeight() - DIAM_BALL);
    ball.move(0, -2 * diff);does the ball actually reaches the bottom of the console, and them let the ball moves back upwards with the distance 2diff?
    thanks a lot!
    beside, I'm new in this forum, how to let the code show in the code mode? Cause it seems hard to read right now.
    Here is the whole program:
    * File: BouncingBall.java
    * This program graphically simulates a bouncing ball.
    import acm.program.*;
    import acm.graphics.*;
    public class BouncingBall extends GraphicsProgram {
    /** Size (diameter) of the ball */
    private static final int DIAM_BALL = 30;
    /** Amount Y velocity is increased each cycle as a
    * result of gravity */
    private static final double GRAVITY = 3;
    /** Animation delay or pause time between ball moves */
    private static final int DELAY = 50;
    /** Initial X and Y location of ball */
    private static final double X_START = DIAM_BALL / 2;
    private static final double Y_START = 100;
    /** X Velocity */
    private static final double X_VEL = 5;
    /** Amount Y Velocity is reduced when it bounces */
    private static final double BOUNCE_REDUCE = 0.9;
    /** Starting X and Y Velocties */
    private double xVel = X_VEL;
    private double yVel = 0.0;
    /* private instance variable */
    private GOval ball;
    public void run() {
    setup();
    // Simulation ends when ball goes off right hand
    // end of screen
    while (ball.getX() < getWidth()) {
    moveBall();
    checkForCollision();
    pause(DELAY);
    /** Create and place ball. */
    private void setup() {
    ball = new GOval(X_START, Y_START, DIAM_BALL, DIAM_BALL);
    ball.setFilled(true);
    add(ball);
    /** Update and move ball */
    private void moveBall() {
    // increase yVelocity due to gravity on each cycle
    yVel += GRAVITY;
    ball.move(xVel,yVel);
    /** Determine if collision with floor, update velocities
    * and location as appropriate. */
    private void checkForCollision() {
    // determine if ball has dropped below the floor
    if (ball.getY() > getHeight() - DIAM_BALL) {
    // change ball's Y velocity to now bounce upwards
    yVel = -yVel * BOUNCE_REDUCE;
    // assume bounce will move ball an amount above the
    // floor equal to the amount it would have dropped
    // below the floor.
    double diff = ball.getY() - (getHeight() - DIAM_BALL);
    ball.move(0, -2 * diff);
    }Edited by: 967521 on 2012-10-24 下午7:11
    Edited by: 967521 on 2012-10-25 上午7:43
    Edited by: Melissa13 on 2012-10-26 上午7:21

    Put your code between tags and it'll show correctly (you should edit the post now).                                                                                                                                                                                   

  • Making titles longer?

    I dropped a title template on my timeline and have edited the way I want it, and have added an animation that makes the text appear from off screen. My problem is I need to make the text appear longer on the screen at the end.
    If I drag the right end to make it longer, or use time stretch to expand it, it does change the overall length of the title, but it also slows the animation, delaying when the title finishes appearing.
    Is it possible to change the duration of a title WITHOUT changing the speed of the text animation?
    Bruce.

    Thanks Peter but I have a question about that. It would take too long to recreate the title from scratch for a second instance, so I'm trying to use copy/paste to create the second instance and then remove the text animation from the second one.
    I can copy the first one to the clipboard, and then paste, but the 2 titles are now linked somehow. The second one is not an independent copy. If I remove the text animation from the second one, the first one loses its text animation too.
    How can I copy a title without the copies remaining linked to the original?
    Bruce.

Maybe you are looking for

  • Issue with LDAP Connection becuase of Network issue

    Hello All, We have some network issues going on which is causing the NIC (Network interface card) to failover to another NIC. Due to this failover SUN access manager's LDAP connection pool fills up and we see errors in logs "Directory is down". We ha

  • Unexpected error during mapping execution

    Hello, we are implementing business intelligence for Siebel 8.1. Having one strange issue and hoping anybody could help us out. We are using OWB 10.2.0.1. Certain error appears during mapping execution LOAD_SR which basically loads service requests f

  • 1/2 of phone not working. I think.

    I noticed this when i bought the phone, but didn't think anything of it until now (its been two weeks). For some reason, the left speaker on the bottom of the iPhone is the only one that works. Is this intentional or is the right one (if it exists) s

  • Invalid Leaf Count Record

    When I repaired my startup disk with Disk Utility, an invalid leaf count record error was reported. From looking at other posts, it appears that one of the recommended things to do for this is trying to repair the issue with Disk Utility. I tried thi

  • Lion software update didn't find updates

    Lion 10.7.2 fresh install (not upgrade). Software updates always says "Your software is up to date. Software Update doesn't have any new software for your computer at this time." Same result after applying  10.7.3 Combo update. Many errors in console