Advertisement
Guest User

Untitled

a guest
Feb 25th, 2013
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.26 KB | None | 0 0
  1. import java.io.* ;
  2. import java.awt.* ;
  3. import java.util.* ;
  4. import java.applet.* ;
  5. import javax.swing.* ;
  6. import java.awt.event.* ;
  7. import javax.swing.event.* ;
  8. import java.awt.Component;
  9. import javax.swing.BoxLayout;
  10. import javax.swing.JButton;
  11. import javax.swing.JFrame;
  12. import javax.swing.WindowConstants;
  13. import javax.swing.BorderFactory;
  14. import java.awt.Dimension;
  15.  
  16. class OnePlayerGame extends JFrame implements ActionListener {
  17.  
  18. Container contentPane = getContentPane() ;
  19.  
  20. JPanel OnePlayerPnl = new JPanel( ) ;
  21. JPanel centerGrid = new JPanel (new GridLayout (4,4,-100,-190));
  22.  
  23. ImageIcon whiteSquarePic = new ImageIcon( "white_Square.png" ) ; // Locate the menu image and assign it to a variable
  24. ImageIcon redSquarePic = new ImageIcon ( "red_Square.png" ) ;
  25. ImageIcon blueSquarePic = new ImageIcon( "blue_Square.png" ) ;
  26. ImageIcon blackCirclePic = new ImageIcon( "black_circle.png" ) ;
  27.  
  28. JButton whiteSquare0 = new JButton( whiteSquarePic ) ;
  29. JButton whiteSquare1 = new JButton( whiteSquarePic ) ;
  30. JButton whiteSquare2 = new JButton( whiteSquarePic ) ;
  31. JButton whiteSquare3 = new JButton( whiteSquarePic ) ;
  32. JButton whiteSquare4 = new JButton( whiteSquarePic ) ;
  33. JButton whiteSquare5 = new JButton( whiteSquarePic ) ;
  34. JButton whiteSquare6 = new JButton( whiteSquarePic ) ;
  35. JButton whiteSquare7 = new JButton( whiteSquarePic ) ;
  36. JButton whiteSquare8 = new JButton( whiteSquarePic ) ;
  37. JButton whiteSquare9 = new JButton( whiteSquarePic ) ;
  38. JButton whiteSquare10 = new JButton( whiteSquarePic ) ;
  39. JButton whiteSquare11 = new JButton( whiteSquarePic ) ;
  40. JButton whiteSquare12 = new JButton( whiteSquarePic ) ;
  41. JButton whiteSquare13 = new JButton( whiteSquarePic ) ;
  42. JButton whiteSquare14 = new JButton( whiteSquarePic ) ;
  43. JButton whiteSquare15 = new JButton( whiteSquarePic ) ;
  44.  
  45. JLabel redSquare = new JLabel( redSquarePic ) ;
  46. JLabel blueSquare = new JLabel( blueSquarePic ) ;
  47. JLabel blackCircle = new JLabel( blackCirclePic ) ;
  48.  
  49. int gridArray[][] =
  50. {
  51. {0, 3},
  52. {1, 2},
  53. {2, 2},
  54. {3, 3},
  55. {4, 2},
  56. {5, 1},
  57. {6, 1},
  58. {7, 2},
  59. {8, 2},
  60. {9, 1},
  61. {10, 1},
  62. {11, 2},
  63. {12, 3},
  64. {13, 2},
  65. {14, 2},
  66. {15, 3},
  67. };
  68.  
  69. boolean PlayerOneTurn = true ;
  70.  
  71.  
  72.  
  73. public OnePlayerGame()
  74. {
  75. super ( "OnePlayerGame" ) ;
  76.  
  77. setSize( 500, 600 ) ;
  78. setResizable( false );
  79.  
  80. setDefaultCloseOperation( EXIT_ON_CLOSE ) ;
  81.  
  82. add( OnePlayerPnl ) ;
  83.  
  84. centerGrid.add ( whiteSquare0 );
  85. centerGrid.add ( whiteSquare1 );
  86. centerGrid.add ( whiteSquare2 );
  87. centerGrid.add ( whiteSquare3 );
  88. centerGrid.add ( whiteSquare4 );
  89. centerGrid.add ( whiteSquare5 );
  90. centerGrid.add ( whiteSquare6 );
  91. centerGrid.add ( whiteSquare7 );
  92. centerGrid.add ( whiteSquare8 );
  93. centerGrid.add ( whiteSquare9 );
  94. centerGrid.add ( whiteSquare10 );
  95. centerGrid.add ( whiteSquare11 );
  96. centerGrid.add ( whiteSquare12 );
  97. centerGrid.add ( whiteSquare13 );
  98. centerGrid.add ( whiteSquare14 );
  99. centerGrid.add ( whiteSquare15 );
  100.  
  101. // whiteSquare0.setBackground(null);
  102. // whiteSquare0.setBorder(null);
  103. // whiteSquare0.setBorderPainted(false);
  104. // whiteSquare0.setContentAreaFilled(false);
  105. // whiteSquare0.setOpaque(true);
  106. // whiteSquare0.setFocusPainted(false);
  107. // whiteSquare0.setBackground(BackgroundFactory.createEmptyBackground());
  108. whiteSquare0.setSize (size.width, size.height);
  109.  
  110. whiteSquare1.setBackground(null);
  111. whiteSquare1.setBorder(null);
  112. whiteSquare1.setBorderPainted(false);
  113. whiteSquare1.setContentAreaFilled(false);
  114.  
  115. whiteSquare2.setBackground(null);
  116. whiteSquare2.setBorder(null);
  117. whiteSquare2.setBorderPainted(false);
  118. whiteSquare2.setContentAreaFilled(false);
  119.  
  120. whiteSquare3.setBackground(null);
  121. whiteSquare3.setBorder(null);
  122. whiteSquare3.setBorderPainted(false);
  123. whiteSquare3.setContentAreaFilled(false);
  124.  
  125. whiteSquare4.setBackground(null);
  126. whiteSquare4.setBorder(null);
  127. whiteSquare4.setBorderPainted(false);
  128. whiteSquare4.setContentAreaFilled(false);
  129.  
  130. whiteSquare5.setBackground(null);
  131. whiteSquare5.setBorder(null);
  132. whiteSquare5.setBorderPainted(false);
  133. whiteSquare5.setContentAreaFilled(false);
  134.  
  135. whiteSquare6.setBackground(null);
  136. whiteSquare6.setBorder(null);
  137. whiteSquare6.setBorderPainted(false);
  138. whiteSquare6.setContentAreaFilled(false);
  139.  
  140. whiteSquare7.setBackground(null);
  141. whiteSquare7.setBorder(null);
  142. whiteSquare7.setBorderPainted(false);
  143. whiteSquare7.setContentAreaFilled(false);
  144.  
  145. whiteSquare8.setBackground(null);
  146. whiteSquare8.setBorder(null);
  147. whiteSquare8.setBorderPainted(false);
  148. whiteSquare8.setContentAreaFilled(false);
  149.  
  150. whiteSquare9.setBackground(null);
  151. whiteSquare9.setBorder(null);
  152. whiteSquare9.setBorderPainted(false);
  153. whiteSquare9.setContentAreaFilled(false);
  154.  
  155. whiteSquare10.setBackground(null);
  156. whiteSquare10.setBorder(null);
  157. whiteSquare10.setBorderPainted(false);
  158. whiteSquare10.setContentAreaFilled(false);
  159.  
  160. whiteSquare11.setBackground(null);
  161. whiteSquare11.setBorder(null);
  162. whiteSquare11.setBorderPainted(false);
  163. whiteSquare11.setContentAreaFilled(false);
  164.  
  165. whiteSquare12.setBackground(null);
  166. whiteSquare12.setBorder(null);
  167. whiteSquare12.setBorderPainted(false);
  168. whiteSquare12.setContentAreaFilled(false);
  169.  
  170. whiteSquare13.setBackground(null);
  171. whiteSquare13.setBorder(null);
  172. whiteSquare13.setBorderPainted(false);
  173. whiteSquare13.setContentAreaFilled(false);
  174.  
  175. whiteSquare14.setBackground(null);
  176. whiteSquare14.setBorder(null);
  177. whiteSquare14.setBorderPainted(false);
  178. whiteSquare14.setContentAreaFilled(false);
  179.  
  180. whiteSquare15.setBackground(null);
  181. whiteSquare15.setBorder(null);
  182. whiteSquare15.setBorderPainted(false);
  183. whiteSquare15.setContentAreaFilled(false);
  184.  
  185. contentPane.add("Center", centerGrid );
  186.  
  187. whiteSquare0.addActionListener ( this );
  188. whiteSquare1.addActionListener ( this );
  189. whiteSquare2.addActionListener ( this );
  190. whiteSquare3.addActionListener ( this );
  191. whiteSquare4.addActionListener ( this );
  192. whiteSquare5.addActionListener ( this );
  193. whiteSquare6.addActionListener ( this );
  194. whiteSquare7.addActionListener ( this );
  195. whiteSquare8.addActionListener ( this );
  196. whiteSquare9.addActionListener ( this );
  197. whiteSquare10.addActionListener ( this );
  198. whiteSquare11.addActionListener ( this );
  199. whiteSquare12.addActionListener ( this );
  200. whiteSquare13.addActionListener ( this );
  201. whiteSquare14.addActionListener ( this );
  202. whiteSquare15.addActionListener ( this );
  203.  
  204. setVisible( true ) ;
  205. }
  206.  
  207. public void actionPerformed ( ActionEvent event )
  208. {
  209. if ( event.getSource() == whiteSquare0 )
  210. {
  211.  
  212. if ( PlayerOneTurn == true ) whiteSquare0.setIcon( redSquarePic );
  213.  
  214. if ( PlayerOneTurn == false ) whiteSquare0.setIcon( blueSquarePic ) ;
  215.  
  216. }
  217. if ( event.getSource() == whiteSquare1 )
  218. {
  219.  
  220. if ( PlayerOneTurn == true ) whiteSquare1.setIcon( redSquarePic );
  221.  
  222. if ( PlayerOneTurn == false ) whiteSquare1.setIcon( blueSquarePic ) ;
  223.  
  224. }
  225. if ( event.getSource() == whiteSquare2 )
  226. {
  227.  
  228. if ( PlayerOneTurn == true ) whiteSquare2.setIcon( redSquarePic );
  229.  
  230. if ( PlayerOneTurn == false ) whiteSquare2.setIcon( blueSquarePic ) ;
  231.  
  232. }
  233. if ( event.getSource() == whiteSquare3 )
  234. {
  235.  
  236. if ( PlayerOneTurn == true ) whiteSquare3.setIcon( redSquarePic );
  237.  
  238. if ( PlayerOneTurn == false ) whiteSquare3.setIcon( blueSquarePic ) ;
  239.  
  240. }
  241. if ( event.getSource() == whiteSquare4 )
  242. {
  243.  
  244. if ( PlayerOneTurn == true ) whiteSquare4.setIcon( redSquarePic );
  245.  
  246. if ( PlayerOneTurn == false ) whiteSquare4.setIcon( blueSquarePic ) ;
  247.  
  248. }
  249. if ( event.getSource() == whiteSquare5 )
  250. {
  251.  
  252. if ( PlayerOneTurn == true ) whiteSquare5.setIcon( redSquarePic );
  253.  
  254. if ( PlayerOneTurn == false ) whiteSquare5.setIcon( blueSquarePic ) ;
  255.  
  256. }
  257. if ( event.getSource() == whiteSquare6 )
  258. {
  259.  
  260. if ( PlayerOneTurn == true ) whiteSquare6.setIcon( redSquarePic );
  261.  
  262. if ( PlayerOneTurn == false ) whiteSquare6.setIcon( blueSquarePic ) ;
  263.  
  264. }
  265. if ( event.getSource() == whiteSquare7 )
  266. {
  267.  
  268. if ( PlayerOneTurn == true ) whiteSquare7.setIcon( redSquarePic );
  269.  
  270. if ( PlayerOneTurn == false ) whiteSquare7.setIcon( blueSquarePic ) ;
  271.  
  272. }
  273. if ( event.getSource() == whiteSquare8 )
  274. {
  275.  
  276. if ( PlayerOneTurn == true ) whiteSquare8.setIcon( redSquarePic );
  277.  
  278. if ( PlayerOneTurn == false ) whiteSquare8.setIcon( blueSquarePic ) ;
  279.  
  280. }
  281. if ( event.getSource() == whiteSquare8 )
  282. {
  283.  
  284. if ( PlayerOneTurn == true ) whiteSquare9.setIcon( redSquarePic );
  285.  
  286. if ( PlayerOneTurn == false ) whiteSquare9.setIcon( blueSquarePic ) ;
  287.  
  288. }
  289. if ( event.getSource() == whiteSquare10 )
  290. {
  291.  
  292. if ( PlayerOneTurn == true ) whiteSquare10.setIcon( redSquarePic );
  293.  
  294. if ( PlayerOneTurn == false ) whiteSquare10.setIcon( blueSquarePic ) ;
  295.  
  296. }
  297. if ( event.getSource() == whiteSquare11 )
  298. {
  299.  
  300. if ( PlayerOneTurn == true ) whiteSquare11.setIcon( redSquarePic );
  301.  
  302. if ( PlayerOneTurn == false ) whiteSquare11.setIcon( blueSquarePic ) ;
  303.  
  304. }
  305. if ( event.getSource() == whiteSquare12 )
  306. {
  307.  
  308. if ( PlayerOneTurn == true ) whiteSquare12.setIcon( redSquarePic );
  309.  
  310. if ( PlayerOneTurn == false ) whiteSquare12.setIcon( blueSquarePic ) ;
  311.  
  312. }
  313. if ( event.getSource() == whiteSquare13 )
  314. {
  315.  
  316. if ( PlayerOneTurn == true ) whiteSquare13.setIcon( redSquarePic );
  317.  
  318. if ( PlayerOneTurn == false ) whiteSquare13.setIcon( blueSquarePic ) ;
  319.  
  320. }
  321. if ( event.getSource() == whiteSquare14 )
  322. {
  323.  
  324. if ( PlayerOneTurn == true ) whiteSquare14.setIcon( redSquarePic );
  325.  
  326. if ( PlayerOneTurn == false ) whiteSquare14.setIcon( blueSquarePic ) ;
  327.  
  328. }
  329. if ( event.getSource() == whiteSquare15 )
  330. {
  331.  
  332. if ( PlayerOneTurn == true ) whiteSquare15.setIcon( redSquarePic );
  333.  
  334. if ( PlayerOneTurn == false ) whiteSquare15.setIcon( blueSquarePic ) ;
  335.  
  336. }
  337.  
  338. }
  339. public static void main (String[] args)
  340.  
  341. {
  342. OnePlayerGame gui = new OnePlayerGame() ;
  343. }
  344. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement