Flickering screen and unable to create smooth moving

hey, i have been trying to do a player moving in a frame according to cordinations(spl) i'll recieve from the mouse by clicking. well
the plan was to repaint() the screen everytime he moves and then see it moving along the screen.
well, all i saw in the input that that the X,Y are changing correctly but the picture of the "player" is stuck and only repaints only when its in the requested location.
Moreover, there is a weird flickering which is very very annoying :(
ok
enjoy the code
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class GameFrame extends JFrame {
     private ImageIcon battleground= new ImageIcon ("Grass.jpg");
     private int prefferedWidth=1280;
     private int prefferedHeight=920;
     private Player p=new Player();
     public GameFrame() {
          super();
          setLayout(new GridBagLayout());
          setBackground(Color.blue);
          setVisible(true);
          setSize(prefferedHeight, prefferedWidth);
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e1) {
               Point point=new Point(e1.getPoint());
               //point.setLocation( p.getX()+(p.getPic().getIconWidth()/2), (p.getY()+(p.getPic().getIconHeight()/2)));
               while ((point.equals(p.getLocation())==false)) {
               //System.out.println(p.getLocation());
if (point.getX()>p.getX()) {
     p.setX(p.getX()+p.getSpeed());
                                                                                                                   try{Thread.sleep(2);} catch (Exception e) {};
System.out.println("1:"+p.getLocation()+ point+" "+(point.equals(p.getLocation())));
else {
if (point.getX()<p.getX()) {
     p.setX(p.getX()-p.getSpeed());
try{Thread.sleep(2); } catch (Exception e) {};
System.out.println("2:"+p.getLocation()+point+" "+(point.equals(p.getLocation())));
if (point.getY()>p.getY()) {
     p.setY(p.getY()+p.getSpeed());
     try{Thread.sleep(2);} catch (Exception e) {};
System.out.println("4:"+p.getLocation()+point+" "+(point.equals(p.getLocation())));
else{          if (point.getY()<p.getY()) {
     p.setY(p.getY()-p.getSpeed());
               try{Thread.sleep(2);} catch (Exception e) {};
               System.out.println("3:"+p.getLocation()+point+(point.equals(p.getLocation())));
     public void paint (Graphics g) {
          g.setColor(Color.white);
          g.fillRect(0,0,prefferedWidth,prefferedHeight);
          int H=battleground.getIconHeight();
          int W=battleground.getIconWidth();
     for (int i=0; i<=1280/*prefferedHeight*/; i=i+W) {
          for (int y=0;y<= 960 /*prefferedWidth*/;y=y+H) {
               battleground.paintIcon(this,g,i,y);
     p.getPic().paintIcon(this,g, (int) p.getX(), (int) p.getY());
     }

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
//attributes
public class GameFrame extends JFrame {
private ImageIcon battleground= new ImageIcon ("Grass.jpg");
private int prefferedWidth=1280;
private int prefferedHeight=920;
private Player p=new Player(); //Player has own picutre, and location basically
public GameFrame() {
super();
setLayout(new GridBagLayout());
setBackground(Color.blue);
setVisible(true);
setSize(prefferedHeight, prefferedWidth);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //have no idea what that does
// using a mouseclick listener to run those following commands:
addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e1) {
//getting the location of click point
Point point=new Point(e1.getPoint());
//aslong as the location of the player and the location of the requested cordinations are different move the player towards its point. Also Player.speed==1.
while ((point.equals(p.getLocation())==false)) {
//System.out.println(p.getLocation());
if (point.getX()>p.getX()) {
p.setX(p.getX()+p.getSpeed());
try{Thread.sleep(2);} catch (Exception e) {};
System.out.println("1:"+p.getLocation()+ point+" "+(point.equals(p.getLocation())));
else {
if (point.getX()<p.getX()) {
p.setX(p.getX()-p.getSpeed());
try{Thread.sleep(2); } catch (Exception e) {};
System.out.println("2:"+p.getLocation()+point+" "+(point.equals(p.getLocation())));
if (point.getY()>p.getY()) {
p.setY(p.getY()+p.getSpeed());
try{Thread.sleep(2);} catch (Exception e) {};
System.out.println("4:"+p.getLocation()+point+" "+(point.equals(p.getLocation())));
else{ if (point.getY()<p.getY()) {
p.setY(p.getY()-p.getSpeed());
try{Thread.sleep(2);} catch (Exception e) {};
System.out.println("3:"+p.getLocation()+point+(point.equals(p.getLocation())));
//the painiting stuff
public void paint (Graphics g) {
g.setColor(Color.white);
g.fillRect(0,0,prefferedWidth,prefferedHeight);
int H=battleground.getIconHeight();
int W=battleground.getIconWidth();
for (int i=0; i><=1280/*prefferedHeight*/; i=i+W) {
for (int y=0;y<= 960 /*prefferedWidth*/;y=y+H) {
battleground.paintIcon(this,g,i,y);
p.getPic().paintIcon(this,g, (int) p.getX(), (int) p.getY());
}

Similar Messages

  • Runtime error and unable to create new web application

    Hi
    when i create new web application i faced this error Runtime error and unable to create new web application.
    in this farm we have
    2 wfe servers
    2 application servers.
    adil

    Adil,
    There could be many reason like IIS issue, Space issue, Permission issue, SQL issue which is not possible us to guess rather
    you need to jump in the SharePoint log(Program Files\Common files\Microsoft Shared\Web Server Extensions\14\LOGS) and find out the specific error log its throwing after which trouble shoot can be start.
    You can refer few similar threads here -
    Link
    Please 'propose as answer' if it helped you, also 'vote helpful' if you like this reply.

  • I have Photoshop Elements 13 and unable to create a panaroma of my imported photos. I clicked on file and there is no automate and photomerge. Any suggestions?

    I have Photoshop Elements 13 and unable to create a panorama photo of six photos. I imported the photos from my computer successfully and clicked on file. However, there is no automate and photomerge buttons. Any suggestions?

    Make sure you are in Expert Mode and then the photomerge button is in
    "Enhance" menu item.
    Good luck.

  • Flickering Screen and Lack of Full Screen Support, Flickering Screen and Lack of Full Screen Support

    Hi,
    I ran into a few things related to using my Bootcamp MacBook Pro 15” 2011 that I purchased 2012Mar. Having issues on the Mac side, with an external monitor. I bought a ViewSonic VX2753mh LED monitor, hooked it up to my laptop, started in Mac OS and seemed to be going good, able to get 1080p, 1920x1080 res on the monitor even though the 2011 MacBook doesn’t have that resolution on the actual attached screen. BUT, the Viewsonic started to intermittently turn off and back on, in addition when I tried to play a movie (or even a slideshow) in full screen (not mirrored), so that I could surf and watch the movie or slideshow, the full screen version of either would be placed back on my laptop screen while the external monitor had a generic grey with vertical lines screensaver pop up, or vica versa. If I played the movie in a small screen it was ok. Have heard a lot of issues with “flickering”. As for the application situation, maybe that’s something I don’t know about yet since I’m new to Mac. Can I play something like slideshow or a movie in full screen on an external monitor while I surf or type on the laptop monitor? Any ideas on either issue?
    Thanks in advance !!!

    Ok, so I solved my full screen problem with VLC, both slideshows of my pics running full screen on external moniter while I work on laptop, and with movies, still getting my external monitor flickering on and off, other threads stop around May, is there anything new ?

  • Firefox Sync Account Deleted and unable to create new

    My Firefox sync was working fine, until my Firefox for Android, started acting up, and I had to reinstall it. When I tried to set up sync again, it asked for a recovery key, which I didn't have (I know, I'm sorry). Getting the data is not a big deal for me, as my desktop Firefox is still alive and well, so this is where I didn my big mistake. I deleted my sync account. Now I am unable to create a new sync account using that email address, as Sync says, Account already in use. I have deleted it and confirmed in the web portal where it says username/email was not recognised. Please help. I need to set this up. I am reluctant to use a different email account, as all my details are tied in with this one, and I have been using this forever.
    Firefox Version: 17
    Firefox for Android Version: I don't know, but the latest one, as of 28/11

    That's the problem. I have deleted the account and hence am not able to access it anymore. I tried resetting and it says account does not exist. But when I try to create a new sync account it says account already exists. All I want is to be able to create a new sync account using the same email

  • Curve 8520 os: 5.0.0.681 randomly crashing and only shows white screen and unable to reboot unless plugged in

    Anyone else suffering from their curve 8520 os: 5.0.0.681 randomly crashing and only showing a white screen as well as it being unable to reboot unless it is plugged in? It often occurs when I'm playing media, using apps and maps. Had the same problem with my previous phone so it was sent in for repair and replaced but I'm still suffering from the same problem with the replacement handset! Any ideas how it fix this?
    Thanks

    Hello Me_Again
    Welcome to BlackBerry Support Community Forums
    Since you got a replacement it the same old Battery you are using or its a new Battery  with your replacement device.Sometime this white Screen or unable to reboot happen because of weak battery .I suggest if you can arrange a good quality Battery then try running your device a few hours to see if the problem is within the device or its just Battery issue.
    Prince
    Click " Like " if you want to Thank someone.
    If Problem Resolves mark the post(s) as " Solution ", so that other can make use of it.
    Click " Like " if you want to Thank someone.
    If Problem Resolves mark the post(s) as " Solution ", so that other can make use of it.

  • Incorrect web server is listed and unable to create EPMA Planning App

    I was trying to create a first EPMA Planning app but unable to continue as it lists incorrect web server.
    Little background on the environment: WinTel 2008 environment, 11.1.2 Suite.
    FS, Essbase, Workspace on box 1
    Planning on box 2
    HFM on box 3
    FDM on box 4
    RA, FR on box 5
    Oracle Enterprise on Box 6
    Originally planning was installed on box 5 and switched to box 2. Currently web server list box 5 instead of updated box (2).
    Are there any settings that I can modify to list proper server?
    Thanks in advance!

    Did you reconfigure "Configure Logical Address for Web Applications" and update the host to the new host?
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • Mail not responding and unable to  delete messages moved to trash

    *I have been unable to delete any messages from my trash. I get a message: an error occurred while moving messages to mailbox "trash on my mac". Then I get a spinning disc and have to wait so I can force quite mail. I can not use the help while in mail as nothing will respond. When I finally get the force quite to work and I long back on all the messages that I tried to move to trash and delete are still there.*
    *Any help anyone can share would be most helpful. This has been happening all day today whenever I log on to Mail.*
    *Thank you for your time.*
    Glenda

    Actually it will happen again, you can wait for it. It usually takes a few months and the entire cycle starts again. Apple knows perfectly well that mail is not working as it should for many years, especially in combination with Mobile Me synchronization. Don't be mistaken in the end nothing will help not vacuum your mailbox except removing your plist file and rebuilding it. With the Mobile Me that is not even able to alphabetically order your mail accounts it would be fun when you have numerous email accounts. Good luck. If I had the possibility to switch to another emailer I would have done so many years ago. However I am stuck with DMI from Marketcircle.

  • 37AV50U, flickering screen and crackling audio

    I have a 37-inch Toshiba tv, model number 37AV50U.  Recently, it has started flickering while on.  When it flickers, the entire screen goes black for one to five seconds, then returns to normal.  Whenever it flickers, the audio also crackles.  It does not grow either more or less frequent as the tv is on for long periods of time.  It does have periods of high frequency, when it will flicker many times each minute, and periods of low frequency, when it will flicker perhaps only once every 15 minutes or so.
    I am uncertain how to diagnose this, and so any advice would be quite helpful.

    Does it happen regardless of input? You should first make sure to isolate whether it's a problem with the source or a problem with the TV.
    Try resetting the video and audio settings to defaults from the settings. If that still doesn't help, it might require servicing.
    - Peter

  • Flickering screen and not enough time to write

    My macpro screen flickers about ebery 15 seconds, and sometimes the curser stops and I cannot continue writing wihout relocating it?

    Thanks. I will check on another computer see the results as indeed my computer is not brand new !
    Thanks for the warm welcome and hope I will be able to help as well although at the moment it is me who need more help!

  • Flickering Screen and Warranty

    Hello,
    I've had my macbook for about one year and half now , just long enough for my limited warranty to wear off. After about 8 month of macbook ecstasy and bashing windows , i realised my screen was beginning to flicker at numerous occasions ( restart , booting , awaking , etc. ) . So i sent my machine to a local apple store but only to learn that my warranty does not cover my screen that is blackening and flickering on random occasions , which basicaly means i can't send my macbook to repair something that is not damaged but is going to be some day. Thus being said , my macbook is now one year and half old and this problem of flickering is getting worse every month ... is there anything i can do or this is some kind of deceiving apple warranty service that makes you want to switch back to windows but eventually makes you buy an other macbook because you're addicted to this trendy machine ?

    Virgile...
    For clarification, you brought your machine into a local Apple Retail store or a 3rd party provider that is authorized to work on Apple products? They declined a repair on your machine as "No Trouble Found" or that identified an issue?
    From what you've described... it sounds like the inverter on your display could be failing. Which can easily be repaired (if that's what it is).
    I'd strongly encourage you to pursue contacting Apple directly to arrange an out-of-warranty repair on your machine, or visit a local Apple Retail Store / Genius Bar if that's convenient.
    As far as the apple warranty is concerned, your machine came with a one-year warranty with the option during the first 365 days of you owning the machine to purchase AppleCare and extend it for two more years (three years total from date of CPU purchase). So if the issue was identified during the in-warranty period you might have a leg to stand on, especially if it was documented somewhere.
    Again, though, that's up for Apple to decide as the machine is now out-of-warranty. Calling them, or visiting a Genius Bar would be the next best plan of action.

  • T520 flickering screen and shutdown

    Hi.
    I had this problem a couple of times before. On some random occasion the screen starts flickering and the laptop restarts/shutdowns after a couple of seconds. 
    The whole thing looks something like this:
    Could this be software related? I have installed the latest drivers from lenovo using system update. The laptop isn't under heavy usage (usually happens when browsing internet) or something.
    Should I consider taking it to the warranty service? How long will it take to fix the problem because I need my laptop ASAP.
    ThinkPad T520 i5-2410M(2.3GHz), 4GB RAM, 500GB 7200rpm HD, 15.6in 1600x900 LCD, NVIDIA NVS 4200M 1GB

    hey GiedriusZ
    hard to say if it is software related, try uninstalling the current graphic driver for your unit and let windows install its generic driver and try again.
    if it still occurs get in contact with the service team to service your unit. how long will it take ? hard for me to say, give them a call and they'll be able to give you a rough ETA.
    http://bit.ly/LNVsuppNum
    WW Social Media
    Important Note: If you need help, post your question in the forum, and include your system type, model number and OS. Do not post your serial number.
    Did someone help you today? Press the star on the left to thank them with a Kudo!
    If you find a post helpful and it answers your question, please mark it as an "Accepted Solution"!
    Follow @LenovoForums on Twitter!
    Have you checked out the Community Knowledgebase yet?!
    How to send a private message? --> Check out this article.

  • MacBook keeps rebooting, grey screen and unable to get a log in screen

    Have no idea what has happened! Looking through mail yesterday, nothing else. When I went to log in last night it started rebooting and then shut itself off. Every time I try to turn it back it on it has grey screen, apple icon and begins to reboot itself and then simply turns itself off again. Cannot even get to log in screen. Any advice on how to get my log in screen back and stop this process?

    Mac OS X: Gray screen appears during startup
    http://support.apple.com/kb/TS2570

  • Pdf printing gets a black screen, and unable to save

    When saving a pdf (saving as), I get a message "unable to save as ...", when printing, it print all black pages...
    The file is OK, as I am able to perform both operations from IE running in parallel...

    Hi..
    Open the Finder. From your Finder menu bar top of your screen click Go > Go to Folder
    Type this exactly as you see it here:   /Library/Internet Plug-Ins
    Click Go
    Move the Adobe PDF Browser plugin  (or just PDF Browser plugin) to the Trash.
    Quit then relaunch Safari to test.

  • Flickering screen and strange startup errors

    Hello sins about 2 weeks right after updating to 10.8.5 my screen start to flicker to black en even crashes
    als i when i start up i get this stage error in my screen. i reset pram en nvram. run diagnostic tests al seems fine.
    as an edior i need my comper so i am starting to sweat just got my mac for a year? anybody else whit this problems ?
    what can i do?

    Hello @tx1873,
    Welcome to the HP Forums, I hope you enjoy your experience! To help you get the most out of the HP Forums I would like to direct your attention to the HP Forums Guide First Time Here? Learn How to Post and More.
    I understand that you are having difficulty with your display on your HP Pavilion Slimline 400-034 Desktop PC. I am providing you with some steps you can try below:
    Step 1. Unplug the power cord from the back of the monitor and the wall
    Step 2. Hold the power button down for at least one minute
    Step 3. Plug the power cord back into the monitor and then into the wall outlet (not a power bar or surge protector)
    Step 4. Press the Menu button on the monitor
    Step 5. Navigate to the Factory Reset option and select it
    Step 6. Try different cables between your computer and monitor.
    If the above steps did not resolve your issue you can try the monitor on a computer or other device to see if the issue persists. Please call our technical support at 800-474-6836. If you live outside the US/Canada Region, please click the link below to get the support number for your region. http://www8.hp.com/us/en/contact-hp/ww-phone-assist.html
    Thank you for posting on the HP Forums. Have a great day!
    Please click the "Thumbs Up" on the bottom right of this post to say thank you if you appreciate the support I provide!
    Also be sure to mark my post as “Accept as Solution" if you feel my post solved your issue, it will help others who face the same challenge find the same solution.
    Dunidar
    I work on behalf of HP
    Find out a bit more about me by checking out my profile!
    "Customers don’t expect you to be perfect. They do expect you to fix things when they go wrong." ~ Donald Porter

Maybe you are looking for

  • I need to consolidate two iTunes libraries from different countries.

    I have been struggling for approximately 5 years now to resolve an issue which it seems is normal for those Apple users who move countries from time to time.  Specifically, I have ended up (inadvertantly in the first instance) with two distinct iTune

  • Optical Audio not working on 2006 Mac Pro 1,1 after 10.6.7 update

    Hi all, I have no digital audio output on my 2006 Mac Pro after I updated to 10.6.7. System Preferences recognizes the output but their is nothing coming out. The digital audio port goes from steady red at startup to dark, indicating that it is not r

  • AR invoice interface

    I want to know about the interface in the module Account Receivables(AR),as i have less knowledge of interface please explain in brief so that it will be helpfull for me.(badly in need). with regards sunil

  • Table parameter of RFC FM in background task

    hi I have a RFC FM in system A which has two table parameters, first table parameter table1 will have the data and the second table parameter table2 will be filled with in the FM with the error and success messages. Now i am calling this RFC FM in a

  • Use of J1I5- Regester update

    Hello CIN guru's Can anyone explain me the use of T code J1I5- Regester Update in CIN module, i concern is when i have already posted the GR and Excise invoice is it really required to again update the regester. when do we use J1I5. Suggestions worth