Crenox

Pong in Java (HOME)

May 27th, 2014
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. package com.samkough.pong.main;
  2.  
  3. import javax.swing.JFrame;
  4. import java.awt.Color;
  5. import java.awt.Graphics;
  6. import com.samkough.pong.entity.Ball;
  7. import com.samkough.pong.entity.Paddle;
  8.  
  9. public class Pong extends JFrame
  10. {
  11. private static final int WIDTH = 400;
  12. private static final int HEIGHT = 400;
  13.  
  14. Ball b = new Ball();
  15. Paddle p1 = new Paddle();
  16. Paddle p2 = new Paddle();
  17.  
  18. protected int x;
  19. protected int y;
  20.  
  21.  
  22. public Pong()
  23. {
  24. b.setSize(30, 30);
  25. b.setColor(Color.BLUE);
  26. b.setX(20);
  27. b.setY(20);
  28.  
  29. p1.setSize(40, 40);
  30. p1.setColor(Color.RED);
  31. p1.setX(50);
  32. p1.setY(50);
  33.  
  34. p2.setSize(40, 40);
  35. p2.setColor(Color.RED);
  36. p2.setX(100);
  37. p2.setY(100);
  38.  
  39. add(b);
  40. add(p1);
  41. add(p2);
  42. getContentPane().repaint();
  43. }
  44.  
  45.  
  46. public void paint(Graphics g)
  47. {
  48.  
  49. }
  50.  
  51. public void setColor(Color c)
  52. {
  53.  
  54. }
  55.  
  56. public boolean collides(boolean a)
  57. {
  58. return a;
  59. }
  60.  
  61. public void setSize(int width, int height)
  62. {
  63.  
  64. }
  65.  
  66. public void setX(int xn)
  67. {
  68. x = xn;
  69. }
  70.  
  71. public void setY(int yn)
  72. {
  73. y = yn;
  74. }
  75.  
  76. public int getX()
  77. {
  78. return x;
  79. }
  80.  
  81. public int getY()
  82. {
  83. return y;
  84. }
  85.  
  86.  
  87. public static void main(String args[])
  88. {
  89. Pong frame = new Pong();
  90. frame.setSize(WIDTH, HEIGHT);
  91. frame.setTitle("Pong");
  92. frame.setResizable(false);
  93. frame.setVisible(true);
  94. frame.setLocationRelativeTo(null);
  95. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  96. }
  97. }
  98. -----------------------------------------------------------------------------------------------------------------------------------
  99. package com.samkough.pong.entity;
  100.  
  101. import java.awt.Color;
  102. import java.awt.Graphics;
  103. import java.awt.event.*;
  104.  
  105. import com.samkough.pong.main.Pong;
  106.  
  107. public class Paddle extends Pong implements KeyListener
  108. {
  109. public Paddle()
  110. {
  111. /*
  112. p1.setColor(Color.RED);
  113. p1.setX(50);
  114. p1.setY(50);
  115.  
  116. p2.setSize(40, 40);
  117. p2.setColor(Color.RED);
  118. p2.setX(100);
  119. p2.setY(100);
  120. */
  121. }
  122.  
  123. public void paint(Graphics g)
  124. {
  125.  
  126. }
  127.  
  128. public void setColor(Color c)
  129. {
  130.  
  131. }
  132.  
  133. public void setSize(int width, int height)
  134. {
  135.  
  136. }
  137.  
  138. public void setX(int i)
  139. {
  140. x = i;
  141. }
  142.  
  143. public void setY(int i)
  144. {
  145. y = i;
  146. }
  147.  
  148. public int getX()
  149. {
  150. return x;
  151. }
  152.  
  153. public int getY()
  154. {
  155. return y;
  156. }
  157.  
  158. public void keyPressed(KeyEvent e)
  159. {
  160.  
  161. }
  162.  
  163. public void keyReleased(KeyEvent e)
  164. {
  165.  
  166. }
  167.  
  168. public void keyTyped(KeyEvent e)
  169. {
  170.  
  171. }
  172.  
  173. }
  174.  
  175. -----------------------------------------------------------------------------------------------------------------------------------
  176. package com.samkough.pong.entity;
  177.  
  178. import java.awt.Color;
  179. import java.awt.Graphics;
  180.  
  181. import com.samkough.pong.main.Pong;
  182.  
  183. public class Ball extends Pong
  184. {
  185. public Ball()
  186. {
  187. /*
  188. b.setSize(30, 30);
  189. b.setColor(Color.BLUE);
  190. b.setX(20);
  191. b.setY(20);
  192. */
  193. }
  194.  
  195. public void paint(Graphics g)
  196. {
  197.  
  198. }
  199.  
  200. public void setColor(Color c)
  201. {
  202.  
  203. }
  204.  
  205. public void setSize(int width, int height)
  206. {
  207.  
  208. }
  209.  
  210. public void setX(int i)
  211. {
  212. x = i;
  213. }
  214.  
  215. public void setY(int i)
  216. {
  217. y = i;
  218. }
  219.  
  220. public int getX()
  221. {
  222. return x;
  223. }
  224.  
  225. public int getY()
  226. {
  227. return y;
  228. }
  229. }
Advertisement
Add Comment
Please, Sign In to add comment