Results 1 to 10 of 10
- 08-15-2012, 12:13 PM #1
Member
- Join Date
- Mar 2012
- Posts
- 71
- Rep Power
- 0
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.
These errors make no sense to me, not all of them refer to the above function though, and that's the only problem.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; } }
I have no idea why or how I'm getting these errors. Could someone help me?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
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.
- 08-15-2012, 01:38 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,447
- Rep Power
- 16
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.
- 08-16-2012, 12:20 PM #3
Member
- Join Date
- Mar 2012
- Posts
- 71
- Rep Power
- 0
-
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.
- 08-17-2012, 12:25 PM #5
Member
- Join Date
- Mar 2012
- Posts
- 71
- Rep Power
- 0
Re: Why are these words underlined in red in Eclipse?
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.
-
Re: Why are these words underlined in red in Eclipse?
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.
- 08-17-2012, 01:42 PM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,447
- Rep Power
- 16
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.
- 08-17-2012, 01:57 PM #8
- 08-17-2012, 02:34 PM #9
Member
- Join Date
- Mar 2012
- Posts
- 71
- Rep Power
- 0
- 08-17-2012, 06:40 PM #10
Re: Why are these words underlined in red in Eclipse?
Giving up so easily? Go through the API for BuferedImage and the Tutorial Lesson: Working with Images (The Java™ Tutorials > 2D Graphics)
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
How many words in a joptionpane
By Innes381 in forum New To JavaReplies: 2Last Post: 06-03-2012, 03:00 PM -
Counting words
By Wasley in forum New To JavaReplies: 9Last Post: 01-30-2011, 10:57 PM -
Help: Num to words
By MyOnlineChurva in forum New To JavaReplies: 16Last Post: 01-08-2010, 01:41 AM -
How to use TextAttribute class to obtain underlined and striked through text
By Java Tip in forum java.awtReplies: 0Last Post: 06-25-2008, 10:34 AM -
help w words
By Gilgamesh in forum New To JavaReplies: 5Last Post: 11-21-2007, 06:15 PM


LinkBack URL
About LinkBacks
Reply With Quote


Bookmarks