Advertisement
Crenox

PONG IN JAVA (CLASS/HOME)

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