Moving a box with a thread

i have been trying to do this for like a week. i have a class Panel and a class Car and i want to draw a moving box on the panel. if i put every thing in the class Panel it works but then if i put it in to Car it doesn't. i want the class Car to implement Runnable (when i did this in the Panel class i just created a new thread) Car should have a method draw (so it knows how to draw a car) and method move (it moves the car across the screen) here is my code that i have now
public class Panel extends JPanel implements ActionListener{
     private JPanel controls;
     private JButton light, start;
private Car c = new Car();
     public Panel(JFrame f) {
          c.setMove(false);
          controls = new JPanel();
          f.add(controls, BorderLayout.SOUTH);
          start = new JButton("start");
          start.addActionListener(this);
          controls.add(start);
     protected void paintComponent(Graphics g) {
super.paintComponent(g);
c.drawCar(g);
     public void actionPerformed(ActionEvent e) {
          if(e.getSource() == start){
               if(c.isMove() == false){
                    c.start();
               }else if(c.isMove() == true){
                    c.stop();
               }else{
                    System.err.println("error");
public class Car extends JComponent implements Runnable{
     private double carSize = 25;
     private boolean move = true;
     private int carX = 0, carY = 5;
     public void drawCar(Graphics g){
Graphics2D g2d = (Graphics2D)g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setColor(Color.red);
g2d.fill(new Rectangle2D.Double(carX, carY, carSize, 12));
     public int getCarX() {
          return carX;
     public void setCarX(int carX) {
          this.carX = carX;
     public boolean isMove() {
          return move;
     public void setMove(boolean move) {
          this.move = move;
public void run(){
while(isMove()){
     setCarX(getCarX() + 1);
if(getCarX() + 50>= getWidth())
break;
try{
Thread.sleep(10);
catch (InterruptedException ignored){
System.out.println("Error");
setMove(false);
repaint();
Thank you everyone
artem

               if(c.isMove() == false){
                    c.start();
               }else if(c.isMove() == true){
                    c.stop();
               }else{
                    System.err.println("error");
Hi, welcome to the forums!
Just some administrative stuff: in the future, when you post code, please selected it and hit the "CODE" button in the toolbar of the editing box.
As the compiler is probably telling you, your "Car" class has no methods called start() and stop(). You are probably thinking of Thread.start() and Thread.stop(), but your Car class implements Runnable, which only has a run() method.
If you want the code in c.run() to be run in a new thread, create a new thread and start it like this:
Thread carThread = new Thread(c);
carThread.start();

Similar Messages

  • Unable to delete photos from  my desktop , I get a drop down box with continued blue/ white bars - now 6 hours

    Having dragged 8 photos onto my desktop from iphoto  for the purpose of easy addition to an email , I now find that when I  dragged them to the Trash bin , they fail to delete.
    I get a drop down box with continued blue/ white bars , stating "moving to trash " .
    It's now  6 hours and I cannot stop either. Tried to shut down my computer and reboot but it won't let me . I tried  turning the power off , but the problem remains .
    Any help would be welcome.

    Hey ! 
    I have found the solution myself  !!!
    Go ..... Apple in the toolbar - Force quite - select finder - then relaunch .
    Brilliant

  • When I try to add an RSS or Atom feed, I get a dialog box with Open or Save instead of adding the feed to NewsFox like it used to do.

    With Firefox 4.x, when I added a feed, it would open NewsFox in a new tab, and bring up a dialog box with info about that feed. I would click on "test this feed" and it would put all available items into NewsFox. Now, I get this dialog box with Open or Save. If I click on Open (declaring Firefox as the preferred app), then it opens the feed itself, it doesn't add it to NewsFox. I've tried going into Options and about:config but don't see anything to change that would fix this problem. I tried Search in Firefox Help but no relevant threads came up.

    Thanks Cor-El. I already have it set to "Use NewsFox." I'm stumped.

  • On some websites, some characters load as only boxes with four numbers/letters in them. What is this, and how do I get it to display the characters properly?

    Several pages will display characters as only boxes with four letters in them. I would like it to display all the characters.

    See my posts in this thread: [/questions/766381]
    Pages that use Unicode (UTF-8) display a little box with the hex code if the character can't be displayed. That allows you to look up the character in a table.
    This can be caused by missing font support for East Asian (CJK: Chinese, Japanese, Korean) or complex script (Indic) languages.

  • Help: Iphoto 6 photos missing, gray box with exclaimation point

    Hi all. I am a terrible manager of my 14K photos. My husband said my system could not process updates because I have so little hard drive space, so I went on this massive effort to purge photos I did not need. I thought I was being virtous by going to the pictures folder from finder, finding the album, and deleting there, but now I have learned that I actually need to delete from the iphoto library. Now, when I go into i photo, there are a lot of big empty gray boxes with an exclaimation point, including for photos I know I did not delete (I can still see the thumbnail in some cases). I am using i photo 6 and would hate to lose these pictures. We have an external hard drive and I was in the process of moving some of the files and videos. Can someone help? I am also wondering what the best way to clean up my library is. Thanks in advance for anyone who can help! I live abroad and so can't go into an Apple store for help. Thanks!

    That's an indicagtion the the file path to the original image files has been broken. Make a temporary, backup copy (if you don't already have a backup copy) of the library and apply the two fixes below in order as needed:
    Fix #1
    Launch iPhoto with the Command+Option keys held down and rebuild the library.
    Select the options identified in the screenshot. 
    Fix #2
    Using iPhoto Library Manager  to Rebuild Your iPhoto Library
    Download iPhoto Library Manager and launch.
    Click on the Add Library button, navigate to your Home/Pictures folder and select your iPhoto Library folder.
    Now that the library is listed in the left hand pane of iPLM, click on your library and go to the File ➙ Rebuild Library menu option
    In the next  window name the new library and select the location you want it to be placed.
    Click on the Create button.
    Note: This creates a new library based on the LIbraryData.xml file in the library and will recover Events, Albums, keywords, titles and comments but not books, calendars or slideshows. The original library will be left untouched for further attempts at fixing the problem or in case the rebuilt library is not satisfactory.
    Happy Holidays

  • Mail has blue boxes with question marks

    I have a new MacBook Pro. In mail when I receive anything with images, I just see blue boxes with question marks. Yes, i have tried reloading Mail, I have tried clicking on and off from Display remote Images, I have checked all my preferences and it just won't work.
    How can i fix this - there must bean answer.
    I am running Mail 5.2...it doesn't do this on my son's machine which is the same. OS 10.7.4

    Hello Linc,
    I'm not one to normally thread jack a post, but I am having the exact same issues, i found your posts while trying to solve the problem. Like tmack101, when I boot into safe mode the images load correctly, so something is loading up at startup thats causing the issue.  I am very PC proficient, but am still new to OS X.  I will post my results below to your terminal commands:
    The domain/default pair of (/Users/darkster/Library/Preferences/com.apple.mail.plist, PreferPlainText) does not exist
    mbair:~ darkster$
    Step#1:**(wierd, I have little snitch uninstalled)**
    kextstat -kl | awk '!/com\.apple/{printf "%s %s\n", $6, $7}'
    at.obdev.nke.LittleSnitch (2.4.0)
    com.parallels.kext.prl_hypervisor (6.0
    com.parallels.kext.prl_hid_hook (6.0
    com.parallels.kext.prl_usb_connect (6.0
    com.parallels.kext.prl_netbridge (6.0
    com.parallels.kext.prl_vnic (6.0
    Step#2
    com.parallels.vm.prl_naptd
    com.parallels.desktop.launchdaemon
    com.microsoft.office.licensing.helper
    com.adobe.SwitchBoard
    com.adobe.fpsaud
    at.obdev.littlesnitchd
    Step #3
    (x|openbsd)/{print $3}'
    com.paragon.ntfs.upd
    com.paragon.ntfs.trial
    com.sony.PMBPortable.AutoRun
    com.parallels.vm.prl_pcproxy
    com.parallels.desktop.client.launch
    com.adobe.CS5ServiceManager
    at.obdev.LittleSnitchUIAgent
    at.obdev.LittleSnitchNetworkMonitor
    sibersystem.RFAgent.plist
    com.microsoft.SyncServicesAgent
    com.google.keystone.user.agent
    com.adobe.ARM.df0ab5bbe6f698196fcc21e3c1e66dcb758bd911f4d637272d9d8109
    Step #4
    P*P,Priv,Qu,Scripti,Servi,Spo,Sta}* L*/Fonts 2> /dev/null
    /Library/Components:
    /Library/Extensions:
    /Library/Frameworks:
    AEProfiling.framework        ProMetadataSupport.framework
    AERegistration.framework    TSLicense.framework
    Adobe AIR.framework        XSKey.framework
    AudioMixEngine.framework    iLifeFaceRecognition.framework
    FxPlug.framework        iLifeKit.framework
    NyxAudioAnalysis.framework    iLifePageLayout.framework
    PluginManager.framework        iLifeSQLAccess.framework
    ProFX.framework            iLifeSlideshow.framework
    /Library/Input Methods:
    /Library/Internet Plug-Ins:
    AdobePDFViewer.plugin            Quartz Composer.webplugin
    CitrixICAClientPlugIn.plugin        QuickTime Plugin.plugin
    EPPEX Plugin.plugin            SharePointBrowserPlugin.plugin
    Flash Player.plugin            SharePointWebKitPlugin.webplugin
    Flip4Mac WMV Plugin.plugin        Silverlight.plugin
    JavaAppletPlugin.plugin            flashplayer.xpt
    LogMeIn.plugin                iPhotoPhotocast.plugin
    LogMeInSafari32.plugin            npContributeMac.bundle
    LogMeInSafari64.plugin            nsIQTScriptablePlugin.xpt
    /Library/Keyboard Layouts:
    /Library/LaunchAgents:
    at.obdev.LittleSnitchNetworkMonitor.plist
    at.obdev.LittleSnitchUIAgent.plist
    com.adobe.AAM.Updater-1.0.plist
    com.adobe.CS5ServiceManager.plist
    com.parallels.desktop.launch.plist
    com.parallels.vm.prl_pcproxy.plist
    com.sony.PMBPortable.AutoRun.plist
    /Library/LaunchDaemons:
    at.obdev.littlesnitchd.plist
    com.adobe.SwitchBoard.plist
    com.adobe.fpsaud.plist
    com.apple.aelwriter.plist
    com.apple.remotepairtool.plist
    com.microsoft.office.licensing.helper.plist
    com.parallels.desktop.launchdaemon.plist
    /Library/PreferencePanes:
    Flash Player.prefPane
    /Library/PrivilegedHelperTools:
    com.microsoft.office.licensing.helper
    /Library/QuickLook:
    GBQLGenerator.qlgenerator    iWork.qlgenerator
    ParallelsQL.qlgenerator
    /Library/QuickTime:
    AppleAVCIntraCodec.component        FCP Uncompressed 422.component
    AppleHDVCodec.component            Flip4Mac WMV Advanced.component
    AppleIntermediateCodec.component    Flip4Mac WMV Export.component
    AppleMPEG2Codec.component        Flip4Mac WMV Import.component
    AppleProResCodec.component        IMXCodec.component
    DVCPROHDCodec.component            LiveType.component
    DesktopVideoOut.component
    /Library/ScriptingAdditions:
    Adobe Unit Types.osax
    /Library/Spotlight:
    GBSpotlightImporter.mdimporter    ParallelsMD.mdimporter
    LogicPro.mdimporter        iWork.mdimporter
    Microsoft Office.mdimporter
    /Library/StartupItems:
    /etc/mach_init.d:
    /etc/mach_init_per_login_session.d:
    /etc/mach_init_per_user.d:
    com.adobe.SwitchBoard.monitor.plist
    Library/Address Book Plug-Ins:
    Library/Fonts:
    Library/Frameworks:
    Library/Input Methods:
    .localized
    Library/Internet Plug-Ins:
    Library/Keyboard Layouts:
    Library/LaunchAgents:
    com.adobe.ARM.df0ab5bbe6f698196fcc21e3c1e66dcb758bd911f4d637272d9d8109.plist
    com.apple.AddressBook.ScheduledSync.PHXCardDAVSource.B3245B3F-8352-4668-A4F2-1AB BDFD6FAD3.plist
    com.apple.CSConfigDotMacCert-**********@me.com-SharedServices.Agent.plist
    com.apple.FolderActions.enabled.plist
    com.apple.FolderActions.folders.plist
    com.google.keystone.agent.plist
    com.microsoft.LaunchAgent.SyncServicesAgent.plist
    sibersystem.RFAgent.plist
    Library/PreferencePanes:
    .c4dsetup            .localized
    .c4dsetupCINEMA 4DF51A2E69
    Library/ScriptingAdditions:
    RFAgentExtension.osax
    Library/Services:
    Step #5
    iTunesHelper, AdobeResourceSynchronizer, Launchpad, Windows Server Launchpad
    Thanks in advance for your assistance...

  • How do you disable "Run with Multiple Threads" in a standalone EXE

    I have a program written in Labview 6.1.  After moving to a different hardware platform, my program has started crashing at the same point every time it is run.  I eventually found out that the cause of the crash is the fact that the new hardware has a dual core processor.  I confirmed this by disabling "Run with multiple threads" and now the program works fine.  What I need to know now is how to disable the same setting in a built EXE file, since as far as I know the "Run with multple threads" setting only affects execution in the Labview Dev environment.
    Thanks for any help,
    Dave

    Greg McKaskle once posted that using a non-reentrant (VI is NOT re-entrant) wrapper VI to make the calls to the dll will prevent simultaneous execution of the dll.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • When I used mountain lion in a preview of a picture I could just press the icon that was a box with an arrow pointing up and that would allow me to share (message, email, Facebook, etc) the image.  Now in Yosemite in preview if I click the box-arrow

    When I used mavericks in a preview of a picture I could just press the icon that was a box with an arrow pointing up and that would allow me to share (message, email, Facebook, etc) the image. Now in Yosemite in preview if I click the box-arrow

    Found my answer in another thread-  this is what I did
    GO to System Preferences > Users > Right Click on your Name > Advanced Options > and refresh your UUID
    Restart your System and the widgets are all back
    This solution worked fine for me!

  • HT1918 I have trial version of Hulu. Tried to set no renewal option and will not come up on screen after clicking renewal options or box with subscription price.

    I have trial version of Hulu. Tried to set no renewal option and will not come up on screen after clicking renewal options or box with subscription price.

    I have been getting the black screen after waking. My screen is not set to sleep, so I don't know if it's related. Some discussion of the problem here:
    http://discussions.apple.com/thread.jspa?threadID=1227085
    http://discussions.apple.com/thread.jspa?threadID=1243743

  • When moving from a list of threads view to a thread would be nice to jump to last thread read.

    When moving from a list of threads being viewed to a thread, it would be nice to jump to last thread read or first unread thread.
    Sometimes the threads get rather long.  Sometimes I haven't read a thread in awhile & I forget where I have left off reading a thread. It would be nice to have an icon to click on to move to your last read post or the first non-read post. 
    Seems this could be implemented in javascript without too much problem.  Might be a problem of when to get rid of the tracking data.
    Robert

    This would be a new capability.   I didn't know you could jump directly to the last post in a thread by clicking on the posters name in your discussions.  However, I am interested in jumping to the first post that I haven't read.
    Since writing my original post, I realize that software doesn't know what posts I have read. Lets say there are are 26 posts in a thread.  Lets assume these are divided into three pages with at most 10 items in a page:
    page 1 -- a, b, c, d, e, f, g, h, i, j
    page 2 -- k, l, m, n, o, p, q, r, s, t
    page 3 -- u, v, w, x, y, z
    The software know that I have viewed the first three pages.  It doesn't know what post on the pages I have read.  The software would need to assume I have read all the available posts on a page.
    Now lets assume that 12 more post were added.  This results in:
    page 1 -- a, b, c, d, e, f, g, h, i, j
    page 2 -- k, l, m, n, o, p, q, r, s, t
    page 3 -- u, v, w, x, y, z, aa,bb,cc,dd
    page 4 -- ee,ff,gg,hh,ii,jj,kk,ll
    It would be nice if I could go to aa. 
    Jumping to the last post in the thread doesn't hack it. You have to spend a lot of time finding where you left off your reading.
    Intesting, the list of your posts on your homepage usings the term Last Activity were as Your Discussions uses the term Last Post. The terminalogy should be the same & should act the same.  For the existing capability of going the the last post, I was thinking of Goto Last Post.

  • I keep getting an intermittent error on web pages where a blue box with a question mark appears instead of pictures.  For example Facebook and Zappos would load normally on one visit, but if I visit other websites and return I get the blue box.

    I keep getting an intermittent error on web pages where a blue box with a question mark appears instead of pictures.  For example Facebook and Zappos would load normally on one visit, but if I visit other websites and return I get the blue box instead of pictures. If I restart the problem will go away temporarly. However, normally returnes in time.

    HI,
    From the Safari Menu Bar click Safari/Preferences then select the Appearance tab. Tick the box next to: Display images when the page opens.
    If that box is already ticked, from the Safari Menu Bar, click Safari / Empty Cache. When you are done with that...
    From the Safari Menu Bar, click Safari / Reset Safari. Select the top 5 buttons and click Reset. Relaunch Safari. If you still have problems loading images, go here for trouble shooting 3rd party plugins or input managers which might be causing the problem. Safari: Add-ons may cause Safari to unexpectedly quit or have performance issues
    Web pages now include a small icon or 'favicon' which is visible in the address bar and next to bookmarks. These icons take up disk space and slow Safari down. It is possible to erase the icons from your computer and start fresh. *To delete Safari's icon cache using the Finder, open your user folder, navigate to ~/Library/Safari/ and move this file "webpageIcons.db to the Trash.*
    Make sure Safari is not running in Rosetta. Right or control click the Safari icon in your Applications folder then click Get Info. In the Get Info window click the black disclosure triangle so it faces down. Where you see Open using Rosetta... make sure that is NOT selected.
    If you still have problems, go to the Safari Menu Bar, click Safari/Preferences. Make note of all the preferences under each tab. Quit Safari. Now go to ~/Library/Preferences and move this file com.apple.safari.plist to the Desktop. Relaunch Safari. If it's a successful launch, then that .plist file needs to be moved to the Trash.
    Carolyn

  • My mail, when reading an email, has an icon which is like a box with an arrow pointing down into it, what is it for?  When I tap it my email goes "somewhere" out of my inbox.  It still apperars in "all Mail" mailbox.

    My mail, when reading an email, has an icon which is like a box with an arrow pointing down into it, what is it for? 
    When I tap it my email goes "somewhere" out of my inbox. The email, which was moved from my inbox still apperars in "ALL Mail" mailbox.

    That is the "Move" the email icon. Tap on that icon and you can move the email to any box or folder that is in black type on the left side of the window - under the Mailboxes heading. If the type is in grey on the left side - that box or folder is not an option that you can use.

  • How can I manage two boxes with exchange mail clie...

    I have two mail boxes and I need to update it from my nokia N8.
    one is a company's business and works with exchane server, the other is hotmail.
    I need to sync with mail for exchange, but once set up the company, if I try to insert a new exchange box with the default client replies that I have already reached the maximum number of boxes exchange.
    Is there a way to synchronize them both (of course with exchange)?
    I tried to synchronize with hotmail PoP / IMAP but it is a disaster. I do not have all the folders, and then I can not sync contacts and calendar.

    Hi aningro,
    Welcome to Nokia Support Discussions!
    You can add only one Mail for Exchange mailbox on Nokia N8. This is by design and unfortunately cannot be changed. The workaround is to use IMAP, like you mentioned, and it should be possible to synchronise your folders even over IMAP.
    To synchronise subfolders perform the following steps:
    Go to Mail.
    Open your Inbox.
    Tap the Inbox on the top of the screen.
    Swipe the list and select Folders, and Folder list opens.
    Select the folder you would like to sync.
    Also, please see this thread for more information on IMAP folder synchronisation.
    Hope this helps,
    Puigchild
    If you find this post helpful, a click upon the white star at bottom would always be appreciated.
    If it also solves your problem, clicking ACCEPT AS SOLUTION below it will benefit other users!

  • How to move R12 apps-tier to another box with same hostname and a new IP ?

    Hi , we want to move R12 apps-tier to another box with same hostname,same application paths and a new IP. What is the best way? SR recommends cloning but I am seeking for a short way,Thanks.

    Hi , we want to move R12 apps-tier to another box with same hostname,same application paths and a new IP. What is the best way? SR recommends cloning but I am seeking for a short way,Thanks.Cloning is the best approach.
    You could simply copy all the files (without running preclone), clean FND_NODES and bring the services up.
    How to Clean Nonexistent Nodes or IP Addresses From FND_NODES [ID 260887.1]
    How to get a clean Autoconfig Environment ? [ID 391406.1]
    You would still need to relink the executable files as per the docs in this thread -- Need clarification on Solaris 10 upgrade for E Business suite application
    Again, I would recommend cloning as it is the easiest/shortest method.
    Thanks,
    Hussein

  • What does the icon with the Box with a Down Arrow do?

    When I open certain messages, at the bottom toolbar instead of a trash can icon I get an icon that looks like a moving box with a arrow pointing down. When I have accidentally pressed it the message disappears. I cant find it in any folder or location? Any ideas what happens to the emails?

    I noticed this new icon appeared after the latest iPhone IOS4 update. From my experience, clicking on that icon throws the email into the "filters" I've created in Gmail on my desktop computer. I'm not sure how it would respond if I didn't have a filter for a particular email. I think another forum user mentioned it gets dumped in the "all mail" folder. Not sure how that would be helpful. If someone from Apple could give us the textbook definition of this new icon and it's use, I'd appreciate it.

Maybe you are looking for

  • What use of having double precision in java.awt.geom?

    Hi, I am trying to draw a line using Line2D with this param: g2d.draw( new Line2D.Double( 1.1d, 1.5d, 1.9d, 1.5d ) ); in my own JPanel paint method. However, the result is that the panel does not display a line nor a dot at all. Only when i change it

  • Cannot display the actual value of ClobDomain variable in jspx

    I have a custom table and three of its fields/columns are of type Clob and they contain xml data. To populate this table I used ADF Business Component and in my application these fields are defined as ClobDomain. Inserting records to this table works

  • Does MV45AFZZ trigger when CRM sales order is replicated into ECC

    Hi All, When a Sales order is created in CRM, it is replicated automatically using BDOCS from CRM into ECC. I have requirement to code the logic during the process, when sales order is replicated into ECC. So I need to know the BAPI which is actually

  • Can't share a friend's screen anymore - any ideas?

    I'm trying to help a friend with his iMac, but we can't seem to share screens anymore. We are both using late 2009 iMacs. I am running Mountain Lion and he is still running Lion. So I am running iMessages and he is running iChat. If I select his name

  • Insert Billing Block if Contract is Changed

    Dear Experts, We have Rental Contract / Service Conract scenario where we create a Contract with BIlling Plan & create Invoice eveny month thru VF04. We now have a requirement to insert Billing Block when the Conract is Created. This is easily achiev