我的项目有问题:/
为什么 drawPac 不能正常工作。黑色矩形正在绘制,但我的图像不是:/为什么
我做了4个类,这里是3个类的鳕鱼,没有扩展JFrame的主类,并且添加了JPanel Game。
文件 #1
package pacman;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JPanel;
public class Game extends JPanel {
Pac pacman = new Pac();
public void Game() {
setFocusable(true);
setBackground(Color.BLACK);
setDoubleBuffered(true);
}
@Override
public void paint(Graphics g){
super.paint(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.black);
g2d.fillRect(0, 0,this.getWidth(),this.getHeight());
drawPac(g2d);
}
public void drawPac(Graphics2D g2d){
g2d.drawImage(pacman.image, pacman.x, pacman.y, 100, 100, this);
}
}
文件 #2
package pacman;
import java.awt.Image;
import javax.swing.ImageIcon;
public class Actor {
int x,y;
int dv;
Image image;
public void Actor(){
}
}
文件 #3
package pacman;
import pacman.Game;
import javax.swing.ImageIcon;
import java.awt.Graphics2D;
public class Pac extends Actor {
public void Pac(){
try{
image = new ImageIcon(Pac.class.getResource("../img/Pac00.gif")).getImage();
x=0;
y=0;
}
catch (Exception e){
System.out.println("Blad prz otwieraniu");
System.exit(0); }
}
}