Pool.java
package com_Tentact_FishGame; //捕鱼达人游戏
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
public class Pool extends JPanel{
Pool pool;
Fish fish;
Net net;
BufferedImage poolImage;
public Pool() throws IOException {
poolImage=ImageIO.read(new File("src/image/bg.jpg")); //读取图片
}
@Override //读取图片后画图片
public void paint(Graphics g) {
g.drawImage(poolImage,0,0,null);
//g.drawImage(fish.fishImage,fish.point.x,fish.point.y,null);
** //就是上面这行代码,添加进去后就无法正常显示图片了。**
** //求大佬解决呀**
//g.drawImage(net.netImage,net.point.x,net.point.y,null);
}
}
Fish.java
package com_Tentact_FishGame;
import java.awt.Point;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Random;
import javax.imageio.ImageIO;
public class Fish {
Fish fish;
Point point;//用点来代替鱼的位置
BufferedImage fishImage;
Random random=new Random();//随机生成数
public Fish() throws IOException {
fishImage=ImageIO.read(new File("src/image/fish01_01.png"));
int x=random.nextInt(80);//生成x坐标
int y=random.nextInt(50);//生成y坐标
point=new Point(x,y);//生成鱼的位置
}
}
Windows.java
package com_Tentact_FishGame;
import java.io.IOException;
import javax.swing.JFrame;
public class Window extends JFrame{
public Window() throws IOException {
this.setSize(800,500);
this.setTitle("捕鱼达人");
this.setLocationRelativeTo(null);//居中
this.setResizable(false);//不可调节
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
Pool pool=new Pool();
this.add(pool);
this.setVisible(true);
}
}
Test.java
package com_Tentact_FishGame;
import java.io.IOException;
public class Test {
public static void main(String[] args) throws IOException {
Window window= new Window();
}
}