Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/adorphuye/othello/Main.java


1   package com.adorphuye.othello;
2   
3   import java.awt.*;
4   import java.awt.event.*;
5   import java.io.*;
6   import java.net.*;
7   import com.adorphuye.othello.gui.GIFImageProvider;
8   
9   public class Main extends Frame
10  {
11    public Main()
12    {
13      setTitle("Java Othello");
14      addWindowListener(new WindowAdapter()
15      {
16        public void windowClosing(WindowEvent evt)
17        {
18          System.exit(0);
19        }
20      });
21  
22      Object whiteImg = null;
23      Object blackImg = null;
24      Object boardImg = null;    
25      
26      MediaTracker tracker = new MediaTracker(this);
27  
28      if(whiteImg==null || blackImg==null)
29      {
30        try
31        {
32          GIFImageProvider gip = GIFImageProvider.getInstance();
33          gip.setSource(GIFImageProvider.APPLICATION);
34  
35          URL url = getClass().getResource("images/white.gif");
36          whiteImg = gip.getImage(url);
37          
38          url = getClass().getResource("images/black.gif");
39          blackImg = gip.getImage(url);
40          
41          url = getClass().getResource("images/board.gif");
42          boardImg = gip.getImage(url);
43  
44          tracker.addImage((Image)whiteImg, 0);
45          tracker.addImage((Image)blackImg, 0);
46          tracker.addImage((Image)boardImg, 0);
47  
48          for(int i=0;i<com.adorphuye.othello.gui.Board.imgs.length;i++)
49          {
50            url = getClass().getResource("images/white2black_00"+lz(i+1)+".gif");
51            
52            com.adorphuye.othello.gui.Board.imgs[i] = gip.getImage(url);
53            tracker.addImage(com.adorphuye.othello.gui.Board.imgs[i],0);
54          }
55          
56          tracker.waitForAll();
57        }
58        catch(Exception e)
59        {
60          e.printStackTrace();
61        }
62      }
63  
64      if(whiteImg==null || blackImg==null)
65      {
66        whiteImg = Color.white;
67        blackImg = Color.black;
68        
69      }
70      Othello othello = new Othello(whiteImg, blackImg, boardImg);
71      add(othello, BorderLayout.CENTER);
72      
73      setSize(238,282);
74      setVisible(true);
75      othello.begin();
76    }
77  
78    /**
79     * @param i
80     * @return  */  
81    private String lz(int i)
82    {
83      String s = String.valueOf(i);
84      if(i<10)
85        s = "0"+s;
86      return s;
87    }
88    
89    
90    /**
91     * @param args  */  
92    public static void main(String[] args)
93    {
94      new Main();
95    }
96  }