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

    Default 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

  2. #2
    Zyril is offline Senior Member
    Join Date
    Oct 2011
    Location
    Sweden
    Posts
    124
    Rep Power
    0

    Default 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)?

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Two quick (and simple) questions

    Please go through the Forum Rules -- particularly the third paragraph.

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

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

    Default Re: Two quick (and simple) questions

    Quote Originally Posted by Zyril View Post
    Where is the class you want to import located?
    Workspace\ImageLoader\ImageLoader.java <- that's the class I want to import.

    Quote Originally Posted by Zryril
    Where are you going to include the path to the image you want to use (where in the code)?
    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.

    Thanks
    Astralogic

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

    Default 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 12:50 PM.

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

    Default Re: Two quick (and simple) questions

    Does anyone know of a more active Java forum?

  7. #7
    AnnaPatricia is offline Member
    Join Date
    Aug 2012
    Posts
    13
    Rep Power
    0

    Default Re: Two quick (and simple) questions

    extends or implement



    you know how to use them??

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

    Default Re: Two quick (and simple) questions

    Quote Originally Posted by AnnaPatricia View Post
    extends or implement



    you know how to use them??
    I've used the extends keyword several times to extend Frame and Canvas objects. I don't know how to use "implement" if that's a keyword.

    This just MAY be too complex for me to do at this level, I just though it would have been quite a simple thing to do.

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Two quick (and simple) questions

    Quote Originally Posted by Astralogic View Post
    I don't know how to use "implement" if that's a keyword.
    Lesson: Interfaces and Inheritance (The Java™ Tutorials > Learning the Java Language)

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

  10. #10
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default Re: Two quick (and simple) questions

    Quote Originally Posted by Astralogic View Post
    How do I make my project refer to another project? "import Imageloader.ImageLoader;" does not work.
    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

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

    Default Re: Two quick (and simple) questions

    Quote Originally Posted by awinston View Post
    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?

    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);
    	}

  12. #12
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Two quick (and simple) questions

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

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

Similar Threads

  1. 2 quick questions
    By krosen11 in forum New To Java
    Replies: 3
    Last Post: 05-21-2012, 08:48 PM
  2. Quick & Simple Question about JLabels.
    By CuppaCoffee in forum New To Java
    Replies: 1
    Last Post: 02-05-2012, 02:41 AM
  3. Quick simple question.
    By FnL7676 in forum New To Java
    Replies: 14
    Last Post: 03-08-2011, 01:26 AM
  4. Two quick questions
    By smacker in forum New To Java
    Replies: 1
    Last Post: 03-07-2011, 01:11 AM
  5. Couple quick log4j questions
    By lowlyintern in forum New To Java
    Replies: 1
    Last Post: 06-22-2010, 07:14 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
  •