import import import import import import import import import
[Link]; [Link]; [Link].Graphics2D; [Link]; [Link]; [Link]; [Link]; [Link]; [Link];
import [Link]; public class test extends JApplet implements Runnable, MouseListener, MouseMotio nListener{ Thread t = new Thread(this); BufferedImage tempImage; Graphics2D g2d; Charger c; Battery b; Motor m; Car car; static final int FPS = 30; static final int w = 500; static final int h = 500; double cx=0; double cy=0; double angle=0; long lastTime = [Link](); long curTime = lastTime; static boolean pressed = false;
public void init(){ tempImage = new BufferedImage(500,500,BufferedImage.TYPE_4BYTE_ABGR); g2d = [Link](); b = new Battery(); c = new Charger(b); m = new Motor(b); car = new Car(200,200); [Link](); [Link](); [Link](); setSize(w,h); setVisible(true); setFocusable(true); addMouseListener(this);
addMouseMotionListener(this); } public void run(){ while(true){ //---------------------------------------------long lastTime = [Link](); long curTime = lastTime; while( true ) { curTime = [Link](); if(curTime - lastTime >= (1000.0/FPS)){ lastTime = curTime; if(checkDistance() == false){ pressed = false; } if(pressed == true){ if([Link] > 0){ double tempx = cx-car.x; double tempy = cy-car.y; angle = Math.atan2(tempy, tempx); car.x += [Link](angle)*[Link]; car.y += [Link](angle)*[Link]; [Link] = angle; } } repaint(); } }
} } public static void main(String[] args){
new test(); } public void paint(Graphics g){ [Link]([Link]); [Link](0,0,w,h); [Link]([Link]); [Link](10, 10, 10, 100); for(int i=0;i<[Link];i++){ //[Link](10,110-10*[Link],10,[Link]*10); //drawBlock(g2d, 10, 10*[Link]); //drawBlock(g2d, 10, 10+10*[Link]); drawBlock(g2d, 10, 100, i);
} [Link]([Link]); [Link]([Link]); [Link](g2d, (int)car.x, (int)car.y); [Link]([Link]); //for(int i=0;i<10;i++) //[Link](110,10+i*10,10,10); //drawBlock(g2d, 10, 10, i); [Link](tempImage,0,0,w,h,this); } public void drawBlock(Graphics2D g2d, int x, int y, int i){ [Link]([Link]); [Link](x, y-i*10, 10, 9); } public void keyReleased(KeyEvent e){ pressed = false; } public void keyTyped(KeyEvent e){ } public void mouseDragged(MouseEvent e){ curTime = [Link](); if(curTime - lastTime >= (1000.0/FPS)){ lastTime = curTime; cx = [Link](); cy = [Link](); if([Link] > 0 && checkDistance()){ pressed = true; moveCar(); repaint(); } } } public void mouseReleased(MouseEvent e){ repaint(); pressed = false; } public void mousePressed(MouseEvent e){ cx = [Link](); cy = [Link](); if([Link] > 0){ moveCar(); repaint();
pressed = true; } } public void mouseEntered(MouseEvent e){ } public void mouseExited(MouseEvent e){ } public void mouseMoved(MouseEvent e){ } public void mouseClicked(MouseEvent e){ } public void moveCar(){ double tempx = cx-car.x; double tempy = cy-car.y; angle = Math.atan2(tempy, tempx); car.x += [Link](angle)*[Link]; car.y += [Link](angle)*[Link]; [Link] = angle; } public boolean checkDistance(){ double tempx = cx-car.x; double tempy = cy-car.y; double distance = [Link]([Link](tempx, 2) + [Link](tempy, 2)); if(distance > [Link]){ return true; } return false; } } class Battery{ int status; public Battery(){ status = 0; } public synchronized void charge(){ // if(status >= 10){ try{ wait(); }catch(Exception e){} } if(status < 10) status++; [Link]("Charging : "+status+" %"); try{ [Link](100);
}catch(Exception e){} notifyAll(); } public synchronized void discharge(){ if(status <= 0){ try{ wait(); }catch(Exception e){} } if([Link] == true){ if(status > 0) { status--; } [Link]("\t\t Using : "+status+" %"); } try{ [Link](500); }catch(Exception e){} notifyAll(); } } class Charger extends Thread{ Battery battery; public Charger(Battery b){ battery = b; } public void run(){ while(true){ if([Link] == false){ [Link](); } } } } class Motor extends Thread{ Battery battery; public Motor(Battery b){ battery = b; } public void run(){ while(true){ if([Link] == true){ [Link](); } } } } class Car { double x; double y; double angle; //
double speed; public Car(int x, int y){ this.x = x; this.y = y; [Link] = 0; [Link] = 15; } public void drawCar(Graphics2D g2d, int x, int y){ [Link](angle, x, y); [Link]([Link]); [Link](x-15, y-5, 30, 10); [Link]([Link]); [Link](x-15, y-5, 30, 10); [Link](x+5, y-5, 10, 10); [Link](-angle, x, y); } }