これは私のコードです:
package com.dani.Game;
import java.awt.*;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.io.*;
import java.util.*;
public class Game extends JFrame {
BufferedImage normal;
public static void main(String[] args) {
Game game = new Game();
}
public Game() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
try {
normal = ImageIO.read(new File("C:\\ImageOne.jpg"));
} catch (IOException e) {
e.printStackTrace();
}
ImagePanel graphics = new ImagePanel();
this.add(graphics);
this.setVisible(true);
}
public class ImagePanel extends JPanel {
public void paintComponent(Graphics g) {
super.paint(g);
g.drawImage(normal,normal.getWidth(), normal.getHeight(), this);
}
}
更新しました:
これを試すと、次の例外が発生します。
Exception in thread
"AWT-EventQueue-0" java.lang.StackOverflowError
at sun.awt.AppContext.get(Unknown Source)
at javax.swing.RepaintManager.currentManager(Unknown Source)
at javax.swing.RepaintManager.currentManager(Unknown Source)
at javax.swing.RepaintManager.currentManager(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at com.course.swing.headPrac$Drawing.paintComponent(headPrac.java:99)
at javax.swing.JComponent.paint(Unknown Source)
私は何を間違っていますか?