Having some problems with ImageIcons and JLabels

I'm making a checkers game, and so far it's going pretty well.
I've got the basic game down, and you can move pieces, jump, your turn ends when you can't jump anymore, etc...
However, I've had three problems:
1.) I'm using JLabels to display my board (8 x 8.. well actually 9 x 9 for an outer row labelled A,B,C,D.. 1,2,3,4...) Anyway, I create the JLabels using something that looks like \:
JLabel square = new JLabel(new ImageIcon("pic.png"));
Now, the picture loads properly, but it seems like the picture is being cropped, and the top and bottom are getting chopped off, so my 36 x 36 pixel *.gif appears to be 36 x 30.
You can see how there is a gap created in:
http://img235.imageshack.us/img235/7765/prob13ky.jpg
Now the problem may be with the GridLayout I am using, but I set the distance between the components in the container to be 0, 0 so I don't think that GridLayout is chopping my icons. I've also tried setPreferredSize(new Dimension(36,36))
for both my ImageIcons and JLabels and for my container (which I set to size 2000,2000, just to make sure there was room). If anyone can help me, it's be appreciated.
2.) I used to be able to view my outside row/column of squares that said A,B,C,D.... and 1,2,3,4... with the square in the corner having a random pic. For some reason now (have no clue why) I now see only the pic in the corner, and then a little gray smudge diagonally under it.
Pic:
http://img347.imageshack.us/img347/8308/prob24im.jpg
I don't know what's wrong. I'm pretty sure it's none of the new methods I've written, as those are all in my static void main (String[] ar) ...... and if I comment all the methods in my main except where I first make the JFrame and set it visible, it still turns out like that. repaint() doesn't help.
3.) For some reason, when I move another window (AIM, the console window, etc...) over my Swing window, it "erases" (turns gray, just wipes clean) the part where I have my squares that have pieces.
What's weird is that:
The border pieces (err.. my one visible corner piece from my second problem) don't get wiped, and some debugging text and JLabels (in a different JPanel) are fine. I don't think the JPanel matters though; the border pieces and the playing squares (which get wiped) are in the same JPanel and same array of squares.
repaint(); also erases ALL of my playing squares, whereas moving a window over them would only erase the part that the window covered.
Also, I added a mouseListener so that whenever I move the mouse over a square, it changes the image (to a tinted version, so you know the mouse is over it) and when you move the mouse away, it returns to normal. However, if I wildly swing the mouse around the area, it seems to lock up and freeze for a few seconds. Is there anything I can do to prevent this??
Thanks in advance.

It is hard to tell what your problems are without any code at all (I saw your images, but that doesn't make it easy to see what is wrong in your code). If you do post code, please use code tags (see button above posting box).
I've seen your MouseListener problem before--we had the exact same issue in our code at work. It would freeze up while it processed all of the mouse events (unbearably slow). I'm not at work right now, so I don't recall how it was fixed. Essentially, you need to only process the event periodically. You need to only update the image if the mouse switches squares. Or, only update the image if the distance from the last mouse event is more than some specified amount. We might also have checked the time difference between mouse events before processing a new one. I could look at the code at work tomorrow, if you are still having trouble.

Similar Messages

  • Having some problems with Xcode and C++

    hi guys , I am learning C++ and I am having the following problem when trying to use .h files.
    Example. I make a new document using Xcode2.3.
    in the source folder I got my main.cpp and i 2nd click it, choose add/file/BSD/header file.
    main.cpp
    #include "funtest.h"
    int main ()
    print_num ( 9 );
    return 0;
    funtest.h
    void print_num (int iNum);
    When I compile with Cmd+R , I get:
    [Session started at 2006-06-26 01:59:31 -0400.]
    ZeroLink: unknown symbol '_Z9printnumi'
    complex2 has exited due to signal 6 (SIGABRT).

    Thanks a lot! I don't recommend you to code too early in the morning :P
    The program now looks like this:
    funciones.cpp
    #include "funciones.h"
    #include <iostream>
    int main ()
    print_num ( 9 );
    return 0;
    funciones.h
    /*funciones utilizadas en el programa*/
    #include <iostream.h>
    void print_num (int iNum)
    std::cout << iNum << endl;
    now it builds and prints a fine "9" as output.
    The only thing that is killing me , is in funciones.h, if I don't use #include <iostream.h> the app doesn't run. And if I include it , it runs but Xcode gives me a warning of old headers.
    thanks again.

  • I just upgraded my iMac to Lion, and a few seconds ago, I upgraded the iWork package and now I'm having some problems with the new version of Pages (4.1) When I try to change something in a document, a message says "the program is not responding"

    I just upgraded my iMac to Lion, and a few seconds ago, I upgraded the iWork package and now I'm having some problems with the new version of Pages (4.1) When I try to change something in a document, a message says "the program is not responding", so I have to force it to close. By the way, the SAVE botton stays the same even I change erverything in my document. Please, a have a work to finish, **** me. What I can do abou it?

    I just upgraded my iMac to Lion, and a few seconds ago, I upgraded the iWork package and now I'm having some problems with the new version of Pages (4.1) When I try to change something in a document, a message says "the program is not responding", so I have to force it to close. By the way, the SAVE botton stays the same even I change erverything in my document. Please, a have a work to finish, **** me. What I can do abou it?

  • My ipod touch will not switch on and is no longer recognised by itunes.  Before this i tried to restore it as I was having some problems with it switching off and on by itself randomly.

    My ipod touch will not switch on and is no longer recognized by itunes.  Before this i tried to restore it as I was having some problems with it switching off and on by itself randomly.
    I tried to restore it and I got error code 2009, so I closed it tried again got error code 1659, now it wont do anything and it's not recognized by my pc /itunes please help x

    For the restore error messages try:
    iTunes: Specific update-and-restore error messages and advanced troubleshooting

  • Hello, well im having some problems with my ipod 4th gen it will not turn on and when i plug it in to itunes it will not come up saying i need to restore. when i try that it will not compleet. the ipod will not do anything at all... please help me

    Hello, well im having some problems with my ipod 4th gen it will not turn on and when i plug it in to itunes it will not come up saying i need to restore. when i try that it will not complet. the ipod will not do anything at all... please help me i havent got  extra money to spend..

    Just what happens when the restore does not complete?
    Error message?
    Does it freeze? Is so what is listed in the status bar of iTunes?

  • HT4060 I'm having some problems with my ipad and charging it. I am having to leave it in charge for a lot longer, but when I take it out and want to use it the battery is still not completely full and goes down a lot faster than usual

    I'm having some problems with my ipad and charging it. I am having to leave it in charge for a lot longer, but when I take it out and want to use it the battery is still not completely full and goes down a lot faster than usual. The other day, I had charged  my iPad overnight so that I could take it to university with me for the day, and when I had switched it on the next day the battery was on 5% and I had not used it since charge.

    Your battery may be dying. THey are only good for so many charges/discharges. If you have an apple store near by make an appointment and have them check itout

  • Having some problems with my c6-01

    Hello there, I have recently bought a nokia c6-01 but I am having some problems with it. Such as, sometimes it freeze and it restart itself then it continues as nothing happened(dont ask me my pin code) my other problem is when I assign ringtone to my contacts it does not bell the tone normally , it plays the music in weird tone (btw my phone play that ringtone normally in music player ) what can I do against these problems ? Is this a software or hardware problem? Should I take it to the provider? Thanks.

    random reboots are quite common
    try updating the software before you do anything else.
    If  i have helped at all a click on the white star below would be nice thanks.
    Now using the Lumia 1520

  • Having some problems with apps froms the app store

    Hello. Since I got my iTouch I've been having some problems with some apps. Some work perfectly fine, but some others are just crashing after a few seconds. I've tried everything I found, but it seems like my problem is different from the one related by lots of others iPod users. Here's a video a friend of mine who's having the same problems I am did showing it:
    http://www.youtube.com/watch?v=MI-gBhP_cgU
    It's really annoying us. Does anyone know how to fix it? Does it look like a firmware problem? Thanks in advance.

    Have youy tried:
    - Reset:
    Reset iPod touch:  Press and hold the On/Off Sleep/Wake button and the Home
    button at the same time for at least ten seconds, until the Apple logo appears.
    - iOS: Troubleshooting applications purchased from the App Store
    - Restoring the iPod from backup
    - Restoring the iPod to factory defaults/new iPod.

  • HT201177 I am having some problems with downloading, possibly settings are incorrect, esp. flashplayer upgrade will not install - i have iMac 8.1 osx v10.5.8 - processor: 3.06 ghz intel core2 duo mem: 2 gb 800 mhz ddr2 sdram

    I am having some problems with downloading, possibly settings are incorrect, esp. flashplayer upgrade will not install - i have iMac 8.1 osx v10.5.8 - processor: 3.06 ghz intel core2 duo mem: 2 gb 800 mhz ddr2 sdram - i am considering making an appt with Apple store nearby since we have a few in vicinity but thought i would give the online support a try.

    The latest version of Adobe FlashPlayer can be obtained from here:
    http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFl ash
    You can check here what version of Flash player you actually have installed:  http://kb2.adobe.com/cps/155/tn_15507.html
    You can check here:  http://www.adobe.com/products/flash/about/  to see which version you should install for your Mac and OS.
    You should first uninstall any previous version of Flash Player, using the uninstaller from here (make sure you use the correct one!):
    http://kb2.adobe.com/cps/909/cpsid_90906.html
    and also that you follow the instructions closely, such as closing ALL applications first before installing. You must also carry out a permission repair after installing anything from Adobe.

  • TS5376 I'm having a problem with downloading and installing the new version of itunes for windows (11.1.4)  I have done everything the troubleshooting article has said and it is still not working properly.

    'm having a problem with downloading and installing the new version of itunes for windows (11.1.4)  I have done everything the troubleshooting article has said and it is still not working properly.  I have even done a repair to see if that works and it has not.  Has anyone else found a new way to get it working?

    Try Troubleshooting issues with iTunes for Windows updates.
    tt2

  • I'm having a problem with coreaudiotoolbox and corevideo.dll.

    I'm having a problem with coreaudiotoolbox and corevideo.dll. PC was corrupted, I restored. Now when I launch Safari, I run into errors, can't find these two dll files. Itunes won't download at all because it says something is missing but won't say what. Now what do I do? Apple won't help because they want $50 dollars just to talk with me and I've been down that road before and to no satisfaction. Help please!!

    Taken at face value, you're having trouble with Apple Application Support program files there. (Apple Application Support is where single copies of program files used by multiple different Apple programs are kept, so an AAS problem can affect both iTunes and Safari.)
    Let's try something relatively simple first. Restart the PC. Now head into your Add or Remove programs control panel, select "Apple Application Support", click "Change" and then click Repair.
    If no joy after that, try the more rigorous uninstall/reinstall procedure from the following post (although it's for Vista and 7, just read "Computer" as "My Computer", read "Uninstall a program control panel" as "Add or Remove programs control panel" and assume the system is 32-bit, and you'll be doing the right things):
    Re: I recently updated to vista service pack 2 and I updated to itunes 10.2.1 and ever since I did that my itunes won't open any more.  Itunes starts but before anything loads a window pops up saying that the prograam has encountered a problem and sh...

  • I am not able to download ITunes. I had some problems with ITunes and had to uninstall but now when I reinstall iTunes after I click on download iTunes and save the File, I get this message"Thank you for downloading iTunes" and nothing else happens. I don

    I had some problems with ITunes and had to uninstall but now when I reinstall iTunes after I click on download iTunes and save the File, I get this message"Thank you for downloading iTunes" and nothing else happens. I don't see any thing else. Now not sure what else I have to do.
    Thanks,
    Ranjit

    See the further information area of Troubleshooting issues with iTunes for Windows updates.
    tt2

  • Hi! Everyone, I have some problems with JOIN and Sub-query; Could you help me, Please?

    Dear Sir/Madam
    I'm a student who is interested in Oracle Database and
    I have some problems with JOIN and Sub-query.
    I hope so many of you could help me.
    if i use JOIN without sub-query, may it be faster or not?
    SELECT field1, field2 FROM tableA INNER JOIN tableB
    if i use JOIN with sub-query, may it be faster or not?
    SELECT field1,field2,field3 FROM tableA INNER JOIN (SELECT field1,field2 FROM tableB)
    Thanks in advance!

    Hi,
    fac30d8e-74d3-42aa-b643-e30a3780e00f wrote:
    Dear Sir/Madam
    I'm a student who is interested in Oracle Database and
    I have some problems with JOIN and Sub-query.
    I hope so many of you could help me.
    if i use JOIN without sub-query, may it be faster or not?
    SELECT field1, field2 FROM tableA INNER JOIN tableB
    if i use JOIN with sub-query, may it be faster or not?
    SELECT field1,field2,field3 FROM tableA INNER JOIN (SELECT field1,field2 FROM tableB)
    Thanks in advance!
    As the others have said, the execution plan will give you a better idea about which is faster.
    If you're trying to see how using (or not using) a sub-query affects performance, make the rest of the queries as similar as possible.  For example, include field3 in both queries, or ignore field3 in both queries.
    In this particular case, I guess the optimizer would do the same thing either way, but that's just a guess.  I can't see your execution plans.
    In general, simpler code is faster, and better in other ways, too.  In this case
    tableB
    is simpler than
    (SELECT field1, field2  FROM tableB)
    Why do you want a sub-query in this example?

  • Having some problems with JAVA sites with safari, opera and firefox

    I work with some online java application for my work. Since I updated to Leopard, I cant access the site with safari, I loose some options with Opera and Firefox...
    Is it the JAVA that is not up to date with leopard?
    Any updates soon?
    Help!!!

    I have experienced memory leaks with the jvm on Leopard. Seem they took a huge step backwards instead of forward.
    It should be obvious by now that they didn't include 1.6 as many publications alluded to (Still haven't seen any explicit word from Apple where they officially said "Yes, Leopard WILL have JVM 1.6 at time of launch".)
    Don't know if the url below will get filtered out, but many other (non-Apple controlled) forums have been saying nasty things about Apple not explaining themselves for this major snafu.
    The article is titled, "So Long Apple. The Party's Over" and hosted by Java Lobby dot org.
    http://www.javalobby.org/java/forums/t102936.html

  • Having a problem with "open" and "import" buttons!

    Hello all,
    I am having some trouble with a basic function in Logic. When I go to "file" and select "import," the window of options appears. However, when I select a file and click the "import" button, literally nothing happens. I have had a similar problem, when I go to the "file" menu and select "open." A window will appear for me to browse to the logic file I want to open, but when I click "open," nothing happens. However, if I manually go to the file and double-click it, then the file will open. The drop-down is set to "All logic document types," though I have tried "all Logic songs" with the same problem. Please help!
    Best,
    Jon

    you know whats funny, this project has to do with arrays of objects and not inheritance. We learned inheritance last week but the lab we are doing which is this, is for arrays of objects. sorry for the confusion lol. so you can completely ignore this, it actually has it in big bold letters at the top of the web page for the lab.

Maybe you are looking for

  • My app wont open

    When I click on the app it wont open!! help?? On windows itunes store...??? HELPPPPP!!!!!!!????????

  • Why is there no scaling for high resolution monitors in Adobe Bridge CC?

    Why is there no scaling for high resolution monitors in Adobe Bridge CC? Photoshop CC, Illustrator CC and Indesign CC have 200% scaling for high resolution monitors in their preferences panel but Bridge CC does not, when will this feature be added to

  • 47'' LG LCD TV

    We just bought a 47'' LG LCD TV and have noticed that sometimes there will be almost a blur around a person moving fast across the screen.  Does anyone know if this is a tv issue or a cable company issue? Thanks

  • Problem setting up JMS (AQ); cannot see JMSDEMO_TOPIC in Consume Message Op

    I am following ESB "Lesson07: OEMS: JMS (AQ) to DB PL/SQL" Setup OEMS in application.xml; and Jms Adapter in oc4j-ra.xml; I setup JMSDEMO_TOPIC in the DB under JMSUSER; started AQ; When I setup JMS Adapter "Step 5 of 6: Consume Operation Parameters":

  • Links will no longer open with "ctrl + click".

    I think the title explains it all. I can no longer open links in a new tab by "ctrl + left clicking" them. As someone who has a lot of tabs up a lot of the time, this is horribly inconvenient.