Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Keylistener
Index -> Programming, Java -> Java Help
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
rizzix




PostPosted: Thu Jun 15, 2006 5:29 pm   Post subject: (No subject)

HellblazerX wrote:
I suggest you convert those images into something else, like gif or jpeg format, something that will much easier on your computer.
Or use a different approach. Try and load only parts of that image when necessary.
Sponsor
Sponsor
Sponsor
sponsor
ScarletSkyFury




PostPosted: Fri Jun 16, 2006 10:01 am   Post subject: (No subject)

Thank you, i changed all my PNG's to JPG and it help quite a bit(went from 400kb to 150kb a picture) but i am still getting:

Quote:

java.lang.OutOfMemoryError


i am now only using 5 pictures(range from 130kb to 180kb each) and two songs(.wav) but it just gives me the memory error.

Could one of you guys look at my code and see whats wrong or what i could change to make it more efficient.
any help would be greatly appreciated thank you



Basketball.java
 Description:
its called basketball but its not a basketball game lol..its an RPG

Download
 Filename:  Basketball.java
 Filesize:  7.74 KB
 Downloaded:  93 Time(s)

wtd




PostPosted: Fri Jun 16, 2006 10:18 am   Post subject: (No subject)

Pobably won't help, but your code presents numerous opportunies for improvement.

Your *Listener classes only ever get used once. Use anonymous inner classes here.

You have numerous lines like:

code:
bufferGraphics.drawImage(screen, 0, 0, 800, 600, this);


Where only the first argument ever differs. Try factoring this out into a method.

code:
                if (screen == background) {
                        bufferGraphics.drawImage(screen, 0, 0, 800, 600, this);
                        String startstring = "Mouse X:" + myMouseX + ", Mouse Y:" + myMouseY + ".";
                        bufferGraphics.setFont(new Font("TimesRoman", Font.PLAIN, 20));
                        bufferGraphics.drawString(startstring, 30, 30);
                }
                else if (screen == menu) {
                        bufferGraphics.drawImage(screen, 0, 0, 800, 600, this);
                        String startstring = "Mouse X:" + myMouseX + ", Mouse Y:" + myMouseY + ".";
                        bufferGraphics.setFont(new Font("TimesRoman", Font.PLAIN, 20));
                        bufferGraphics.drawString(startstring, 30, 30);
                }
                else if (screen == menu2) {
                        bufferGraphics.drawImage(screen, 0, 0, 800, 600, this);
                        String startstring = "Mouse X:" + myMouseX + ", Mouse Y:" + myMouseY + ".";
                        bufferGraphics.setFont(new Font("TimesRoman", Font.PLAIN, 20));
                        bufferGraphics.drawString(startstring, 30, 30);
                }
                else if (screen == menu3) {
                        bufferGraphics.drawImage(screen, 0, 0, 800, 600, this);
                        String startstring = "Mouse X:" + myMouseX + ", Mouse Y:" + myMouseY + ".";
                        bufferGraphics.setFont(new Font("TimesRoman", Font.PLAIN, 20));
                        bufferGraphics.drawString(startstring, 30, 30);
                }


Note how all of these do the same thing?

Well, just use logical ors to make that one condition.

Oh, and notice how I changed the formatting of the code? Follow the Sun Java guidelines. Friends don't let friends auto-format with RTP.
ScarletSkyFury




PostPosted: Fri Jun 16, 2006 12:50 pm   Post subject: (No subject)

Ugghhhhh this outofmemory problem is really getting on my nerves...not just because its an error but because there isnt really much i can do about it.

ok i got a question or two:

1)if i have implemented the mouselistener and the mousemotionlistener and im not really using it, would my program run faster(reduce the memory problem) if i just took it out?

2)i have already converted my previous PNG's to JPG's which did make them a lot smaller in memory, however apparently its still not enough, is there anything else i can do to make the pictures(change to another format?) so that they become even smaller?

3)is there anyhing else i can possibly do?....geez im only using 5 pics and the memory is already bugging me...shouldnt be...i would have guessed that if i were to make a BIG game like 30-40 pics...but c'mon...5????is that really normal?

4)if nay of you have made a game, how many pictures did you use and what much memory did they take up?what format?

5)Drawing the pictures numerous times takes up extra memory?if so, then is there a command similar to turing's "PicFree", and if yes then how would i use it in JAVA?

Thank you
ScarletSkyFury




PostPosted: Fri Jun 16, 2006 2:22 pm   Post subject: (No subject)

If i can get the above questions answered that would be great but i was wondering if this is my case:

Quote:

For most basic classroom uses, Ready is okay. Remember, just because you're using RTP does NOT mean you'll neccesarily have to use the HSA Console classes or any of that crap. I would definitely stay away from using that, but there's nothing wrong with using Ready at first -- it is nothing more than a syntax-highlighting text editor with compile+run bound to its F1 key. Yes, it does use a different compiler, but by the time students get to the point where that makes any difference, it will be trivial to switch them over to Sun JDK.


Maybe i wouldnt be going trought all this if i wasnt using RTP?
wtd




PostPosted: Fri Jun 16, 2006 2:55 pm   Post subject: (No subject)

ScarletSkyFury wrote:
Maybe i wouldnt be going trought all this if i wasnt using RTP?


Maybe. Maybe not. I can't right now say definitively one way or the other. I do know that there are other reasons to be using the standard JDK.

For one, the knowledge you gain will be more readily applicable outside of Ontario high schools, both in terms of libraries and tools.
ScarletSkyFury




PostPosted: Fri Jun 16, 2006 3:07 pm   Post subject: (No subject)

So am i screwed?
wtd




PostPosted: Fri Jun 16, 2006 3:30 pm   Post subject: (No subject)

Ummm... why would you think that?

Just grab yourself the JDK from Sun's site. RTP only covers Java 1.4.2, so make sure you ge the 1.4.2 JDK. Then grab a good text editor (I suggest Textpad when it comes to Winders) and get comfy with the command-line.
Sponsor
Sponsor
Sponsor
sponsor
ScarletSkyFury




PostPosted: Fri Jun 16, 2006 3:37 pm   Post subject: (No subject)

Ouch check this out:

http://i72.photobucket.com/albums/i163/ScarletSkyFury/proof.jpg
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 24 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: