Você está na página 1de 29

AACS3123 Java Programming II Assignment 2012

1.0 Module Functionalities


In this assignment, we develop a F1 Car Racing applet by using Java knowledge and Web Development knowledge. All of the modules and functions that contained in the assignment will be run on the browser. By using the Web Development knowledge, our assignment will be presented in a more interesting way, better quality and better view. Besides, we get our ideas for this assignment from the F1 official websites. We fulfil the system specifications which include Graphic User Interface (GUI), Multimedia, Applet, Multithreading and Networking. In developing Graphical User Interfaces (GUI) for this applet, we used knowledge learnt in subject AACS1193 Web Design and Development. We use some Flash Development Programs to help in presenting our final work. Multimedia, we also include music track, images, videos that related to F1 car racing in these web pages. This is to help we in stronger the desire of this assignment. Applet, we imported all the necessary images and audio that stimulates the F1 car racing to make the program feel like the user is on the real car racing situation. The cheers of the audience, the sound of the car engines will be played on the program. Multithreading, there are 6 cars will be running on the track, each of the car has their own thread. By using 1 car 1 thread, this will make the program more independent and each car can be run on different position. All the cars start runs on a same time because they share a same timer which is important in getting the elapsed time accurately. The cars speed is set to be random generated, so that the winner will be different each time the program restart. Networking, when each of the cars finishes the 3 laps, the result will be obtain from the timer and then send to the server to be analysed and determine which car is the winner. The ranking position of the car racer will be arranged by using formula that formulated by us and result/ ranking position will be shown in another page. Modules Handled by Lim Sau Jian: GUI, Applet, Multithreading and Networking Modules Handled by Ooi Wen Jie: GUI, Applet, Multimedia and Networking

AACS3123 Java Programming II Assignment 2012


2.0 Print Screen: Sample Testing and Functions

Figure 2.0: News Page This is the home page of our assignment; this page will introduce our assignment development process. The processes include Template and Example, Circuit Design, Multimedia for F1, Developing of Applet, Web Page Idea and Web Page Design.

Figure 2.1: Gallery Page This is the Gallery page; this page will show all the multimedia that relates to F1 Car Racing to stronger the desire of the assignment. This page will show the videos which is related to the assignment and sound tracks used in applet.

AACS3123 Java Programming II Assignment 2012

Figure 2.2: Drivers Page This page will briefly explain the cars driver that is being used in our assignment. The background colors of each driver represent the color of their car that is being used during the racing.

Figure 2.3: Track Page This page contains of a video guide that will explain on the track/circuit background that we used for the assignment. Besides, this page will also show the car model that we use for the F1 Car Racing Applet.

AACS3123 Java Programming II Assignment 2012

Figure 2.4: F1 Car Racing Applet By Default This interface shows the default view of the car racing situation. On the right side is the server that being used in this assignment. When user click on the start button, a start sound track will be heard and after the traffic lights turn from red to green, the 6 cars will began the race. If user click pause, the race will be pause, if user wish to resume the race, just click on the resume button. If user click stop, it will stop the entire program from running. On the middle, have a score board to show the racing time use by each car and the shortest time, the top speed of each car that is running on the track.

Figure 2.5: F1 Car Racing Applet When Lap Finish This interface will show the final view of the Car racing when all the cars finish their 3 laps running. The program will send the time used of each car and then the server will determine the result and it will be prompt the on screen. Besides, the server frame will also show the process of the server carry out. When user clicks on the Ok button on the, it will direct user to the Ranking Page, Result.

AACS3123 Java Programming II Assignment 2012

Figure 2.6: F1 Car Racing Applet Result Page This page will show the final ranking, the times used for each car race on the track. The placing of the race will be according to the result that being determined by the server. The color of the placer will be change according the cars color that is being introduced in the Driver Page.

AACS3123 Java Programming II Assignment 2012


3.0 Source Code
C:\Users\user\Desktop\SJLIM+OWJ\src\MyApplet.java

1 /* 2 Programmed By : SJLIM & WJOOI 3 Tutorial Group : Y2M41 4 */ 5 6 import java.applet.*; 7 import java.awt.*; 8 import java.awt.event.*; 9 import java.io.*; 10 import java.net.*; 11 import java.util.logging.Level;import java.text.DecimalFormat; 12 import java.util.logging.Logger; 13 import javax.swing.*; 14 15 public class MyApplet extends JApplet{ 16 17 Image track,light; 18 Image carRed,carCyan,carYellow,carBlue,carGreen,carWhite,pitstop,bg; 19 20 int redX,redY; 21 int cyanX,cyanY; 22 int yellowX,yellowY; 23 int blueX,blueY; 24 int greenX,greenY; 25 int whiteX,whiteY; 26 27 int redLap=0,cyanLap=0,yellowLap=0,blueLap=0,greenLap=0,finishLap=0; 28 29 boolean redEnd=false,cyanEnd=false,yellowEnd=false,blueEnd=false,greenEnd=false,whiteEnd=false; 30 31 boolean conditionStart=false; 32 33 AudioClip ready, start1, start2,running,horn1,horn2,cheer; 34 JButton jbtStart,jbtRem,jbtPause,jbtStop; 35 Container cp; 36 37 Thread red,cyan,yellow,blue,green,white; 38 39 Image image_onScreen; 40 Graphics tempGraphic; 41 42 double eRed=0.0,eCyan=0.0,eYellow=0.0,eBlue=0.0,eGreen=0.0,eWhite=0.0; 43 double bRed=0.0,bCyan=0.0,bYellow=0.0,bBlue=0.0,bGreen=0.0,bWhite=0.0; 44 double tRed=0.00,tCyan=0.00,tYellow=0.00,tBlue=0.00,tGreen=0.00,tWhite=0.00; 45 46 DecimalFormat twoDForm = new DecimalFormat("#.###"); 47 48 long startTime; 49 Timer timer=null; 50 51 String forfeit=""; 52 53 boolean pause=false; 54

AACS3123 Java Programming II Assignment 2012


55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 DataInputStream inputFromServer; DataOutputStream outputToServer; double[] timeFromServer=new double[5]; String[] carFromServer=new String[5]; //AppletServer myServer; Socket clientSocket; ImageIcon StartIcon1=new ImageIcon(getClass().getResource("images/start1.png")); ImageIcon StartIcon2=new ImageIcon(getClass().getResource("images/start2.png")); ImageIcon ResumeIcon1=new ImageIcon(getClass().getResource("images/resume1.png")); ImageIcon ResumeIcon2=new ImageIcon(getClass().getResource("images/resume2.png")); ImageIcon PauseIcon1=new ImageIcon(getClass().getResource("images/pause1.png")); ImageIcon PauseIcon2=new ImageIcon(getClass().getResource("images/pause2.png")); ImageIcon StopIcon1=new ImageIcon(getClass().getResource("images/stop1.png")); ImageIcon StopIcon2=new ImageIcon(getClass().getResource("images/stop2.png")); public static void main(String[] args){ try { Desktop.getDesktop().open(new File("build/classes/MyAppletHTML.html")); } catch (IOException ex) { Logger.getLogger(MyApplet.class.getName()).log(Level.SEVERE, null, ex); } } public void update(Graphics g){paint(g);} // overrided update method public void destroy(){ closeAudio(); try { if(clientSocket!=null) clientSocket.close(); } catch (IOException ex) { Logger.getLogger(MyApplet.class.getName()).log(Level.SEVERE, null, ex); } } // close all audio when applet destroyed public void init(){ // get track Image track=getImage(getClass().getResource("Track.JPG")); light=null; // get car Images and set original position setDefault(true); // get supporter images // get audio clips ready = Applet.newAudioClip(getClass().getResource("audio/ready.wav")); start1 = Applet.newAudioClip(getClass().getResource("audio/start1.wav")); start2 = Applet.newAudioClip(getClass().getResource("audio/start2.wav")); running = Applet.newAudioClip(getClass().getResource("audio/running.wav")); horn1 = Applet.newAudioClip(getClass().getResource("audio/horn1.wav")); horn2 = Applet.newAudioClip(getClass().getResource("audio/horn2.wav")); cheer = Applet.newAudioClip(getClass().getResource("audio/cheer.wav")); jbtStart=new JButton(StartIcon1);

AACS3123 Java Programming II Assignment 2012


115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 jbtRem=new JButton(ResumeIcon1); jbtPause=new JButton(PauseIcon1); jbtStop=new JButton(StopIcon1); jbtStart.setRolloverIcon(StartIcon2); jbtStart.setPressedIcon(StartIcon2); jbtRem.setRolloverIcon(ResumeIcon2); jbtRem.setPressedIcon(ResumeIcon2); jbtPause.setRolloverIcon(PauseIcon2); jbtPause.setPressedIcon(PauseIcon2); jbtStop.setRolloverIcon(StopIcon2); jbtStop.setPressedIcon(StopIcon2);

jbtStart.setOpaque(true); jbtRem.setOpaque(true); jbtPause.setOpaque(true); jbtStop.setOpaque(true); jbtStart.setBorderPainted(false); jbtRem.setBorderPainted(false); jbtPause.setBorderPainted(false); jbtStop.setBorderPainted(false); jbtStart.setContentAreaFilled(false); jbtRem.setContentAreaFilled(false); jbtPause.setContentAreaFilled(false); jbtStop.setContentAreaFilled(false); jbtStart.setFocusPainted(false); jbtRem.setFocusPainted(false); jbtPause.setFocusPainted(false); jbtStop.setFocusPainted(false); jbtStart.setToolTipText("Start New Game"); jbtRem.setToolTipText("Resume"); jbtPause.setToolTipText("Pause"); jbtStop.setToolTipText("Stop"); jbtStart.setPreferredSize(new Dimension(243, 25)); jbtRem.setPreferredSize(new Dimension(243, 25)); jbtPause.setPreferredSize(new Dimension(243, 25)); jbtStop.setPreferredSize(new Dimension(243, 25)); jbtStart.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ startNewGame(); repaint(); }}); jbtRem.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ running.stop(); red.resume();cyan.resume();yellow.resume();blue.resume();green.resume();white.resume(); if(!conditionStart){running.stop();} else{running.loop();} pause=false;

AACS3123 Java Programming II Assignment 2012


175 }}); 176 177 jbtPause.addActionListener(new ActionListener(){ 178 public void actionPerformed(ActionEvent e){ 179 red.suspend();cyan.suspend();yellow.suspend();blue.suspend();green.suspend();white.suspend(); 180 running.stop(); 181 pause=true; 182 183 }}); 184 185 jbtStop.addActionListener(new ActionListener(){ 186 public void actionPerformed(ActionEvent e){ 187 red.stop();cyan.stop();yellow.stop();blue.stop();green.stop();white.stop(); 188 running.stop(); 189 conditionStart=false; 190 if(timer!=null) 191 timer.stop(); 192 193 }}); 194 195 JPanel jpButton=new JPanel();; 196 jpButton=new JPanel(){ protected void paintComponent(Graphics g){ 197 g.drawImage(bg,0,0,bg.getWidth(this),bg.getHeight(this),null); 198 }}; 199 jpButton.setLayout(new FlowLayout(FlowLayout.LEFT)); 200 jpButton.add(jbtStart);jpButton.add(jbtRem);jpButton.add(jbtPause);jpButton.add(jbtStop); 201 jpButton.setSize(new Dimension(1000,400)); 202 203 setSize(1000,620); 204 bg=getImage(getClass().getResource("images/bg.jpg")); 205 206 cp = getContentPane(); 207 cp.setLayout(new BorderLayout()); 208 cp.add(jpButton,BorderLayout.SOUTH); 209 210 jpButton.setOpaque(false); 211 212 red = new Thread(new Red()); 213 cyan = new Thread(new Cyan()); 214 yellow = new Thread(new Yellow()); 215 blue = new Thread(new Blue()); 216 green = new Thread(new Green()); 217 white = new Thread(new White()); 218 219 this.paint(this.getGraphics()); 220 221 } 222 223 public void paint(Graphics g){ // Paint Method 224 image_onScreen = createImage(1000,620); 225 tempGraphic = image_onScreen.getGraphics(); 226 Font font = new Font("Helvetica", Font.BOLD, 16); 227 tempGraphic.setFont(font); 228 super.paintComponents(tempGraphic); 229 tempGraphic.drawImage(track, 0, 0,track.getWidth(this),track.getHeight(this), this); 230 tempGraphic.drawImage(light,755,195,70,165,null); 231 tempGraphic.drawImage(carRed,redX,redY,carRed.getWidth(this),carRed.getHeight(this),this); 232 tempGraphic.drawImage(carCyan,cyanX,cyanY,carCyan.getWidth(this),carCyan.getHeight(this),this);

AACS3123 Java Programming II Assignment 2012


233 tempGraphic.drawImage(carYellow,yellowX,yellowY,carYellow.getWidth(this),carYellow.getHeight(this),this); 234 tempGraphic.drawImage(carBlue,blueX,blueY,carBlue.getWidth(this),carBlue.getHeight(this),this); 235 tempGraphic.drawImage(carGreen,greenX,greenY,carGreen.getWidth(this),carGreen.getHeight(this),this); 236 tempGraphic.drawImage(carWhite,whiteX,whiteY,carWhite.getWidth(this),carWhite.getHeight(this),this); 237 238 tempGraphic.drawImage(pitstop,533,515,pitstop.getWidth(this),pitstop.getHeight(this),this); 239 240 tempGraphic.drawString(Double.toString(eRed), 350, 245); 241 tempGraphic.drawString(Double.toString(eCyan), 350, 270); 242 tempGraphic.drawString(Double.toString(eYellow), 350, 293); 243 tempGraphic.drawString(Double.toString(eBlue), 350, 315); 244 tempGraphic.drawString(Double.toString(eGreen), 350, 336); 245 tempGraphic.drawString(Double.toString(eWhite)+forfeit, 350, 360); 246 247 tempGraphic.drawString(Double.toString(bRed), 520, 245); 248 tempGraphic.drawString(Double.toString(bCyan), 520, 270); 249 tempGraphic.drawString(Double.toString(bYellow), 520, 293); 250 tempGraphic.drawString(Double.toString(bBlue), 520, 315); 251 tempGraphic.drawString(Double.toString(bGreen), 520, 336); 252 tempGraphic.drawString(Double.toString(bWhite), 520, 360); 253 254 tempGraphic.drawString(Double.toString(tRed), 650, 245); 255 tempGraphic.drawString(Double.toString(tCyan), 650, 270);; 256 tempGraphic.drawString(Double.toString(tYellow), 650, 293); 257 tempGraphic.drawString(Double.toString(tBlue), 650, 315); 258 tempGraphic.drawString(Double.toString(tGreen), 650, 336); 259 tempGraphic.drawString(Double.toString(tWhite), 650, 360); 260 261 g.drawImage(image_onScreen,0,0, null); 262 263 } 264 265 public void startNewGame(){ 266 267 try { 268 clientSocket = new Socket(getCodeBase().getHost(), 8000); 269 inputFromServer = new DataInputStream(clientSocket.getInputStream()); 270 outputToServer = new DataOutputStream(clientSocket.getOutputStream()); 271 System.out.println("Server Found"); 272 } 273 catch (IOException ex) { JOptionPane.showMessageDialog(null,"Hey ? Did you open server ?","F1 RACING CAR GAME", 274 JOptionPane.ERROR_MESSAGE,null); 275 } 276 277 conditionStart=true; 278 279 red.stop();cyan.stop();yellow.stop();blue.stop();green.stop();white.stop(); 280 281 closeAudio(); 282 283 red = new Thread(new Red()); 284 cyan = new Thread(new Cyan()); 285 yellow = new Thread(new Yellow()); 286 blue = new Thread(new Blue()); 287 green = new Thread(new Green()); 288 white = new Thread(new White());

10

AACS3123 Java Programming II Assignment 2012


289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 setDefault(true); ready.play(); this.paint(this.getGraphics()); try {Thread.sleep(2000L);}catch (InterruptedException ex) {} finally{start1.play();start2.play();running.loop();} light=getImage(getClass().getResource("images/orange.JPG")); this.paint(this.getGraphics()); try {Thread.sleep(3000L);light=getImage(getClass().getResource("images/green.JPG")); this.paint(this.getGraphics());} catch (InterruptedException ex) {} red.start();cyan.start();yellow.start();blue.start();green.start();white.start(); startTime = System.currentTimeMillis(); if(timer==null){ timer = new Timer(100,new CarTimer()); timer.start(); }else timer.restart(); } public void closeAudio(){ready.stop(); start1.stop(); start2.stop();running.stop();horn1.stop();horn2.stop();cheer.stop();} public void lapFinish(){ finishLap+=1; if(finishLap==5){ if(timer!=null) timer.stop(); running.stop();cheer.play();conditionStart=false; try { String[] carImgName={"red","cyan","yellow","blue","green","white"}; System.out.println("Sending Result to Server"); outputToServer.writeBoolean(true); outputToServer.writeDouble(eRed); outputToServer.writeUTF("Red Car"); outputToServer.flush(); outputToServer.writeDouble(eCyan); outputToServer.writeUTF("Cyan Car"); outputToServer.flush(); outputToServer.writeDouble(eYellow); outputToServer.writeUTF("Yellow Car"); outputToServer.flush(); outputToServer.writeDouble(eBlue); outputToServer.writeUTF("Blue Car"); outputToServer.flush(); outputToServer.writeDouble(eGreen); outputToServer.writeUTF("Green Car"); outputToServer.flush(); outputToServer.writeDouble(eWhite); System.out.println("Receving Result from Server"); timeFromServer[0]=inputFromServer.readDouble(); carFromServer[0]=inputFromServer.readUTF();

11

AACS3123 Java Programming II Assignment 2012


348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 carImgName[0]=inputFromServer.readUTF(); timeFromServer[1]=inputFromServer.readDouble(); carFromServer[1]=inputFromServer.readUTF(); carImgName[1]=inputFromServer.readUTF(); timeFromServer[2]=inputFromServer.readDouble(); carFromServer[2]=inputFromServer.readUTF(); carImgName[2]=inputFromServer.readUTF(); timeFromServer[3]=inputFromServer.readDouble(); carFromServer[3]=inputFromServer.readUTF(); carImgName[3]=inputFromServer.readUTF(); timeFromServer[4]=inputFromServer.readDouble(); carFromServer[4]=inputFromServer.readUTF(); carImgName[4]=inputFromServer.readUTF(); System.out.println("Server-Client : Result Shown"); Object[] result = {"Ranking \n\n"+ "1st : "+carFromServer[0]+"\n"+ "2nd : "+carFromServer[1]+"\n"+ "3th : "+carFromServer[2]+"\n"+ "4th : "+carFromServer[3]+"\n"+ "5th : "+carFromServer[4]+"\t\t\t\n"+ "6th : "+"White Car"+"\n\n\n" }; JOptionPane.showMessageDialog(null,result,"F1 RACING CAR CHAMPIONSHIP", JOptionPane.INFORMATION_MESSAGE,new ImageIcon( getImage(getClass().getResource("images/trophy.JPG")))); getAppletContext().showDocument(newURL( getDocumentBase(),"MyAppletResult.html"),"_self");

} catch (IOException ex) { System.out.println("Error in communicating"); } setDefault(false);repaint(); finishLap=0; } } // Default everything in Applet public void setDefault(boolean defaultCondition){ redX=470;redY=50; cyanX=470;cyanY=100; yellowX=470;yellowY=150; blueX=390;blueY=80; greenX=390;greenY=130; if(defaultCondition){ whiteX=310;whiteY=100;carWhite=getImage(getClass().getResource("car/white1.JPG")); pitstop=getImage(getClass().getResource("car/pitstop1.JPG")); eRed=0.0;eCyan=0.0;eYellow=0.0;eBlue=0.0;eGreen=0.0;eWhite=0.0; bRed=0.0;bCyan=0.0;bYellow=0.0;bBlue=0.0;bGreen=0.0;bWhite=0.0; tRed=0.00;tCyan=0.00;tYellow=0.00;tBlue=0.00;tGreen=0.00;tWhite=0.00;

12

AACS3123 Java Programming II Assignment 2012


407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 forfeit="";} redLap=0;cyanLap=0;yellowLap=0;blueLap=0;greenLap=0;finishLap=0; redEnd=false;cyanEnd=false;yellowEnd=false;blueEnd=false;greenEnd=false;whiteEnd=false; carRed=getImage(getClass().getResource("car/red1.JPG")); carCyan=getImage(getClass().getResource("car/cyan1.JPG")); carYellow=getImage(getClass().getResource("car/yellow1.JPG")); carBlue=getImage(getClass().getResource("car/blue1.JPG")); carGreen=getImage(getClass().getResource("car/green1.JPG")); light=getImage(getClass().getResource("images/red.JPG")); pause=false; repaint(); } // Car Thread public class Red implements Runnable{ int x,y; public void run() { int range=8000;double previousLap=0; while(!redEnd){ if(redLap!=3){ x=redX;y=redY; if((y==50&&x<870)&&x>=470){ //starting point carRed=getImage(getClass().getResource("car/red1.JPG")); x+=(int)(Math.random() * 15) + 8; } else if(x >= 870 && x<=960 && y < 350){ // top right turning carRed=getImage(getClass().getResource("car/red2.JPG")); x+=15; // moving to right if(x>=960){x=960;y+=5;} y += (int)(Math.random() * 11) + 5; } else if(y>=350&&x>95){ // bottom right turing y+=7; if(y>=460){y=460;} x-=(int)(Math.random() * 15) + 5; carRed=getImage(getClass().getResource("car/red3.JPG")); if(x<=95){x=95;} }else if(y<=460&&y>150){ // bottom left turning x-=10; if(x<=30){x=30;} y-=(int)(Math.random() * 11) + 5; carRed=getImage(getClass().getResource("car/red4.JPG")); if(y<=150){ x=30; y=150; } }else if(y<=150&&x<470){ // top left turing y-=5;x+=5; if(y<50){y=50;x+=5;x+=(int)(Math.random() * 12) + 5;}

13

AACS3123 Java Programming II Assignment 2012


467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 carRed=getImage(getClass().getResource("car/red1.JPG")); if(x>=470){ redLap+=1; if(redLap==1){bRed=eRed;previousLap=eRed;} else if((eRed-previousLap)<bRed){ bRed=Double.valueOf(twoDForm.format(eRed-previousLap)); previousLap=eRed;} } } redX=x;redY=y; }else{redEnd=true;} repaint();try {Thread.sleep(30);}catch(Exception e){} double speed=((int)(Math.random() * range) + 5)/100; if(range<25000){range+=20;} if(speed>tRed){tRed=speed;} }lapFinish();red.stop(); } } public class Cyan implements Runnable{ int x,y; public void run(){ int range=7500;double previousLap=0; while(!cyanEnd){ if(cyanLap!=3){ x=cyanX;y=cyanY; if(y==100&&x<860&&x>=470){ // -> increase from original position to X carCyan=getImage(getClass().getResource("car/cyan1.JPG")); x+=(int)(Math.random() * 15) + 8; } else if(x >= 860 && y < 340){ // V increase from top right moving down to Y carCyan=getImage(getClass().getResource("car/cyan2.JPG")); x+=15; // moving to X path position diff is 30 if(x>=930){x=930;y+=5;} y += (int)(Math.random() * 10) + 5; } else if(y>=340&&x>85){ // <- decreasing from btm right moving left to X y+=4; // moving to the Y path position diff is 30 if(y>=430){y=430;} x-=(int)(Math.random() * 12) + 5; carCyan=getImage(getClass().getResource("car/cyan3.JPG")); if(x<=85){x=85;} }else if(y<=430&&y>120){ // ^ decreasing from btm left moving up to Y x-=2; // moving to the X path position diff is 30 if(x<=50){x=50;} y-=(int)(Math.random() * 10) + 5; carCyan=getImage(getClass().getResource("car/cyan4.JPG")); if(y<=120){ x=50; y=120; } }else if(y<=120&&x<470){ // -> increase from top left position to original position

14

AACS3123 Java Programming II Assignment 2012


527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 y-=5; // moving to the Y path position diff is 30 if(y<100){y=100;x+=5;} x+=(int)(Math.random() * 12) + 5; carCyan=getImage(getClass().getResource("car/cyan1.JPG")); if(x>=470){ cyanLap+=1; if(cyanLap==1){bCyan=eCyan;previousLap=eCyan;} else if((eCyan-previousLap)<bCyan){ bCyan=Double.valueOf(twoDForm.format(eCyan-previousLap)); previousLap=eCyan;} } } cyanX=x;cyanY=y; } else{cyanEnd=true;} repaint();try {Thread.sleep(30);}catch(Exception e){} double speed=((int)(Math.random() * range) + 5)/100; if(range<27000){range+=20;} if(speed>tCyan){tCyan=speed;} }lapFinish();cyan.stop(); } } public class Yellow implements Runnable{ int x,y; public void run(){ int range=8000;double previousLap=0; while(!yellowEnd){ if(yellowLap!=3){ x=yellowX;y=yellowY; if(y==150&&x<830&&x>=470){ //starting point carYellow=getImage(getClass().getResource("car/yellow1.JPG")); x+=(int)(Math.random() * 8) + 5; } else if(x >= 830 && y < 350){ // top right turning x+=15; if(x>=900){x=900;y+=5;} y += (int)(Math.random() * 10) + 5; carYellow=getImage(getClass().getResource("car/yellow2.JPG")); } else if(y>=350&&x>100){ // bottom right turing y+=4; if(y>=385){y=385;} x-=(int)(Math.random() * 10) + 5; carYellow=getImage(getClass().getResource("car/yellow3.JPG")); if(x<=100){x=100;} }else if(y<=385&&y>200){ // bottom left turning x-=2; if(x<=80){x=80;} y-=(int)(Math.random() * 10) + 5; carYellow=getImage(getClass().getResource("car/yellow4.JPG")); if(y<=200){ x=80; y=200; }

15

AACS3123 Java Programming II Assignment 2012


587 }else if(y<=200&&x<470){ // top left turing 588 y-=15; if(y<150){y=150;x+=5;} 589 x+=(int)(Math.random() * 10) + 5; 590 carYellow=getImage(getClass().getResource("car/yellow1.JPG")); 591 if(x>=470){ 592 yellowLap+=1; 593 if(yellowLap==1){bYellow=eYellow;previousLap=eYellow;} 594 else if((eYellow-previousLap)<bYellow){ 595 bYellow=Double.valueOf(twoDForm.format(eYellow-previousLap)); previousLap=eYellow;} 596 } 597 } 598 yellowX=x;yellowY=y; 599 600 } 601 else{yellowEnd=true;} 602 603 repaint();try {Thread.sleep(30);}catch(Exception e){} 604 double speed=((int)(Math.random() * range) + 5)/100; 605 if(range<30000){range+=20;} 606 if(speed>tYellow){tYellow=speed;} 607 }lapFinish();yellow.stop(); 608 } 609 } 610 611 public class Blue implements Runnable{ 612 int x,y; 613 public void run(){ 614 int range=8700;double previousLap=0; 615 while(!blueEnd){ 616 if(blueLap!=3){ 617 x=blueX;y=blueY; 618 619 if(y==80&&x<830&&x>=390){ //starting point 620 carBlue=getImage(getClass().getResource("car/blue1.JPG")); 621 x+=(int)(Math.random() * 9) + 5; 622 } 623 else if(x >= 830 && y < 370){ // top right turning 624 x+=10; 625 if(x>=915){x=915;y+=5;} 626 y += (int)(Math.random() * 11) + 5; 627 carBlue=getImage(getClass().getResource("car/blue2.JPG")); 628 } 629 else if(y>=370&&x>115){ // bottom right turing 630 y+=4; 631 if(y>=405){y=405;} 632 x-=(int)(Math.random() * 12) + 5; 633 carBlue=getImage(getClass().getResource("car/blue3.JPG")); 634 if(x<=115){x=115;} 635 }else if(y<=405&&y>200){ // bottom left turning 636 x-=3; 637 if(x<=110){x=110;} 638 y-=(int)(Math.random() * 11) + 5; 639 carBlue=getImage(getClass().getResource("car/blue4.JPG")); 640 if(y<=200){ 641 x=110; 642 y=200; 643 } 644 }else if(y<=200&&x<390){ // top left turing 645 y-=20; if(y<80){y=80;x+=5;}

16

AACS3123 Java Programming II Assignment 2012


646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 x+=(int)(Math.random() * 8) + 5; if(x>=390){ blueLap+=1; if(blueLap==1){bBlue=eBlue;previousLap=eBlue;} else if((eBlue-previousLap)<bBlue){ bBlue=Double.valueOf(twoDForm.format(eBlue-previousLap)); previousLap=eBlue;} } carBlue=getImage(getClass().getResource("car/blue1.JPG")); } blueX=x;blueY=y; } else{blueEnd=true;} repaint();try {Thread.sleep(30);}catch(Exception e){} double speed=((int)(Math.random() * range) + 5)/100; if(range<26000){range+=20;} if(speed>tBlue){tBlue=speed;} }lapFinish();blue.stop(); } } public class Green implements Runnable{ int x,y; public void run(){ int range=7600;double previousLap=0; while(!greenEnd){ if(greenLap!=3){ x=greenX;y=greenY; if(y==130&&x<810&&x>=390){ //starting point carGreen=getImage(getClass().getResource("car/green1.JPG")); x+=(int)(Math.random() * 10) + 5; } else if(x >= 810 && y < 385){ // top right turning x+=15; // moving to right if(x>=930){x=930;y+=5;} y += (int)(Math.random() * 10) + 5; carGreen=getImage(getClass().getResource("car/green2.JPG")); } else if(y>=385&&x>125){ // bottom right turing y+=7; if(y>=445){y=445;} x-=(int)(Math.random() * 12) + 5; carGreen=getImage(getClass().getResource("car/green3.JPG")); if(x<=125){x=125;} }else if(y<=445&&y>200){ // bottom left turning x-=10; if(x<=70){x=70;} y-=(int)(Math.random() * 11) + 5; carGreen=getImage(getClass().getResource("car/green4.JPG")); if(y<=200){ x=70; y=200; } }else if(y>=130&&x<400){ // top left turing y-=10; if(y<=130){y=130;} x+=(int)(Math.random() * 14) + 5;

17

AACS3123 Java Programming II Assignment 2012


706 carGreen=getImage(getClass().getResource("car/green1.JPG")); 707 if(x>=390){ 708 greenLap+=1; 709 if(greenLap==1){bGreen=eGreen;previousLap=eGreen;} 710 else if((eGreen-previousLap)<bGreen){ 711 bGreen=Double.valueOf(twoDForm.format(eGreen-previousLap)); previousLap=eGreen;} 712 } 713 } 714 greenX=x;greenY=y; 715 716 } 717 else{greenEnd=true;} 718 719 repaint();try {Thread.sleep(30);}catch(Exception e){} 720 double speed=((int)(Math.random() * range) + 5)/100; 721 if(range<25200){range+=20;} 722 if(speed>tGreen){tGreen=speed;} 723 }lapFinish();green.stop(); 724 } 725 } 726 727 public class White implements Runnable{ 728 int x,y; 729 public void run(){ 730 int range=3000; 731 while(!whiteEnd){ 732 733 x=whiteX;y=whiteY; 734 735 if(y==100&&x<860&&x>=310){ //starting point toward right corner 736 carWhite=getImage(getClass().getResource("car/white1.JPG")); 737 x+=(int)(Math.random() * 15) + 10; 738 if(range<15000){range+=60;} 739 } 740 else if(x >= 860 && y < 390){ // top right turning toward bottom 741 x=860; 742 y += (int)(Math.random() * 9) + 3; 743 carWhite=getImage(getClass().getResource("car/white2.JPG")); 744 if(range<15000){range+=60;} 745 if(y>=380){x=830;y=420;} 746 } 747 else if(x>725&&y>=420){ // bottom right turing toward left 748 y=420; 749 x-=(int)(Math.random() * 9) + 3; 750 carWhite=getImage(getClass().getResource("car/white3.JPG")); 751 if(range<15000){range+=20;} 752 if(x<=725){x=725;y+=2;} // reach pit stop entrance 753 754 }else if(x<=725&&y<530){ // turning into pit stop area 755 x-=2; 756 y+=2; 757 carWhite=getImage(getClass().getResource("car/white3.JPG")); 758 if(y>=530){ 759 y=530; 760 } 761 }else if(y==530&&x>550){ // moving toward pit stop 762 x-=1; 763 y+=2; 764

18

AACS3123 Java Programming II Assignment 2012


765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 } if(x<=550){x=330;y=90; whiteEnd=true; carWhite=getImage(getClass().getResource("car/pitstop1.JPG")); pitstop=getImage(getClass().getResource("car/pitstop2.JPG")); } }else if(y>530&&x>550){ x-=1; y=530; // moving toward pit stop : car vibrating

if(x<=550){x=330;y=90; whiteEnd=true; carWhite=getImage(getClass().getResource("car/pitstop1.JPG")); pitstop=getImage(getClass().getResource("car/pitstop2.JPG")); } } whiteX=x;whiteY=y; repaint();try {Thread.sleep(50);}catch(Exception e){} double speed=((int)(Math.random() * range) + 5)/100; if(speed>tWhite){tWhite=speed;} }bWhite=Double.valueOf(twoDForm.format(0.000));forfeit=" (Forfeit)";white.stop(); } } public class CarTimer implements ActionListener{ public void actionPerformed(ActionEvent e){ if(!pause){ if((!redEnd))eRed = (System.currentTimeMillis() - startTime) / 1000.0 ; if((!cyanEnd))eCyan = (System.currentTimeMillis() - startTime) / 1000.0 ; if((!yellowEnd))eYellow = (System.currentTimeMillis() - startTime) / 1000.0 ; if((!blueEnd))eBlue = (System.currentTimeMillis() - startTime) / 1000.0 ; if((!greenEnd))eGreen = (System.currentTimeMillis() - startTime) / 1000.0 ; if((!whiteEnd))eWhite = (System.currentTimeMillis() - startTime) / 1000.0 ; } } }

C:\Users\user\Desktop\SJLIM+OWJ\src\AppletServer.java

1 import java.awt.*; 2 import java.awt.event.ActionEvent; 3 import java.awt.event.ActionListener; 4 import java.io.*; 5 import java.net.*; 6 import java.text.DecimalFormat; 7 import java.util.*; 8 import java.util.logging.Level; 9 import java.util.logging.Logger; 10 import javax.swing.*; 11

19

AACS3123 Java Programming II Assignment 2012


12 public class AppletServer extends JFrame{ 13 14 DecimalFormat twoDForm = new DecimalFormat("#.###"); 15 DataInputStream inputFromClient; 16 DataOutputStream outputToClient; 17 ServerSocket serverSocket; 18 19 Socket socket=null; 20 double temp; 21 double[] timeFromClient={0,1,2,3,4,50}; 22 String[] carFromClient={"Yellow Car","Red Car","Cyan Car","Blue Car","Green Car","White Car"}; 23 String[] carImgName={"red","cyan","yellow","blue","green","white"}; 24 String tempCar; 25 26 JTextArea jta = new JTextArea(); 27 JButton jbtClose=new JButton("Close"); 28 static int clientNo = 1; 29 30 public static void main(String[] args){ 31 new AppletServer(); 32 } 33 34 public AppletServer(){ 35 36 setTitle("F1 Racing Car Server"); 37 setSize(300,700); 38 setVisible(true); 39 setLocation(1065, 5); 40 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 41 setResizable(false); 42 setAlwaysOnTop(true); 43 44 setLayout(new BorderLayout()); 45 add(new JLabel("F1:Racing Car Server",JLabel.CENTER),BorderLayout.NORTH); 46 add(new JScrollPane(jta), BorderLayout.CENTER); 47 add(jbtClose,BorderLayout.SOUTH); 48 49 jta.setForeground(Color.blue); 50 jta.setEditable(false); 51 jta.setOpaque(false); 52 53 jbtClose.addActionListener(new ActionListener(){ 54 public void actionPerformed(ActionEvent e){ 55 closeServer(); 56 }}); 57 58 try { 59 serverSocket = new ServerSocket(8000); 60 jta.setForeground(Color.blue); 61 jta.append("Server : Started on "+new Date() + '\n'); 62 63 while(true){ 64 65 socket = serverSocket.accept(); 66 jta.setForeground(Color.blue); 67 jta.append("Server : Started on "+new Date() + '\n'); 68 69 System.out.println("Server Load : Waiting for Client"); 70

20

AACS3123 Java Programming II Assignment 2012


71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 jta.append("\nServer : Client Connected \n"); InetAddress inetAddress = socket.getInetAddress(); jta.append("Client "+clientNo+"'s host name is " + inetAddress.getHostName() +"\n"); jta.append("Client "+clientNo+"'s IP Address is " + inetAddress.getHostAddress()+"\n\n"); clientNo+=1; ServerClass thread = new ServerClass(socket); thread.start(); } } catch(IOException ex) { System.err.println(ex); } } class ServerClass extends Thread { private Socket socket; public ServerClass(Socket socket) { this.socket = socket; } public void run() { System.out.println("Client Found"); Boolean flag=true; try { inputFromClient = new DataInputStream(socket.getInputStream()); outputToClient = new DataOutputStream(socket.getOutputStream()); while(true){ jta.append(" Waiting info . . .\n"); flag=inputFromClient.readBoolean(); if(flag){ jta.setForeground(Color.BLUE); timeFromClient[0]=inputFromClient.readDouble(); carFromClient[0]=inputFromClient.readUTF(); timeFromClient[1]=inputFromClient.readDouble(); carFromClient[1]=inputFromClient.readUTF(); timeFromClient[2]=inputFromClient.readDouble(); carFromClient[2]=inputFromClient.readUTF(); timeFromClient[3]=inputFromClient.readDouble(); carFromClient[3]=inputFromClient.readUTF(); timeFromClient[4]=inputFromClient.readDouble(); carFromClient[4]=inputFromClient.readUTF(); timeFromClient[5]=inputFromClient.readDouble(); jta.append(" jta.append(" jta.append(" jta.append(" jta.append(" "+carFromClient[0]+" : "+ timeFromClient[0]+"\n"); "+carFromClient[1]+" : "+ timeFromClient[1]+"\n"); "+carFromClient[2]+" : "+ timeFromClient[2]+"\n"); "+carFromClient[3]+" : "+ timeFromClient[3]+"\n"); "+carFromClient[4]+" : "+ timeFromClient[4]+"\n");

21

AACS3123 Java Programming II Assignment 2012


131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 jta.append(" "+carFromClient[5]+" : "+ timeFromClient[5]+"\n\n");

for(int i=0;i<5;i++){ for(int j=i+1;j<5;j++){ if(timeFromClient[j]<timeFromClient[i]) { temp = timeFromClient[i]; timeFromClient[i]=timeFromClient[j]; timeFromClient[j]=temp; tempCar=carFromClient[i]; carFromClient[i]=carFromClient[j]; carFromClient[j]=tempCar; tempCar=carImgName[i]; carImgName[i]=carImgName[j]; carImgName[j]=tempCar; } else if(timeFromClient[j]==timeFromClient[i]){ Double.valueOf(twoDForm.format(timeFromClient[j]+=0.001)); } } } jta.append(" jta.append(" jta.append(" jta.append(" jta.append(" jta.append(" jta.append("

Applet : Sending info . . .\n"); "+carFromClient[0]+" : "+ timeFromClient[0]+"\n"); "+carFromClient[1]+" : "+ timeFromClient[1]+"\n"); "+carFromClient[2]+" : "+ timeFromClient[2]+"\n"); "+carFromClient[3]+" : "+ timeFromClient[3]+"\n"); "+carFromClient[4]+" : "+ timeFromClient[4]+"\n"); "+carFromClient[5]+" : "+ timeFromClient[5]+"\n\n");

for(int z=0;z<5;z++){ outputToClient.writeDouble(timeFromClient[z]); outputToClient.flush(); outputToClient.writeUTF(carFromClient[z]); outputToClient.flush(); outputToClient.writeUTF(carImgName[z]); outputToClient.flush(); } } else{ jta.setForeground(Color.MAGENTA); jta.append(" Result : Showing result info . . .\n"); for(int z=0;z<=5;z++){ outputToClient.writeUTF(carImgName[z]); outputToClient.flush(); outputToClient.writeDouble(timeFromClient[z]); outputToClient.flush(); jta.append(" "+carImgName[z]+" : "+ timeFromClient[z]+"\n"); }jta.append("\n"); } System.out.println("Server-Finish Arranging Client request"); } } catch (IOException ex) {System.err.println(ex);} } }

22

AACS3123 Java Programming II Assignment 2012


191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 } public void closeServer(){ try { jta.setForeground(Color.red); jta.setText("Server : Closed on "+ new Date() + '\n'); serverSocket.close(); System.out.println("Server Close"); }catch (IOException ex) { Logger.getLogger(AppletServer.class.getName()).log(Level.SEVERE, null, ex); } } public String[] getRank(){return carImgName;} public double[] getTime(){return timeFromClient;}

C:\Users\user\Desktop\SJLIM+OWJ\src\Result.java

1 /*Programmed By : SJLIM & WJOOI 2 Tutorial Group : Y2M41 */ 3 import java.applet.*; 4 import java.awt.*; 5 import java.io.*; 6 import java.net.Socket; 7 import java.util.logging.*; 8 import javax.swing.*; 9 10 public class Result extends JApplet implements Runnable { 11 12 AudioClip clip1; 13 Image bg,rank1,rank2,rank3,rank4,rank5,rank6,driver1,driver2,driver3; 14 double[] timeFromClient={12.332,13.221,13.421,14.667,14.852,12.312}; 15 String[] carImgName={"red","green","cyan","yellow","blue","white"}; 16 int[] x={280,265,250,250,265,280}; 17 Thread thread1; 18 19 Socket clientSocket; 20 DataInputStream inputFromServer; 21 DataOutputStream outputToServer; 22 23 public void update(Graphics g){paint(g);} 24 25 public void destroy(){clip1.stop();} 26 27 public void init(){ 28 29 clip1 = Applet.newAudioClip(getClass().getResource("audio/finalCountDown.wav")); 30 try { 31 clientSocket = new Socket(getCodeBase().getHost(), 8000); 32 inputFromServer = new DataInputStream(clientSocket.getInputStream()); 33 outputToServer = new DataOutputStream(clientSocket.getOutputStream()); 34 35 outputToServer.writeBoolean(false); 36 carImgName[0]=inputFromServer.readUTF(); 37 timeFromClient[0]=inputFromServer.readDouble(); 38 carImgName[1]=inputFromServer.readUTF(); 39 timeFromClient[1]=inputFromServer.readDouble();

23

AACS3123 Java Programming II Assignment 2012


40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 carImgName[2]=inputFromServer.readUTF(); timeFromClient[2]=inputFromServer.readDouble(); carImgName[3]=inputFromServer.readUTF(); timeFromClient[3]=inputFromServer.readDouble(); carImgName[4]=inputFromServer.readUTF(); timeFromClient[4]=inputFromServer.readDouble(); carImgName[5]=inputFromServer.readUTF(); timeFromClient[5]=inputFromServer.readDouble(); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Open Server First !","F1 RACING CAR GAME", JOptionPane.ERROR_MESSAGE,null); } bg=getImage(getClass().getResource("images/Result.JPG")); rank1=getImage(getClass().getResource("car/"+carImgName[0]+".PNG")); rank2=getImage(getClass().getResource("car/"+carImgName[1]+".PNG")); rank3=getImage(getClass().getResource("car/"+carImgName[2]+".PNG")); rank4=getImage(getClass().getResource("car/"+carImgName[3]+".PNG")); rank5=getImage(getClass().getResource("car/"+carImgName[4]+".PNG")); rank6=getImage(getClass().getResource("car/"+carImgName[5]+".PNG")); driver1=getImage(getClass().getResource("images/"+carImgName[0]+".PNG")); driver2=getImage(getClass().getResource("images/"+carImgName[1]+".PNG")); driver3=getImage(getClass().getResource("images/"+carImgName[2]+".PNG")); clip1.loop(); thread1=new Thread(this); thread1.start(); } public void run(){ while(true){ if(x[0]>150){x[0]--;if(x[0]<=150)x[0]=150;} if(x[1]>150){x[1]--;if(x[1]<=150)x[1]=150;} if(x[2]>150){x[2]--;if(x[2]<=150)x[2]=150;} if(x[3]>150){x[3]--;if(x[3]<=150)x[3]=150;} if(x[4]>150){x[4]--;if(x[4]<=150)x[4]=150;} if(x[5]>150){x[5]--;if(x[5]<=150)x[5]=150;} repaint(); try { Thread.sleep(30); } catch (InterruptedException ex) { Logger.getLogger(Result.class.getName()).log(Level.SEVERE, null, ex); } } } public void paint(Graphics g){ Image img=createImage(1018,572); Graphics g2=img.getGraphics(); g2.drawImage(bg,0,0,bg.getWidth(this),bg.getHeight(this),null); g2.drawImage(rank1,x[0],90,130,50,null); g2.drawImage(rank2,x[1],165,130,50,null);

24

AACS3123 Java Programming II Assignment 2012


100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 } 122 } g2.drawImage(rank3,x[2],240,130,50,null); g2.drawImage(rank4,x[3],320,130,50,null); g2.drawImage(rank5,x[4],390,130,50,null); g2.drawImage(rank6,x[5],462,130,50,null); Font font = new Font("Helvetica", Font.BOLD, 30); g2.setFont(font); g2.setColor(Color.WHITE); g2.drawString(Double.toString(timeFromClient[0])+" min",350,130); g2.drawString(Double.toString(timeFromClient[1])+" min",350,200); g2.drawString(Double.toString(timeFromClient[2])+" min",350,270); g2.drawString(Double.toString(timeFromClient[3])+" min",350,350); g2.drawString(Double.toString(timeFromClient[4])+" min",350,425); g2.drawString(Double.toString(timeFromClient[5])+" min",350,500); g2.drawImage(driver1,755,180,driver1.getWidth(this),driver1.getHeight(this),null); g2.drawImage(driver2,630,220,driver2.getWidth(this),driver2.getHeight(this),null); g2.drawImage(driver3,900,255,driver3.getWidth(this),driver3.getHeight(this),null); g.drawImage(img,0,0,null);

25

AACS3123 Java Programming II Assignment 2012


4.0 Personal Reflection By Lim Sau Jian
Strengths The solving of flickering problem Obviously, the developed applet does not have flickering problem (image flashing) which commonly occurred if we keep on repainting the screen. We have used buffered graphics to paint everything (updated car position) on one image before really show it to user. The functions of server The server developed have two main functions which are communicate with racing applet and communicate with result page. Server will carried out different operation base on the client behaviors. For example, server will arrange the car ranking when communicate with racing game applet while send the car name for image when communicate with result page. The use of multithreading We have create one thread for each car in order to make the program more independent. Each car will have its unique racing position which is different from others. Each car will be stop if the condition of 3 laps is reach. Weakness No result storing One of the great disadvantages is no result storing. Each record of the ranking will lost if a new game is start. We could have store the result in many ways such as use of database or text files but we are lack of time in doing this. Lack of modules We have only 5 modules which is the basic requirements in this assignment. If we are given more time and skill, we will develop some extra module such as racing mode, track selection, car selection, all time high score and etc. Lesson Learnt During conducting the development of this assignment, I have done a lot of self reading on the web as well references book. I face a lot of problems such as flickering problem, sending and getting result on server, putting JPanel background, the JAVA policy permission for applet networking on the web and so on. I have learnt a lot of new programming technique and improved my both technical and soft skill as well. I believe that my group could develop a more attracting, interesting and quality applet if we are given longer period in producing this assignment. Here by, I would like to present my thankfulness to my lecturer and tutor, Mr Nikalus Swee for delivering the necessary programming skill and experiences that needed in this assignment.

26

AACS3123 Java Programming II Assignment 2012


5.0 Personal Reflection By Ooi Wen Jie
Strengths Random Winner The 6 cars are running among themselves on a random speed on the track that designed. Each time the race is conducted, the winner will be different. Supported by Multimedia In this Car racing assignment, lots of multimedia is used to design its interface and websites, lots of pictures, sound tracks, videos is used to better explain the assignments background, racers background, tracks background and cars background. By using the multimedia, its make this assignment looks more attracting and more real. Shared Timer Each car that runs on the track will share a same timer. After each of the cars ends their laps, the result will then send to the server to calculate who the winner is. By sharing a timer, the result will be more accurate rather than creating one timer for each car. Weaknesses Car / Driver selection We do not have car and driver selection in this assignment. User cannot choose which car to be the winner or control the car that they wish to. The car will be running on a random speed. No Result Storing The biggest disadvantage of the assignment is that all the racing result will not be store either in a database or in spreadsheet. Every time user reloads the program, the result will be start all over again Lesson Learnt Assignment need a lot of extra knowledge others than those knowledge teaches during the lecture season. Self-exploring on the nets is the biggest advantages to solve the problem faced during development of the assignment and enhance the quality of the assignment. Knowledge that has been learnt from pervious semester is also important in design the assignment for example Web Development Knowledge. The most important is communication and teamwork between my teammate. Support and ideas from the discussion between teammates is also the biggest inspire to the assignment.

27

AACS3123 Java Programming II Assignment 2012


6.0 Skill Developed
Time Management Skill We have learnt how to manage our time properly which is the main factor we can complete this assignment under the time given. Leadership Skill We have improved our leadership skill which each of us takes turn to assign job to group member since this assignment are divided in two main parts and numbers of module. We managed to give instruction to allocate which module to be complete by which member and they need to prepare what documentation needed on time. Communication Skill We have carried out meetings and discussion to solve problems found. We are able to communicate very well even though there were conflict in ideas and suggestion of doing this system. We able to provide suggestion, advises and carry out discussion to solve problem we have faced. Technical Skill We have learnt how to manage this project by dividing it into part such as designing and programming, so that each of us can be work on assigned task at the same time which all of the tasks will be combined once its completed. This has accumulated our experience in managing assignment since us first step into college. Besides, we have carried out a lot of reading on external sources in order to improve out JAVA2 programming skill needed in this assignment.

28

AACS3123 Java Programming II Assignment 2012


7.0 Soft Copy

29

Você também pode gostar