Why won;t the images render on the screen?

Nothing changes from the default white screen. Any help? And one of the images is a large background, and the other is a small "person"
package game;
public class Main {
     public static void main(String[] args) {
          new Thread(new GameEngine()).start();
package game;
import java.io.*;
import javax.swing.*;
import java.awt.*;
public class GameEngine implements Runnable {
     public GameEngine() {
          GameEngine.engine = this;
     public void run() {
     private final Sprite[] loadSpriteCache() {
          try {
               Sprite[] spriteCache = new Sprite[10];
               spriteCache[0] = new Sprite(Util.getBytes("background.png"));
               spriteCache[1] = new Sprite(Util.getBytes("person.png"));
               return spriteCache;
          } catch(IOException e) {
               e.printStackTrace();
               return null;
     private final UserInterface createUserInterface() {
          return new UserInterface();
     public void paint(Graphics g) {
          for(Sprite s : spriteCache) {
               if(s != null) {
                    s.drawSprite(g, 0, 0);
                    Util.println("Rendered");
     public static GameEngine getEngine() {
          return engine;
     private static GameEngine engine;
     private Sprite[] spriteCache = loadSpriteCache();;
     private final UserInterface ui = createUserInterface();
package game;
import javax.swing.*;
import java.awt.*;
public class UserInterface extends Canvas {
     public UserInterface() {
     @Override
     public void paint(Graphics g) {
          super.paint(g);
          GameEngine.getEngine().paint(g);
     @SuppressWarnings("deprecation")
     public final JFrame createFrame() {
          JFrame frame = new JFrame();
          frame.setTitle("Simple Graphics Application");
          frame.setResizable(false);
          frame.setPreferredSize(new Dimension(700, 500));
          frame.add((Canvas)this);
          frame.pack();
          frame.show();
          return frame;
     private final JFrame frame = createFrame();
package game;
import java.io.*;
import javax.swing.*;
import java.awt.*;
public class Sprite {
     public Sprite(byte[] rawSprite) {
          this.rawSprite = rawSprite;
     public void drawSprite(Graphics g, int X, int Y) {
          g.drawImage(sprite, X, Y, null);
     private byte[] rawSprite;
     private Image sprite;
package game;
import java.io.*;
public class Util {
     public static void println(String args) {
          System.out.println(args);
     public static byte[] getBytes(String name) throws IOException {
          try {
               File file = new File(cachePath + name);
               byte[] data = new byte[(int)file.length()];
               new FileInputStream(file).read(data);
               return data;
          } catch(FileNotFoundException e) {
               println("Could not load: " + name);
               e.printStackTrace();
               return null;
     public static final String cachePath = "./data/";
}

This code is starting a thread with an empty run method :
package game;
public class Main {
     public static void main(String[] args) {
          new Thread(new GameEngine()).start();
}-> GameEngine.java
public void run() {
}The singleton pattern used in GameEngine needs reworking (The constructor is not private), and getEngine() returns engine without checking if it exists.
You should also not be overriding the paint methods, especially for a game as it can be called at random.
The draw method in Sprite is drawing an Image but the Sprite constructor takes a byte [] and does not actually initialize the Image variable with the byte [].
I also have absolutely no idea what the Util class is for ...
Would loading your images as ImageIcons or BufferedImages not be easier?
Edited by: Swordwrathe on Sep 2, 2009 2:58 AM

Similar Messages

  • Why won't large images open in full screen on first click?

    I go to open an image (jpg, png) that has a byte size of 2000 x 3096. What ends up happening, is that it will initially open a full screen window, and after a second or so, that full screen window will shrink to a half screen window. Now I'm required to click the max window size button in the upper right corner to expand the window to full size, right click on the image, select View Image from the drop down menu, and then finally click in the image to get it to display in its full size.
    Is there a plug-in, or a config. parameter that I can use, so that the image opens up in full screen mode from the start?

    Is this with opening an image link from a web page or with viewing images that you already have stored on the computer?
    You can check for problems caused by a corrupted localstore.rdf file.
    *http://kb.mozillazine.org/Corrupt_localstore.rdf
    See also:
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes
    You can try to rename or delete the prefs.js file and possible numbered prefs-##.js and user.js files to reset all prefs to the default value.
    *http://kb.mozillazine.org/Preferences_not_saved
    *http://kb.mozillazine.org/Resetting_preferences

  • Why won't my images appear on the page?

    I tried to upload new pictures but all that shows up is the alternate wording. I don't know what's gone wrong. I've been using Dreamweaver CS5 for over 2 years and this problem is new.
    This is the url: http://mountainartistsguild.org/masters_working.html
    Here's the error message:
    Started: 3/28/13 1:18 PM
    masters_working.html - Put operation successful
    main.css - same - not transferred
    images:1900x1900_blues_bigstock-Abstract-watercolor-hand-paint-33863234.jpg - same - not transferred
    images:revised_1045_header-100%gradient.png - same - not transferred
    SpryAssets:SpryMenuBar.js - same - not transferred
    SpryAssets:SpryMenuBarVertical.css - same - not transferred
    SpryAssets:SpryMenuBarRight.gif - same - not transferred
    SpryAssets:SpryMenuBarRightHover.gif - same - not transferred
    /public_html/mountainartistsguild/images/masters / - error occurred - Unable to create server folder /public_html/mountainartistsguild/images/masters /.  Access denied.  The file may not exist, or there could be a permission problem.   Make sure you have proper authorization on the server and the server is properly configured.
    images:masters :Silent Flow.jpg - user cancelled
    File activity incomplete. 1 file(s) or folder(s) were not completed.
    Files updated: 1
    Files skipped: 7
    Files with errors: 1
    /public_html/mountainartistsguild/images/masters /
    Finished: 3/28/13 1:18 PM

    I'd contact my hosting company with that information if it happened to me.
    Looks like you don't have the ability to overwrite files with your current credentials.

  • Why won't Acrobat X Pro honor the margin (art box) from PDF's exported from InDesign CS6?

    Why won't Acrobat X Pro honor the margin (art box) from PDF's exported from InDesign CS6?
    When I export a PDF from InDesign CS6 with specific margins, Acrobat does not recognize the Art box. (I have PitStop Pro 11 for page box view)

    Thanks Steve,
    We are exporting PDF's as you indicate. I see the same thing. The boxes are all the size of the original InDesign document. The PDF art box should be predicated by the margins in InDesign. When we had CS3, this worked great. Now, it seems that there is a disconnect between the two Adobe products honoring the page box size. I have contacted the Adobe techs via chat, and they had no clue what I was referring to. I find it mystifying that Acrobat can not interpret the art box set in InDesign as margins.

  • Why won't my Apple TV display the setup screen?

    Why won't my Apple TV display the setup screen? I have changed hdmi cable, confirmed the correct input, checked connection but nothing. HELP!!! I have a Bose System and use a universal remote, Logitech. Could this be a factor?

    Welcome to the Apple Community.
    What exactly does your Apple TV display.

  • HT1338 Why won't my computer pick up the wireless in my home? All other computers in my home can get internet

    Why won't my computer pick up the wireless in my home? All other computers in my home can get the internet.

    Turn Off your computer. Then turn Off (disconnect power cord for 30 seconds or longer) the wireless router & then back On. Now boot your computer. Hopefully it will see the WiFi.
     Cheers, Tom

  • Why won't my iPhone connect to the Internet? It will goes days with no connection, then suddenly have a connection for a while. I am on the Sprint network.

    Why won't my iPhone connect to the Internet? It will goes days with no connection, then suddenly have a connection for a while. I am on the Sprint network.

    Have you contacted Sprint?  See if they can resolve your issue, if you can't get 3G.

  • Why won't iPhone 4 charge in the car

    Why won't iPhone 4 charge in the car anymore?  I have changed out the cords several times. It's a Belkin...bought at the apple store...not a cheapo!

    Car chargers tend to break down frequently
    buy a new one
    Strongly recommend buying on eBay a few units at a discounted price

  • Why don't you make the image classification except the computer?

          Why don't you make the image classification except the computer?

    Please try posting in your native language. This question make no sense.

  • Why won't my background rotate when The IPAD turns anymore

    Why won't my background rotate when The IPAD turns anymore?

    You posted this in the iPhone forum. Check in Control Center (swipe up from the home screen) and see if the rotation lock is turned on there (an icon of a lock with a circled arrow).

  • Why won't my podcasts download in the app over a Wifi connection?

    Why won't my podcasts download in the app over a Wifi connection using the Apple app on my iPhone 5?
    It works over 3G and 4G connection but every time I try to download a podcast through wifi I continually receive the message 'Download Error'.

    Hi jasonpbell,
    Thanks for visiting Apple Support Communities.
    Some of the steps in this article may help with the Wi-Fi download issue that you're seeing:
    iOS: Troubleshooting Wi-Fi networks and connections
    http://support.apple.com/kb/ts1398
    Regards,
    Jeremy

  • Why won't my iPhoto open in the latest operating system

    why won't my iPhoto open in the latest operating system

    Whcih version of iPhoto do you have? You may want to look at the Mac App Store and see if you have an update for iPhoto.
    Clinton

  • Why does the click-hold to reveal the image area outside the frame work on only some images?

    I just upgraded to ID CC 2014 and the click-hold function to reveal the image area outside the frame only works for some images. Any suggestions?
    Jim

    Thanks, Peter. That could be the problem--operator error. But, I did a restart and all seems fine. If I get another image with a display issue, I'll be back

  • Wondering about the "image" tag in the Tech Specs example

    I'll begin by admitting that what I don't know about coding would fill a bunch of bookshelves, but I've noticed that some people (including myself) have been having problems with their image files lately. I've also noticed that the coding for the image tag in the sample on the Technical Specifications page (http://www.apple.com/itunes/podcasts/techspecs.html) isn't formed like all the rest.
    It’s
    <itunes:image href="http://example.com/podcasts/everything/AllAboutEverything.jpg" />
    Shouldn’t it be
    <itunes:image> href="http://example.com/podcasts/everything/AllAboutEverything.jpg" </itunes:image>
    HP Pavilion zd8000   Windows XP  
    HP Pavilion zd8000   Windows XP  

    Hi DiscipleC--
    Andy is 100% correct (he makes some of the best podcast software around, so you're getting the advice of the pros here).
    What will happen now that your feed doesn't validate is that the image will likely stay there. But that's not because it's correct--it's because iTunes will see a broken feed when it checks, and it won't make any changes at all. So if you add episodes, those won't appear because the feed won't be updated until it works again.
    Follow the image art example exactly as listed in the example feed in the technical spec, make sure it validates over at feedvalidator.org, and you'll be fine.
    Good luck!
    -S
    PowerMac G5, 15" Powerbook, 12" Powerbook   Mac OS X (10.4.5)  

  • Photoshop CC: Have a template that I moved image into.  Image is too small.  How do I resize the image while in the template?  Or must I go to original image file and resize there again and again until I get the right fit?

    I have a template that I am able to plug different pictures into at different times.  The problem is that when I plug an image into that template, I find that the image is either too big or too small.  Is there a way to plug the image into the template and resize the image (and not the template itself) OR will I have to go to the file with the original image and resize it there and then try to plug it in to the template to see if it fits------and if it does not fit, go back to the original file with the image and resize it again and see if that fits---and so on and so on...........?  I have tried the" image size" option but it's hit or miss------mostly miss!
    Thanks!

    Read up on Smart Objects. It looks like you have no idea as to how to create and use them.
    Jut create a Smart Object from the layer containing whatever it image it is that you are "plugging into your template".  But you do need to learn the application at its most basic levels.
    Photoshop is a professional level application that makes no apologies for its very long and steep learning curve.  You cannot learn Photoshop in a forum, one question at a time.
    Or is it possible that you don't even have Photoshop proper but the stripped-down Photoshop Elements?"
    If the latter is the case, you're in the wrong forum.  This is not the Elements forum.
    Here's the link to the forum you would want if you're working in Elements.:
    https://forums.adobe.com/community/photoshop_elements/content
    If you do have Photoshop proper, please provide the exact version number of that application and of your OS.
    (edited for clarification)

Maybe you are looking for

  • I currently have OS X version 10.5.8 what is my next upgrade?

    I currently have Mac OS X version 10.5.8 - intel processor what should my next upgrade be?  I need to upgrade in order to accommodate my new ipod nano.

  • Sap daily backup error

    hello experts,                            in that sap the daily backup of sap production server due to error during initialization for the error.one hour before take os level nt backup.then next take the sap daily base back up. profile :initmpc.sap r

  • Why is my macbook air downloading so slowly?

    I have the most recent OS 10.9.4.  My Air is mid 2013 13".  I am running google chrome and the downloads are extremely slow.  They don't show up on my desktop quickly either.  Safari is running a little faster, but not as fast as I think it used to. 

  • I can't see my table in my app with oracle 9i

    Hi: I have an app with Java and O9i where i have to delete some data in table, but when i execute my metod appears a "ORA-00903: invalid table name" error code, but when i check the schema in DbVisualizer i see it that table in fact i can delete data

  • Transfering an e-mail address to Mobile Me account.  Do I need to?

    Hi everyone, I'm not sure if this post should go here or perhaps in the Mobile Me area. It involves both iWeb and Mobile Me. === For about the last 10 years I've had my own domain name [www.morrisacevedo.com] It's been hosted by various companies. Th