템플릿 이미지를 읽고 그 위에 텍스트를 쓴 다음 새 텍스트로 새 이미지를 만드는 이미지 작성자를 만들려고합니다. 어떤 이유로 내 코드가 괜찮아 보일 때 오류가 발생합니다. 다음은 아래 코드입니다.
public class GUI extends JFrame{
private JPanel p1 = new JPanel();//Puts tiles in, and organizes them for you
private JPanel p2 = new JPanel();//Holds trash tiles
JLabel ll = new JLabel();
//private JPanel p3 = new JPanel();//Holds trash tiles
public GUI(){
this.setTitle("Tile Game");
this.setSize(600,600);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
try {
createTile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.add(ll);
}
public void createTile() throws IOException{
final BufferedImage image = ImageIO.read(getClass().getResource("/src/tile.png"));
//File outPut = new File("saved.png");
Graphics g = image.getGraphics();
g.setFont(g.getFont().deriveFont(30f));
g.drawString("Hello World!", 100, 100);
g.dispose();
ImageIO.write(image, "png", new File("/src/test2.png"));
final BufferedImage image2 = ImageIO.read(new File("/src/test2.png"));
ImageIcon icon1 = new ImageIcon(image2);
ll.setIcon(icon1);
p1.add(ll); }
}
위의 코드를 실행하면 다음과 같은 오류가 발생합니다.
GUI.<init>() line: 36
Start.main(String[]) line: 7
GUI 생성자를 디버깅하라는 요청을받는 이유를 이해하지 못합니다. 모두 완벽하게 작동하는 것 같습니다.
이미지 위치가 적합하지 않습니다! (다른 클래스는 무시하고 테스트 프로젝트 일뿐입니다 ^^)
이클립스 프로젝트에 폴더를 만들되 소스 디렉토리 (!!!)에없는 폴더를 만든 다음 다음과 같은 이미지를 참조하십시오.
Image img1 = Toolkit.getDefaultToolkit().getImage("img/index.png");
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다