Results 1 to 11 of 11
  1. #1
    javaa is offline Member
    Join Date
    Aug 2012
    Posts
    28
    Rep Power
    0

    Default how to access images

    ok so i have this folder on the c drive called MyJavaPrograms and then within it I have a program and a folder called cards. how do I access the images within the folder cards through the program? Thanks!!
    ps sorry if thats a little confusing...

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,412
    Rep Power
    25

    Default Re: how to access images

    What is the path from where the current directory is (when the program executes) to where the folder with the images is?
    Sounds like: "cards/anImageFN.jpg"
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    javaa is offline Member
    Join Date
    Aug 2012
    Posts
    28
    Rep Power
    0

    Default Re: how to access images

    So the path of the program is : C:\MyJavaPrograms\Assignment.java
    The path to one of the images is: C:\MyJavaPrograms\cards\c1.gif

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

    Default Re: how to access images

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

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,412
    Rep Power
    25

    Default Re: how to access images

    What happens when you compile and execute the code?
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    javaa is offline Member
    Join Date
    Aug 2012
    Posts
    28
    Rep Power
    0

    Default Re: how to access images

    well nothing since it cant access the images its just a blank applet screen

  7. #7
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default Re: how to access images

    Quote Originally Posted by javaa View Post
    well nothing since it cant access the images its just a blank applet screen
    Have you drawn the image on the applet?
    Why don't you post your code here so people can see what you are doing wrong?
    Last edited by PhQ; 09-01-2012 at 10:45 PM.

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,412
    Rep Power
    25

    Default Re: how to access images

    Can you make a small simple program that compiles, executes and shows the problem?

    Are there any error messages? Look in the browser's java console.
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    javaa is offline Member
    Join Date
    Aug 2012
    Posts
    28
    Rep Power
    0

    Default Re: how to access images

    there aren't any error messages, the applet just comes up as a blank screen

  10. #10
    javaa is offline Member
    Join Date
    Aug 2012
    Posts
    28
    Rep Power
    0

    Default Re: how to access images

    Java Code:
    import java.awt.*;
    import java.applet.Applet;
    
    public class Unit12CTYassignment extends Applet {
    	private Image card;
    	private String cardT;
    	private int a1 = 5;
    
    	public void paint( Graphics screen ) {
    		for (int i = 0; i < 10; i++) {
    			getCard();
    
    			if (i < 5) {
    				screen.drawImage( card, a1 + (i*75) , 5, this);
    			}
    			else if (i < 10) {
    	 			screen.drawImage( card, a1 + ((i-5)*75) , 105, this);
    			}
    		}
    	}
    
    	public void getCard() {
    		int cardType = (int)(Math.random() * 4);
    		if (cardType == 0)
    			cardT = "c";
    		else if (cardType == 1)
    			cardT = "d";
    		else if (cardType == 2)
    			cardT = "h";
    		else if (cardType == 3)
    			cardT = "s";
    
    		int cardNumber = (int)(Math.random() * 13) + 1;
    
    		if (cardNumber <= 10) {
    			card = getImage( getDocumentBase(), cardT + cardNumber + ".gif" );
    		}
    		else if (cardNumber == 11)
    			card = getImage( getDocumentBase(), cardT + "j.gif" );
    		else if (cardNumber == 12)
    			card = getImage( getDocumentBase(), cardT + "k.gif" );
    		else if (cardNumber == 13)
    			card = getImage( getDocumentBase(), cardT + "q.gif" );
    	}
    }

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,412
    Rep Power
    25

    Default Re: how to access images

    Print out the values of the args to the getImage() method to see if the paths are correct.

    Add an ending else statement on the chain of i/else if statements that prints out a message if none of the above were true.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 0
    Last Post: 01-10-2011, 06:26 AM
  2. Replies: 0
    Last Post: 12-16-2010, 05:14 PM
  3. Replies: 4
    Last Post: 12-16-2010, 04:32 PM
  4. how to store images in access database
    By sridarshan in forum JDBC
    Replies: 11
    Last Post: 06-26-2010, 02:26 AM
  5. How to display Images from MS access using JSP
    By redmaverick in forum JDBC
    Replies: 3
    Last Post: 11-30-2009, 09:28 AM

Posting Permissions

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