import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class WangBa {
public static void main(String[] args) {
JFrame w=new JFrame();
w.setSize(1720, 768);
w.setBackground(Color.LIGHT_GRAY);
Mypan mp=new Mypan();
w.add(mp);
w.addMouseListener(mp);
w.addMouseMotionListener(mp);
w.addKeyListener(mp);
mp.addKeyListener(mp);
Thread ti=new Thread(mp);
ti.start();
w.show();
}
}
class Mypan extends JPanel implements Runnable,MouseListener,MouseMotionListener,KeyListener{//这里要设置监听
int x=300;//乌龟的初始坐标
int y=100;
int[] m=new int[50];//气泡
int[] n=new int[50];
int[] q=new int[50];
int[] a=new int[300];//海水
int[] b=new int[300];
int[] c=new int[10];//金鱼
int[] d=new int[10];
int f=0;//o就是右下,如果是1就是左下,2就是左上,3就是右上
int ga=0;
boolean fan=true;
boolean mov=true;
Mypan(){
for(int i=0;i<300;i++){//设置海浪的随机
a[i]=(int)(Math.random()*1720);
b[i]=(int)(Math.random()* 768);
}
for(int j=0;j<50;j++){//设置气泡的随机
m[j]=(int)(Math.random()*1720);
n[j]=(int)(Math.random()* 768);
q[j]=(int)(Math.random()*35+4);
}
for(int k=0;k<10;k++){//设置金鱼的随机
c[k]=(int)(Math.random()*1720);
d[k]=(int)(Math.random()* 268+450);//金鱼一般在底部运动
}
}
public void paintComponent(Graphics g){
super.paintComponent(g);
this.setBackground(Color.cyan);
for(int j=0;j<50;j++){//画气泡
g.setColor(Color.blue);
g.fillOval(m[j], n[j], q[j], q[j]);
g.setColor(Color.white);
g.fillOval(m[j]+3,n[j]+3,q[j]-4,q[j]-4);
}
g.setColor(Color.green);
g.fillOval(80,600,20,200);
g.fillOval(70, 650, 200, 200);
g.setColor(Color.cyan);
g.fillOval(80, 670, 200, 200);
g.setColor(Color.green);
g.fillOval(40, 650, 50, 50);
g.setColor(Color.cyan);
g.fillOval(30, 670, 50, 50);
g.setColor(Color.green);
g.fillOval(150,500,25,300);
g.fillOval(140, 650, 200, 300);
g.setColor(Color.cyan);
g.fillOval(150, 670, 200, 200);
g.setColor(Color.green);
g.fillOval(110, 650, 50, 50);
g.setColor(Color.cyan);
g.fillOval(100, 670, 50, 50);
for(int k=0;k<10;k++){//画金鱼
g.setColor(Color.black);
g.fillOval(c[k], d[k], 20, 15);
g.setColor(Color.cyan);
g.fillOval(c[k]-10, d[k], 20, 15);
g.setColor(Color.orange);
g.fillOval(c[k]+15, d[k]-10, 50, 30);
g.setColor(Color.black);
g.fillOval(c[k]+45, d[k]-5, 5, 10);
g.setColor(Color.red);
g.fillOval(c[k]+63, d[k]+3, 5, 8);
}
if(fan==true){
if(mov==true){
g.setColor(Color.getHSBColor(169, 40, 3));//乌龟的头
g.fillOval(x, y, 70, 100);
g.setColor(Color.BLACK);
g.fillOval(x+10, y+30, 10, 10);
g.fillOval(x+50, y+30, 10, 10);
}else{
g.setColor(Color.getHSBColor(169, 40, 3));//乌龟的头
g.fillOval(x, y, 70,