Can't get ball to move

I am trying to make a ball move on my applet but am having trouble trying to make it happen. I have a class golfcourse which draws the course, a ball which handles the drawing and (hopefully) it's movements and a bar class which extends JProgressBar and stops moving from left to right when clicked on.
I want to firstly make the ball move forward based on the where the bar is stopped (percentage) and currently have some permanent numbers which will eventually be based on club selected.
What I would like to ask is whether I am on the right track or if not, can you provide any good advice?
Here is my code:
class ball
public class Ball
     int x_pos = 228; // x position
     int y_pos = 445; // y position
     int y_final = 745;
     int x_final = 228;
     int r = 10; //radius
     DistanceBar12 dest;
     int targetDest;
     int maxDist = 200;
     private int distance; // how far the ball will travel after distance bar pressed
     public void paint(Graphics g)
          g.setColor(Color.black);
          g.fillOval(x_pos, y_pos, r, r);
     public void move()
                         y_pos ++;
     } // close move()
          public int getY_pos() 
          return y_pos;
          public int getX_pos() 
          return x_pos;
          public int getmaxDist() 
          return maxDist;
} // close classclass GameScreen2
class GameScreen2 extends JPanel {
     GolfCourse gc = new GolfCourse();
     Ball ball = new Ball();
      public GameScreen2(){
      public void paintComponent(Graphics graphics) {
         Graphics2D g = (Graphics2D) graphics;
         super.paintComponent(g); //paint background
gc.paint(g);
ball.paint(g);
   }class MainGame2
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.Border;
public class MainGame2 extends JApplet implements Runnable{
final DistanceBar12 bar = new DistanceBar12();
int finalDest;
Thread th;
Ball ball;
   public void init() {
      buildUI(getContentPane());
        bar.start();
        bar.setMaximum(100);
            addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
                bar.stop();
                JOptionPane.showMessageDialog(bar,
                 bar.getValue() + " percent");
                bar.start();
   void buildUI(Container container) {
      container.setLayout (new BoxLayout (container, BoxLayout.Y_AXIS));
      GameScreen2 screen = new GameScreen2();
      container.add(screen);
       container.add(bar);
      screen.setAlignmentX(LEFT_ALIGNMENT);
      bar.setAlignmentX(LEFT_ALIGNMENT);
   public void start()
          th = new Thread (this);
          th.start ();
     public void stop()
     public void run ()
          finalDest = ball.getY_pos() + (bar.getValue() * ball.getmaxDist() / 100);
          // Erniedrigen der ThreadPriority um zeichnen zu erleichtern
          Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
          while (true)
               if (ball.y_pos < finalDest)
                    ball.move();
                    repaint();
               try
                    // Stoppen des Threads f�r 10 Millisekunden
                    Thread.sleep (15);
               catch (InterruptedException ex)
                    // do nothing
               // Zur�cksetzen der ThreadPriority auf Maximalwert
               Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
// ball and course do not appear in applet when this is included
//          public void paint (Graphics g)
//          ball.paint(g);
     public void destroy()
}

If you move the ball-position-updating code to Ball, you'll have to make it implement Runnable, and you'll need to pass a reference to the component that contains it so you can call its repaint method. Alternatively you can try active rendering (I believe that's the correct term) -- where the applet doesn't wait for repaints() to be called.

Similar Messages

  • How can I get an itunes movie from macbook to apple tv via airplay, how can I get an itunes movie from macbook to apple tv via airplay

    how can I get an itunes movie from macbook to apple tv via airplay?

    You don't use Airplay.  You set up Home Sharing on both and under the Computers section of AppleTV you'll then find it under Movies (or Rentals if rented), assuming it's in a compatible format.
    AC

  • My e-mail address has changed and i-tunes still recognizes me by the old one. I can't get authorization to move songs from one computer to the next.

    When I first got started with Mac, I had a different e-mail address. I have a new e-dress and new passwords, but much of what I bought was with that old e-dress. Now, I'm trying to migrate my i-tunes library to a new computer, and I can't get authorized to move or play songs on the new computer.
    Does anyone know what to do? (A once and for all reset of Apple username and password).....
    Thnx

    Have the tracks become unchecked? iTunes will skip unchecked tracks, so if they're all unchecked, iTunes will play one and then stop. If this is indeed the case, re-checkmark the tracks - Command-click on any checkbox will select or unselect them all - and you should then have continuous playback.
    Hope this helps.

  • How can i get my rented movie itunes download is informing waiting

    how can i get my rented movie itunes download is informing waiting

    hi
    i used my ipad for downloding. when i connect to my imac , itunes there are no available downlods, they charged me already

  • Mouse pointer is frozen in left corner of monitor.  restarted, can't get it to move

    My Power Mac G-4's mouse indicator/pointer is frozen in  the upper left corner of the monitor.  I can't get it to move.  I have restarted, powered down, checked all connections to no avail.    Anybody have any ideas?  Thanks.

    I just had this problem. It turned out to be a bad kernel extension. Here's how I solved it:
    While booting, hold <Shift> to boot into "Safe Boot". I was able to control the mouse from there.
    In Finder, navigate to /System/Library/Extensions.
    Choose the "list" view so you can see the details of each file.
    Right-click on one of the column headers and make sure that "Date Created" is checked.
    Sort by "Date Created".
    Most of the extensions should now be clustered into groups which all have the same date (when the MacOS update providing those extensions was built). What you want to look for are some extensions which are "oddballs", ones which don't share a date in common with any other extensions. To verify that it didn't come from Apple, you can use Get Info to see if the copyright is from Apple or if it is from another company or missing, entirely.
    I found three oddballs on my computer. What I did was empty my trash, and then I moved those three to the trash (so that I could restore them, if I wanted), and then I rebooted out of Safe Boot.
    After the reboot, everything was fine. Hope this helps someone.
    Incidentally, the three extensions were named JMicronATA.kext, GenericUSBXHCI.kext, and AppleBMC.kext.

  • I can't get a purchased movie to play, even though it seems to have downloaded properly

    I can't get a purchased movie to play, even though it seems to have downloaded properly. Any help?

    Hello, Gemma. 
    Thank you for visiting Apple Support Communities. 
    I would recommend trying the steps in the articles below.  If none of the steps work please reply back with any errors received and which computer operating system you are using. 
    Troubleshooting iTunes for Windows Vista or Windows 7 video playback performance issues
    http://support.apple.com/kb/ts1718
    iTunes for Windows XP: Troubleshooting video playback
    http://support.apple.com/kb/TS1386
    Cheers,
    Jason H. 

  • Can i get my rented movies off my ipad and put them on my PC, as i do not have posession of my ipad and i wont for awhile, also can i change the password remotely for my ipad to avoid intrusions?

    can i get my rented movies off my ipad and onto my PC without my ipad in my possession? also can i change my password to access my ipad remotely to stop the intrusions?

    Where did the movies come from?
    For what you said you should be easily be able to do what you want except for:
    "remove them from the ipad but still have access to them for viewing on the road or at hotel"
    Home sharing only works wehn the devices are connected to the same network
    Understanding Home Sharing
    If they are iTunes purchases, you should be able to redownload most iTunes purchases on the road if you have an internet connection by:
    Downloading past purchases from the App Store, iBookstore, and iTunes Store

  • When I use a tool on an enlarged image the image freezes and I can't get it to move unless I change tools. I tried resetting tools and uninstalling and reloading CC. What should I do?

    When I use a tool on an enlarged image the image freezes and I can't get it to move unless I change tools. I tried resetting tools and uninstalling and reloading CC. What should I do?  Once any tool is used I can't change its size or move the image.

    Howdy,
    Sorry for the lack of info. It is Adobe Photoshop CC, I have been using
    CS5 and am trying the trial version of CC to see if it worth changing
    to. Any tool works once but freezes the tool sizing and image movement.
    I am also using the Beta version of Mac Yosemite. But the CS5 version is
    working fine.
    Hasta,
    Bob McCaw

  • I don't no much, but I can follow instructions. How can I get my rental movie from my iPhone to my iPad.... And I've rentented another movie, now I want to get it from pc to iPad....help be much appreciated...

    I don't know much, but I can follow instructions. How can I get my rental movie from my iPhone to my iPad.... And I've rented another movie, now I want to get it from pc to iPad....help be much appreciated...

    Did you rent the film directly on the iPhone ? I've never rented films, but from : http://support.apple.com/kb/HT1415 :
    You can move the rental between devices as many times as you wish during the rental period. However, the movie can only be played on one device at a time. If you rent a movie on an iPhone, iPad, iPod touch, or Apple TV, it is not transferable to any other device and you must watch it on that device.
    If you've rented a film on your computer's iTunes then you should be able to sync it to your iPad from your computer's iTunes via the Movies tab that shows on the right-hand side of iTunes when you've selected the iPad 'device' on its left-hand side

  • How can I get an anamorph movie to widescreen in IDVD

    Hi, I NEED URGENT HELP!
    A friend of mine and I cut and created a movie on his PC with Premiere Pro 2.0. Now I need to create a high quality dvd from it but I can't get the anamorph data to play in widescreen on my IMac. neither in I Movie nor in IDVD. I tried and burned DVDs in both formats 4:3 and 16:9 but both times the film didn't convert to widescreen and on top the movies looked bad- really bad quality, even though the orignal data my friend gave me, is very high quality film resolution.
    What do I need to do to convert the xxx.mov anamorph (16:9) into a widescreen IDVD?
    My friend says the original material is: Mini DV, PAL 720x576 Pixel, anamorph (16:9)
    Or in what form/size do I need the movies/data from him to make sure I can burn a widescreen dvd with it?
    Please help!

    I am not sure about SWF support in Acrobat 8.x, however, if it is supported, you will have to add it to the PDF after the PDF has been created.  You can leave the space for it in your FrameMaker document and add it via the Mulimedia Tool.
    I do know that SWF is fully supported in Acrobat 9.x, but in this case you will also have to add the SWF to the PDF after converting the FrameMaker document.  To do this, marquee and area on the PDF using the Flash Tool; Tools > Multimedia > Flash Tool.  You can also simply double click on the PDF with the Flash Tool.  Support for SWF, and several other multimedia file types is much stronger in Acrobat 9.

  • How can I get back my movie logo?

    I have downloaded a film from iTunes from my iPad. When downloaded, at first I could see this downloaded film including the movie cover on the app called 'Video's'.
    After I streamed this film on my tv via the Apple TV, the movie cover logo disappeared and in place of the original movie cover there is just a drawing of a TV.
    How can I get back the original movie cover logo on my iPad ? Does anyone know this?

    I already did the backup and the apps are now in a folder on my pc and appears when I connect my iPhone to the pc on iTunes). I'm happy it can happen... when the new iPhone will arrive I will try soon! Thank you!!!!!

  • Can't get iTunes to move from one song to the next

    I'm using iTunes 7.3.1 on an iMac with OS X 10.4.10. Everything was working fine, but now I can't get the playlists to move automatically from one song to the next. All the songs play if I double click on them individually, but when a song is finished playing, iTunes does not move automatically to the next song. I have to then double click on the next song I want to play. Furthermore, neither the "next," nor the "previous" track functions work. I have tried fiddling with the control settings (Repeat Off, Repeat All, Repeat One), but nothing I have tried makes a difference. Bottom line: If I want to sit at my computer and hear a playlist on iTunes, I have to manually click on each song I want to hear. Not too convenient when I want to listen while walking on my treadmill! Anyone suggestions would be appreciated.
    iMac   Mac OS X (10.4.10)  

    Have the tracks become unchecked? iTunes will skip unchecked tracks, so if they're all unchecked, iTunes will play one and then stop. If this is indeed the case, re-checkmark the tracks - Command-click on any checkbox will select or unselect them all - and you should then have continuous playback.
    Hope this helps.

  • How can I get a quicktime movie in imovie?

    I have a video saved as quicktime, .m4v, .3gp, .m4v and .mov.  None of these will import into iMovie!  How can I get this video in iMove???

    MOV is a container, not a codec. so if it uses a codec that iMovie can read, then it should work.
    .m4v should work. Codecs that work include h.264, DV, HDV, Apple Intermediate Codec, Apple Animation Codec, Motion JPEG/A and a few others.
    Some.commercial .m4v's may have copy protection that would prevent iMovie from opening it.
    Also, if any of these movies have extra tracks beyond the audio and video tracks, they will not work. This would include Chapter Tracks, Tween Tracks, Closed Captioning Tracks, and the like. These extra tracks could possibly be removed in QuickTime Pro.
    .3gp would never work without converting it to something else.

  • Can't get preview from MOV

    I'm trying to encode MOV files as FLV. When I add them to my
    queue, go to settings to crop and resize, I can't get a preview to
    judge how much to crop.
    Anyone else have this problem?
    Anyone have a fix?

    was this ever solved? because i am having a very similar
    issue. using flash CS3 on a macbook pro with external monitor in
    clamshell. here is the odd thing. i have two videos rendered out of
    AE CS3 in apple animation codec (Lossless). the original file size
    for one is a little over 50 MB and the other is 210 MB. i need
    preview in order to set cue points, BUT on the larger video, i am
    having the exact same issue as the earlier poster. it just sits on
    frame one making it impossible to set my cue points :( is flash
    having issues with files of over a certain size? thanks.

  • How can I get an HD movie from iTunes store to play on original iPad

    I recently purchased an HD movie--Brave--from the iTunes store.  I'm trying to play on my original iPad (iPad 1), but iTunes refuses to synch it because it says it is an unsupported format.  The movie is in 1080p format.  I typically get both HD and SD formats when I purchase movies, but iTunes no longer downloads the SD version automatically when I purchase the HD version.  I attempted to get an SD version from the store, but it said I already purchased the movie and instructed me to check the downloads.  There is no SD download pending and a check for new downloads was fruitless.
    Can someone confirm that the original iPad is unable to play HD video?  I imagine it is the 1080p that's the problem.  Can anyone confirm that 720p would work?  Is there no longer a means to get both HD and SD when purchasing a movie from the iTunes store?  If there is, how?
    Thanks for your help.
    Jamie

    You can get the SD or 720p version by:
    Open iTunes 11
    Click iTunes in menu bar > select Preferences...
    Click on the Store tab
    Change When downloading High Definition videos, prefer dropdown to 720p > click OK
    Click on the iTunes Store button
    Click Purchased link
    Click Movies tab
    You should now see a download icon for the movies you already have 1080p version of.
    Click on this download icon to download the 720p version.
    This will put a 720p version in the same folder on your hard drive as the 1080p version.  If you have iTunes setup to play 1080p when available, it will play the 1080p version.  When you connect your iPad 1, it will sync the 720p version.
    Don't forget to change your preference back to 1080p so you can continue to get the higher quality version.

Maybe you are looking for