package tabletennis;
import java.awt.*;
import javax.swing.*;
public class BallGame extends JFrame{
//加载图片
Image ball = Toolkit.getDefaultToolkit().getImage("img/ball.png");
Image desk = Toolkit.getDefaultToolkit().getImage("img/desk.jpg");
//画窗口方法
public void paint(Graphics g) {
System.out.println("窗口被画了一次!");
g.drawImage(desk,0,0,null);
g.drawImage(ball,100,100,null);
}
//窗口加载
void launchFrame() {
setSize(300,300);
setLocation(856,500);
setVisible(true);
}
public static void main(String[] args) {
BallGame ballgame = new BallGame();
ballgame.launchFrame();
}
}
3 回答
ibeautiful
TA贡献1993条经验 获得超5个赞
检查路径对么,最好用项目路径
this.getClass().getResource("/").getPath()//这个是获取class路径的
添加回答
举报
0/150
提交
取消