アットウィキロゴ

java0214

import java.awt.*;
import java.awt.event.*;

class game0214 extends Frame implements Runnable ,MouseListener{

int px,py;
int mode;
int map[]=new int[1001];
int m;

public static void main(String [] args) {
        Frame f=new game0214();
        f.setTitle("game0214");
        f.setSize(500,500);
        f.setBackground(Color.yellow);
        f.setVisible(true);
    }

game0214(){

for (m=1;m<1001;m++){
map[m]=(int)(300*Math.random());
}

addMouseListener(this);

Thread th=new Thread(this);
th.start();
addWindowListener(new stopwin());
}


class stopwin extends WindowAdapter{
    public void windowClosing(WindowEvent we){System.exit(0);}
}  


public void run(){
int t;
mode=1;
px=300;
py=400;
t=0;
while(t<200){
if(px>500)px=500;
if(px<100)px=100;
repaint();
try{
Thread.sleep(100);
}catch(InterruptedException e){}
t=t+1;
}
repaint();
}


public void mouseEntered(MouseEvent e){
    }

public void mouseExited(MouseEvent e){
  }

  public void mousePressed(MouseEvent e){
}

  public void mouseReleased(MouseEvent e){
   }

  public void mouseClicked(MouseEvent e){
int x,y;
y=e.getY() ;
x=e.getX();
if(x>px+10)px=px+10;
if(x<px-10)px=px-10; ;
}

public void paint(Graphics g){

g.setColor(Color.green);
for (m=1;m<501;m++){
g.fillRect(m+px+100,1,1,map[m]);
}

g.setColor(Color.black);
g.fillRect(px,py,50,50);
}

}
最終更新:2011年02月13日 17:14