-1
이 코드가 있지만 이미지 stone.png을로드하는 방법을 모르므로 사용할 수 있습니다..jar 파일의 .png 이미지에 액세스하여 사용하십시오.
package mine.mine.mine;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class MainGame {
private static void showGUI()
{ JFrame frame = new JFrame("Mine Mine Mine");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel emptyLabel = new JLabel("");
emptyLabel.setPreferredSize(new Dimension(496, 496));
frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
BufferedImage img = null, diamond = null, emerald = null, gold = null, lapis = null, iron = null, redstone = null, coal = null; //Ignore these.
try {
img = ImageIO.read(new File("stone.png")); //Main problem is here. Used debug method on line 27.
} catch (IOException e) {
JOptionPane.showMessageDialog(null, "ERROR: The game has corrupted/missing files. Please redownload the game.", "Mine Mine Mine", JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(null, e.getStackTrace());
}
}
public static void main(String args[]){
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
showGUI();
}
});
}
}
내가 JLabel의 또는 JFrame의에 stone.png 표시 할이 내 처음으로 그렇게 나에게 멍청한 놈을 호출하지 마십시오이 시도이다. ;)
안녕하세요, 고마워. JLabel/JFrame에 이미지를 표시하는 것을 도와 주시겠습니까? –
[레이블 사용 방법] (http://docs.oracle.com/javase/tutorial/uiswing/components/label.html) – MadProgrammer