import java.awt.*;
import javax.swing.ImageIcon;
import javax.swing.JApplet;
public class MonoplyDriver extends JApplet {
boolean isFirst=true;
Player John = new Player(1500,"Circle","John");
Board board = new Board();
Image imgBoard;
public void init()
{
//imgBoard = new ImageIcon("res/board.png").getImage();
imgBoard = getImage(getDocumentBase(),"res/board.png");
setSize(750,750);
System.out.println(getDocumentBase());
}
public void paint(Graphics g)
{
//super.paint(g);
if(isFirst)
{
isFirst=false;
}
g.drawImage(imgBoard, 0, 0, this);
}
}
答案 0 :(得分:1)
根据它的声音,找不到图像,因为它是内部资源。
您可以尝试类似......
imgBoard = ImageIO.read(getClass().getResource("res/board.png"));
如果由于某种原因无法加载图像,则会抛出IOException
,这比您现在获得的图片更有用
暂且不说。您应该避免直接绘制到顶级容器,而是使用从JComponent
延伸的内容并覆盖它的paintComponent
方法