Results 1 to 10 of 10
  1. #1
    Astralogic is offline Member
    Join Date
    Mar 2012
    Posts
    71
    Rep Power
    0

    Default Why are these words underlined in red in Eclipse?

    Code tags destroy the color codes, so i'll have to paste it like this. I found the resizeImage() method online and just copied and pasted it, that's the only place where the errors occur.

    Java Code:
    import java.awt.Component;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.MediaTracker;
    import java.awt.Toolkit;
    import java.net.URL;
    
    public class ImageLoader extends Component {
    
    	public Image loadImageFromFile(String filename) {
    		Image image = null;
    		Toolkit tk = Toolkit.getDefaultToolkit();
    		image = tk.getImage(filename);
    		waitForImage(image);
                    image = resizeImage(image, 200, 200);
    		return(image);
    	}
    
    	private void waitForImage(Image image) {
    		MediaTracker mt = new MediaTracker(this);
    		mt.addImage(image, 1);
    		try {
    			mt.waitForAll();
    		} catch(Exception e) {
    			e.printStackTrace();
    			System.exit(0);
    		}
    	}
    	
    	public Image loadImageFromInternet(String urlString) {
    		Image image = null;
    		URL url = null;
    		try {
    			url = new URL(urlString);
    		} catch(Exception e) {
    			e.printStackTrace();
    			System.exit(0);
    		}
    		Toolkit tk = Toolkit.getDefaultToolkit();
    		image = tk.getImage(url);
    		waitForImage(image);
                    image = resizeImage(image, 200, 200);
    		return(image);
    	}
    	
    	public static Image resizeImage(Image src, int screenWidth, int screenHeight) {
    		int srcWidth = src.getWidth(); *******************************************************
                    int srcHeight = src.getHeight(); ********************************************************
    		Image tmp = Image.createImage(screenWidth, srcHeight); ***********************************************
    		Graphics g = tmp.getGraphics();
    		int ratio = (srcWidth << 16) / screenWidth;
    		int pos = ratio / 2;
    		 
    	    // Horizontal Resize
    	    for (int x = 0; x < screenWidth; x++)
    	    {
    	        g.setClip(x, 0, 1, srcHeight);
    	        g.drawImage(src, x - (pos >> 16), 0, Graphics.LEFT | Graphics.TOP);**************************************
    	        pos += ratio;
    	    }
    		 
    	    Image resizedImage = Image.createImage(screenWidth, screenHeight);*************************************
    	    g = resizedImage.getGraphics();
    	    ratio = (srcHeight << 16) / screenHeight;
    	    pos = ratio / 2;
    	 
    	    //Vertical resize
    	    for (int y = 0; y < screenHeight; y++) {
    	        g.setClip(0, y, screenWidth, 1);
    		        g.drawImage(tmp, 0, y - (pos >> 16), Graphics.LEFT | Graphics.TOP);********************************************
    		        pos += ratio;
    		    }
    	 
    		    return resizedImage;
    		}
    }
    These errors make no sense to me, not all of them refer to the above function though, and that's the only problem.

    Description Resource Path Location Type
    The serializable class DrawSquares does not declare a static final serialVersionUID field of type long DrawSquares.java /DrawSquares/src line 7 Java Problem
    The method show() from the type Window is deprecated DrawSquares.java /DrawSquares/src line 18 Java Problem
    The serializable class FSquares does not declare a static final serialVersionUID field of type long FillSquares.java /FillSquares/src line 28 Java Problem
    The method show() from the type Window is deprecated FillSquares.java /FillSquares/src line 19 Java Problem
    The serializable class DisplayCanvas does not declare a static final serialVersionUID field of type long DisplayCanvas.java /ImageLoader/src line 6 Java Problem
    The serializable class FillSquares does not declare a static final serialVersionUID field of type long FillSquares.java /FillSquares/src line 8 Java Problem
    The method show() from the type Window is deprecated QWin.java /QWin/src line 19 Java Problem
    The serializable class Squares does not declare a static final serialVersionUID field of type long DrawSquares.java /DrawSquares/src line 28 Java Problem
    The serializable class QWin does not declare a static final serialVersionUID field of type long QWin.java /QWin/src line 4 Java Problem
    The value of the local variable qw is not used QWin.java /QWin/src line 9 Java Problem
    The value of the local variable fred is not used ArrayDemo.java /ArrayDemo/src line 7 Java Problem
    The serializable class ImageLoader does not declare a static final serialVersionUID field of type long ImageLoader.java /DrawMemory/src line 7 Java Problem
    The value of the local variable lance is not used ArrayDemo.java /ArrayDemo/src line 23 Java Problem
    The serializable class Display does not declare a static final serialVersionUID field of type long Display.java /ImageLoader/src line 5 Java Problem
    The serializable class DrawBevel2 does not declare a static final serialVersionUID field of type long DrawBevel2.java /DrawBevel2/src line 8 Java Problem
    The serializable class Bevel2 does not declare a static final serialVersionUID field of type long DrawBevel2.java /DrawBevel2/src line 27 Java Problem
    The method show() from the type Window is deprecated DrawBevel2.java /DrawBevel2/src line 18 Java Problem
    The serializable class DrawMemoryCanvas does not declare a static final serialVersionUID field of type long DrawMemoryCanvas.java /DrawMemory/src line 8 Java Problem
    The method show() from the type Window is deprecated Display.java /ImageLoader/src line 19 Java Problem
    The serializable class RemoteDisplayCanvas does not declare a static final serialVersionUID field of type long RemoteDisplayCanvas.java /ImageLoader/src line 6 Java Problem
    The serializable class CheckerBoard does not declare a static final serialVersionUID field of type long CheckerBoard.java /CheckerBoard/src line 8 Java Problem
    The serializable class Checker does not declare a static final serialVersionUID field of type long CheckerBoard.java /CheckerBoard/src line 29 Java Problem
    The method show() from the type Window is deprecated CheckerBoard.java /CheckerBoard/src line 19 Java Problem
    The serializable class ImageLoader does not declare a static final serialVersionUID field of type long ImageLoader.java /ImageLoader/src line 7 Java Problem
    The serializable class ColourFadeCanvas does not declare a static final serialVersionUID field of type long ColourFade.java /ColourFade/src line 30 Java Problem
    The serializable class ColourFade does not declare a static final serialVersionUID field of type long ColourFade.java /ColourFade/src line 9 Java Problem
    The serializable class DrawMemory does not declare a static final serialVersionUID field of type long DrawMemory.java /DrawMemory/src line 5 Java Problem
    The method show() from the type Window is deprecated DrawMemory.java /DrawMemory/src line 16 Java Problem
    The method show() from the type Window is deprecated ColourFade.java /ColourFade/src line 20 Java Problem
    The serializable class ImageLoader does not declare a static final serialVersionUID field of type long ImageLoader.java /CheckerBoard/src line 7 Java Problem
    I have no idea why or how I'm getting these errors. Could someone help me?

    Thanks
    Astralogic

    Edit: I added code tags, and stars *** to highlight the lines on which the errors occured.
    Last edited by Astralogic; 08-15-2012 at 02:20 PM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,970
    Rep Power
    19

    Default Re: Why are these words underlined in red in Eclipse?

    Keep the code tags, because most of us won't bother reading unformatted code.

    Provide the relevant error text and point out which line they occur on.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Astralogic is offline Member
    Join Date
    Mar 2012
    Posts
    71
    Rep Power
    0

    Default Re: Why are these words underlined in red in Eclipse?

    Here is an image of what is highlighted red:

    Why are these words underlined in red in Eclipse?-eclipse-screen01.jpg

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Why are these words underlined in red in Eclipse?

    You are trying to use fields of a class that don't exist. Look up the Graphics API and see if it has LEFT, RIGHT, TOP,... fields and you'll see that it doesn't. You can't make things up and expect it to work.

  5. #5
    Astralogic is offline Member
    Join Date
    Mar 2012
    Posts
    71
    Rep Power
    0

    Default Re: Why are these words underlined in red in Eclipse?

    Quote Originally Posted by Fubarable View Post
    You are trying to use fields of a class that don't exist. Look up the Graphics API and see if it has LEFT, RIGHT, TOP,... fields and you'll see that it doesn't. You can't make things up and expect it to work.
    I didn't make those up, I found this method on a website with many many comments from people saying it is an excellent method to use.

    Take a look at them and you'll see why I assumed it should work perfectly.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Why are these words underlined in red in Eclipse?

    Quote Originally Posted by Astralogic View Post
    I didn't make those up, I found this method on a website with many many comments from people saying it is an excellent method to use.

    Take a look at them and you'll see why I assumed it should work perfectly.
    Rule number 2: don't believe all you see on the internet. The Java API is the final arbiter of what fields and methods a class has. If you check the Graphics API, you'll see that those fields simply don't exist for this class.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,970
    Rep Power
    19

    Default Re: Why are these words underlined in red in Eclipse?

    It does exist.
    In JME.
    Which is what that page is all about (see the heading - "[J2ME] Resize an Image Object ")
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default Re: Why are these words underlined in red in Eclipse?

    Quote Originally Posted by Astralogic View Post
    Take a look at them and you'll see why I assumed it should work perfectly.
    No, I don't see why you should assume that a url containing 'j2me' would lead you to code that would work perfectly in Java SE.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  9. #9
    Astralogic is offline Member
    Join Date
    Mar 2012
    Posts
    71
    Rep Power
    0

    Default Re: Why are these words underlined in red in Eclipse?

    Quote Originally Posted by DarrylBurke View Post
    No, I don't see why you should assume that a url containing 'j2me' would lead you to code that would work perfectly in Java SE.

    db
    Well, I didn't know they are two different things, thanks.

    I'll just forget about resizing the image.

    Astralogic

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default Re: Why are these words underlined in red in Eclipse?

    Quote Originally Posted by Astralogic View Post
    I'll just forget about resizing the image.
    Giving up so easily? Go through the API for BuferedImage and the Tutorial Lesson: Working with Images (The Java™ Tutorials > 2D Graphics)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. How many words in a joptionpane
    By Innes381 in forum New To Java
    Replies: 2
    Last Post: 06-03-2012, 03:00 PM
  2. Counting words
    By Wasley in forum New To Java
    Replies: 9
    Last Post: 01-30-2011, 10:57 PM
  3. Help: Num to words
    By MyOnlineChurva in forum New To Java
    Replies: 16
    Last Post: 01-08-2010, 01:41 AM
  4. Replies: 0
    Last Post: 06-25-2008, 10:34 AM
  5. help w words
    By Gilgamesh in forum New To Java
    Replies: 5
    Last Post: 11-21-2007, 06:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •