#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    19
    Rep Power
    0

    Java Picture Loading help


    Hello, I am having a problem with the picture loading part in java game dev (thenewboston). please help. The problem is it says change bg to Image and that's not what I want to do, but if I do nothing about it makes it all underlined in red.
    the starts in the code are just my account name name.
    I'm also using a mac. Thanks
    Code:
    import java.awt.*;
    import java.awt.Image;
    
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    public class Image extends JFrame {
    	public static void main(String[] args) {
    		DisplayMode dm = new DisplayMode(800,600,16, DisplayMode.REFRESH_RATE_UNKNOWN);
    		Image I = new Image();
    		I.run(dm);
    	}
    	
    	private Screen s;
    	private Image bg;
    	private Image pic;
    	private boolean loaded;
    	//run
    	public void run(DisplayMode dm){
    		setBackground(Color.PINK);
    		setForeground(Color.WHITE);
    		setFont(new Font("Arial", Font.PLAIN, 24));
    		loaded = false;
    		
    		s = new Screen();
    		try{
    		    s.setfullScreen(dm, this);
    		    loadpics();
    			try{
    				Thread.sleep(5000);
    			}catch(Exception ex){}
    		}finally{
    			s.restoreScreen();
    		}
    	}	
    	
    	private void loadpics() {
    		bg = new ImageIcon("/Users/*********/Documents/back.JPG").getImage();
    		bg = new ImageIcon("/Users/*********/Documents/back.JPG").getImage();
    		
    	}
    
    	public void paint(Graphics g){
    		g.drawString("This is going to be awesome", 200, 200);
    	}
    
    }
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    348
    If you are getting compiler error messages, copy the full text of the messages and paste it here.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    19
    Rep Power
    0
    Originally Posted by NormR
    If you are getting compiler error messages, copy the full text of the messages and paste it here.
    The error that I am getting is,
    Exception in thread "main" java.lang.Error: Unresolved compilation problems:
    Type mismatch: cannot convert from java.awt.Image to Image
    Type mismatch: cannot convert from java.awt.Image to Image

    at Image.loadpics(Image.java:35)
    at Image.run(Image.java:25)
    at Image.main(Image.java:8)
  6. #4
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    348
    Type mismatch: cannot convert from java.awt.Image to Image
    The compiler is complaining that it does not know how to convert an object of type java.awt.Image to an object of type Image (that's the name of your class)

    Rename your class so it has a different name than the java SE class.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    19
    Rep Power
    0
    Originally Posted by NormR
    The compiler is complaining that it does not know how to convert an object of type java.awt.Image to an object of type Image (that's the name of your class)

    Rename your class so it has a different name than the java SE class.
    Okay, Thanks
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0
    I am having problem with JVM.
  12. #7
  13. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    348
    @MaryDorr
    Please start a new thread and explain your problem. Be sure to copy the full text of the error messages and paste it here.

IMN logo majestic logo threadwatch logo seochat tools logo