java图像未在简单JFrame中显示
嗨,我正在为我想创建的游戏创建一个小演示。我想把马里奥的照片画在一条黑线上。我已经实现了下面的代码。{JPanel
,但结果是一样的
package Game;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class world extends JFrame {
public static void main(String[] args) {
// TODO Auto-generated method stub
world w = new world();
}
public ImageIcon mario = new ImageIcon("D:\\Eclipse\\2DShooter\\Photos\\wall-jump.jpg");
public world() {
setTitle("Demo");
setSize(800, 480);
setDefaultCloseOperation(EXIT_ON_CLOSE);
JLabel Mario = new JLabel();
Mario.setIcon(mario);
add(Mario);
setVisible(true);
}
public void paint(Graphics g){
g.setColor(Color.BLACK);
g.fillRect(0, 460, 800, 20);
}
}
共 (0) 个答案