Im 이미지를 Java로로드하려고하지만 코드를 실행할 때 내 JFrame에 아무 것도 나타나지 않습니다.Java (BlueJ)에서 캔트로드 이미지
방식의 메신저 내 주에서 내 이미지 함수를 호출하고 : 다음
import java.awt.*; // Graphics stuff from the AWT library, here: Image
import java.io.File; // File I/O functionality (for loading an image)
import javax.swing.ImageIcon; // All images are used as "icons"
public class GameImage
{
public static Image loadImage(String imagePathName) {
// All images are loades as "icons"
ImageIcon i = null;
// Try to load the image
File f = new File(imagePathName);
if(f.exists()) { // Success. Assign the image to the "icon"
i = new ImageIcon(imagePathName);
}
else { // Oops! Something is wrong.
System.out.println("\nCould not find this image: "+imagePathName+"\nAre file name and/or path to the file correct?");
System.exit(0);
}
// Done. Either return the image or "null"
return i.getImage();
} // End of loadImages method
}
를 그리고 여기 전화 :
GI_Background = GameImage.loadImage("Images//background.jpg");
GI_DuskyDolphin = GameImage.loadImage("Images//DuskyDolphin.jpg");
을이 나는 기꺼이를 제공 할 것이다 충분한 정보가없는 경우 코드의 나머지 부분 :) 감사합니다
이미지로 수행 할 작업을 표시합니다. 이미지 표시 방법을 보여줍니다. (아마) 프로그램이이 코드를 종료하지 않을 것이기 때문에 아마 괜찮을 것입니다. – Radiodef
좋아,이 이미지는'GI_Background'이지만, 어떻게 할 것인가? 레이블에 추가합니까, 페인트합니까? 네가 그걸로 아무 것도하지 않는다는 것을 나는 안다. –
배포 시점까지는 해당 리소스가 [태그 : 포함 리소스]가 될 수 있습니다. 그렇다면 리소스는'File' 대신'URL'에 의해 접근되어야합니다. 'URL'을 구성하는 방법은 태그에 대한 [info page] (http://stackoverflow.com/tags/embedded-resource/info)를 참조하십시오. –