我用Java编写了一个模拟,并且在帮助下得到了一个扩展JPanel的类。实施摘要如下:
public class Map extends JPanel {
BufferedImage truck1;
public Map() throws IOException {
truck1 = ImageIO.read(getClass().getResource("Truck.png"));
}
protected void paintcomponent (Graphics g) {
super.paintComponent(g);
g.drawImage(truck1, 50, 100, 300, 300, this);
}
如何在主函数中初始化或调用此对象,使其在屏幕上绘制对象?