Results 1 to 13 of 13
Thread: Two quick (and simple) questions
- 08-13-2012, 10:19 AM #1
Member
- Join Date
- Mar 2012
- Posts
- 71
- Rep Power
- 0
Two quick (and simple) questions
Hello, how do I import a class into a project? I know I could just re-create the empty class and paste the code into it, but I've already done that and I think it's time to learn how to do it properly :)
Also, if I want to refer to an image file without any sort of path to it, where do I put the image file? In other words I'd like to refer to it by filename alone.
Thanks
Astralogic
- 08-13-2012, 02:20 PM #2
Senior Member
- Join Date
- Oct 2011
- Location
- Sweden
- Posts
- 123
- Rep Power
- 0
Re: Two quick (and simple) questions
Where is the class you want to import located?
Look into how API's and class libraries are built and how you import them.
Where are you going to include the path to the image you want to use (where in the code)?
- 08-13-2012, 02:35 PM #3
Re: Two quick (and simple) questions
Please go through the Forum Rules -- particularly the third paragraph.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 08-14-2012, 09:57 AM #4
Member
- Join Date
- Mar 2012
- Posts
- 71
- Rep Power
- 0
Re: Two quick (and simple) questions
Workspace\ImageLoader\ImageLoader.java <- that's the class I want to import.
It will be in the ImageLoader class. I have a loadImageFromFile(String) method and a loadImageFromInternet(String) method. I want to call the loadImageFromFile() method and send it just the filename of the image rather than the whole path.
Originally Posted by Zryril
Thanks
Astralogic
- 08-15-2012, 11:45 AM #5
Member
- Join Date
- Mar 2012
- Posts
- 71
- Rep Power
- 0
Re: Two quick (and simple) questions
How do I make my project refer to another project? "import Imageloader.ImageLoader;" does not work.
Last edited by Astralogic; 08-15-2012 at 11:50 AM.
- 08-16-2012, 11:51 AM #6
Member
- Join Date
- Mar 2012
- Posts
- 71
- Rep Power
- 0
Re: Two quick (and simple) questions
Does anyone know of a more active Java forum?
- 08-16-2012, 11:57 AM #7
Member
- Join Date
- Aug 2012
- Posts
- 13
- Rep Power
- 0
Re: Two quick (and simple) questions
extends or implement
you know how to use them??
- 08-16-2012, 12:22 PM #8
Member
- Join Date
- Mar 2012
- Posts
- 71
- Rep Power
- 0
Re: Two quick (and simple) questions
- 08-16-2012, 04:06 PM #9
Re: Two quick (and simple) questions
Why do they call it rush hour when nothing moves? - Robin Williams
- 08-16-2012, 07:53 PM #10
Student
- Join Date
- Jul 2012
- Location
- United States
- Posts
- 328
- Rep Power
- 1
Re: Two quick (and simple) questions
But extending a class or implementing an interface is not how you import a class.
What do you mean by "does not work"? Do you receive any errors? If so, please post the full error messages.
Is ImageLoader.java inside a package called ImageLoader? Do you include the directory where the ImageLoader package is located within your classpath when compiling the class that utilizes ImageLoader?"Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill
- 08-25-2012, 12:51 PM #11
Member
- Join Date
- Mar 2012
- Posts
- 71
- Rep Power
- 0
Re: Two quick (and simple) questions
I thought I replied to you ages ago, good job I came back to this thread. I have solved my first problem, I didn't add the project to the classpath, doing so solved it.
But could someone tell me where I should put an image file if I want the below method to work if the "filename" String variable passed into it is just a filename with no path.
Java Code:public Image loadImageFromFile(String filename) { Image image = null; Toolkit tk = Toolkit.getDefaultToolkit(); image = tk.getImage(filename); waitForImage(image); return(image); }
- 08-25-2012, 06:23 PM #12
Re: Two quick (and simple) questions
Why do they call it rush hour when nothing moves? - Robin Williams
- 08-27-2012, 12:04 PM #13
Member
- Join Date
- Mar 2012
- Posts
- 71
- Rep Power
- 0
Similar Threads
-
2 quick questions
By krosen11 in forum New To JavaReplies: 3Last Post: 05-21-2012, 07:48 PM -
Quick & Simple Question about JLabels.
By CuppaCoffee in forum New To JavaReplies: 1Last Post: 02-05-2012, 01:41 AM -
Quick simple question.
By FnL7676 in forum New To JavaReplies: 14Last Post: 03-08-2011, 12:26 AM -
Two quick questions
By smacker in forum New To JavaReplies: 1Last Post: 03-07-2011, 12:11 AM -
Couple quick log4j questions
By lowlyintern in forum New To JavaReplies: 1Last Post: 06-22-2010, 06:14 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks