Professional Documents
Culture Documents
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.
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.
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.
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.
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
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;
10
11
} 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
13
14
15
16
17
18
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
20
21
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
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
24
25
26
27
28
29