Source code: com/adorphuye/othello/Init.java
1 package com.adorphuye.othello;
2
3 import java.applet.*;
4 import java.awt.*;
5 import java.awt.event.*;
6 import java.io.*;
7 import java.util.zip.*;
8 import java.net.*;
9 import com.adorphuye.othello.gui.GIFImageProvider;
10
11 public class Init extends Applet
12 {
13 private Othello othello = null;
14 private static Image whiteImg = null;
15 private static Image blackImg = null;
16 private static Image boardImg = null;
17
18 public void init()
19 {
20 super.init();
21 if(othello==null)
22 {
23 MediaTracker tracker = new MediaTracker(this);
24 try
25 {
26 GIFImageProvider gip = GIFImageProvider.getInstance();
27 gip.setSource(GIFImageProvider.APPLET);
28
29 URL white, black,board;
30 white = new URL(getCodeBase().toString()+"images/white.gif");
31 black = new URL(getCodeBase().toString()+"images/black.gif");
32 board = new URL(getCodeBase().toString()+"images/board.gif");
33 whiteImg = gip.getImage(white);
34 blackImg = gip.getImage(black);
35 boardImg = gip.getImage(board);
36 tracker.addImage((Image)whiteImg, 0);
37 tracker.addImage((Image)blackImg, 0);
38 tracker.addImage((Image)boardImg, 0);
39
40 for(int i=0;i<com.adorphuye.othello.gui.Board.imgs.length;i++)
41 {
42 java.net.URL url = new URL(getCodeBase().toString()+"images/white2black_00"+lz(i+1)+".gif");
43
44 com.adorphuye.othello.gui.Board.imgs[i] = gip.getImage(url);
45 tracker.addImage(com.adorphuye.othello.gui.Board.imgs[i],0);
46 }
47
48 tracker.waitForAll();
49 }
50 catch(Exception e)
51 {
52 e.printStackTrace();
53 }
54
55 setLayout(new FlowLayout());
56 othello = new Othello(whiteImg, blackImg, boardImg);
57 add(othello);
58 doLayout();
59 }
60 }
61
62 /**
63 * @param i
64 * @return */
65 private String lz(int i)
66 {
67 String s = String.valueOf(i);
68 if(i<10)
69 s = "0"+s;
70 return s;
71 }
72
73 public void start()
74 {
75 super.start();
76 othello.begin();
77 }
78 }