Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JFrame;
- import java.awt.Color;
- import java.awt.Graphics;
- public class Pong extends JFrame
- {
- private static final int WIDTH = 400;
- private static final int HEIGHT = 400;
- Ball b = new Ball();
- Paddle p1 = new Paddle();
- Paddle p2 = new Paddle();
- protected int x;
- protected int y;
- public Pong()
- {
- b.setSize(30, 30);
- b.setColor(Color.BLUE);
- b.setX(20);
- b.setY(20);
- p1.setSize(40, 40);
- p1.setColor(Color.RED);
- p1.setX(50);
- p1.setY(50);
- p2.setSize(40, 40);
- p2.setColor(Color.RED);
- p2.setX(100);
- p2.setY(100);
- add(b);
- add(p1);
- add(p2);
- getContentPane().repaint();
- }
- public void paint(Graphics g)
- {
- }
- public void setColor(Color c)
- {
- }
- public boolean collides(boolean a)
- {
- return a;
- }
- public void setSize(int width, int height)
- {
- }
- /*public void setX(int i)
- {
- x = i;
- }
- public void setY(int i)
- {
- y = i;
- }
- public int getX()
- {
- return x;
- }
- public int getY()
- {
- return y;
- }*/
- public static void main(String args[])
- {
- Pong frame = new Pong();
- frame.setSize(WIDTH, HEIGHT);
- frame.setTitle("Pong");
- frame.setResizable(false);
- frame.setVisible(true);
- frame.setLocationRelativeTo(null);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
- }
- -------------------------------------------------------------------------------------------------------------------------------------
- import java.awt.Color;
- import java.awt.Graphics;
- public class Ball extends Pong
- {
- public Ball()
- {
- /*
- b.setSize(30, 30);
- b.setColor(Color.BLUE);
- b.setX(20);
- b.setY(20);
- */
- }
- public void paint(Graphics g)
- {
- }
- public void setColor(Color c)
- {
- }
- public void setSize(int width, int height)
- {
- }
- public void setX(int i)
- {
- x = i;
- }
- public void setY(int i)
- {
- y = i;
- }
- public int getX()
- {
- return x;
- }
- public int getY()
- {
- return y;
- }
- }
- -------------------------------------------------------------------------------------------------------------------------------------
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.event.*;
- public class Paddle extends Pong implements KeyListener
- {
- public Paddle()
- {
- /*
- p1.setColor(Color.RED);
- p1.setX(50);
- p1.setY(50);
- p2.setSize(40, 40);
- p2.setColor(Color.RED);
- p2.setX(100);
- p2.setY(100);
- */
- }
- public void paint(Graphics g)
- {
- }
- public void setColor(Color c)
- {
- }
- public void setSize(int width, int height)
- {
- }
- public void setX(int i)
- {
- x = i;
- }
- public void setY(int i)
- {
- y = i;
- }
- public int getX()
- {
- return x;
- }
- public int getY()
- {
- return y;
- }
- public void keyPressed(KeyEvent e)
- {
- }
- public void keyReleased(KeyEvent e)
- {
- }
- public void keyTyped(KeyEvent e)
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement