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...
Printable View
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...
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"
So the path of the program is : C:\MyJavaPrograms\Assignment.java
The path to one of the images is: C:\MyJavaPrograms\cards\c1.gif
What happens when you compile and execute the code?
well nothing since it cant access the images its just a blank applet screen
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.
there aren't any error messages, the applet just comes up as a blank screen
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" );
}
}
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.