Advertisement
hunkyhari

SO23571375-JalPan.java

May 9th, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.94 KB | None | 0 0
  1. /**
  2.  *
  3.  */
  4. package com.shreesoft.so;
  5.  
  6. /**
  7.  * @author srihari
  8.  *
  9.  */
  10. import java.awt.Color;
  11. import java.awt.Graphics;
  12. import java.awt.Graphics2D;
  13. import java.awt.RenderingHints;
  14. import java.awt.event.KeyEvent;
  15. import java.awt.event.KeyListener;
  16. import javax.swing.JFrame;
  17. import javax.swing.JOptionPane;
  18. import javax.swing.JPanel;
  19.  
  20. public class JalPan extends JPanel {
  21.     /**
  22.      *
  23.      */
  24.     private static final long serialVersionUID = -1653358556165127083L;
  25.     int x = 0;
  26.     int y = 0;
  27.     Ball ball = new Ball(this);
  28.     Plate plate = new Plate(this);
  29.  
  30.     void move() {// move
  31.         ball.move();
  32.         plate.move();
  33.     }
  34.  
  35.     JalPan() {
  36.         // constructor
  37.         KeyListener k = new KeyListener() {
  38.  
  39.             @Override
  40.             public void keyPressed(KeyEvent e) {
  41.                 plate.keyPressed(e);
  42.             }
  43.  
  44.             public void keyReleased(KeyEvent e) {
  45.                 // TODO Auto-generated method stub
  46.                 plate.keyReleased(e);
  47.             }
  48.  
  49.             @Override
  50.             public void keyTyped(KeyEvent e) {
  51.                 // TODO Auto-generated method stub
  52.  
  53.             }
  54.  
  55.         };
  56.         addKeyListener(k);
  57.         setFocusable(true);
  58.     }
  59.  
  60.     public void paint(Graphics g) {
  61.         super.paint(g);// pehle screen saaf karo pehle jaisi
  62.         setBackground(Color.black);
  63.         Graphics2D g2d = (Graphics2D) g;
  64.         g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  65.         ball.paint(g2d);
  66.         plate.paint(g2d);
  67.         // super.paint(g);//agar yaha to puri screen pehle jaisi saaf ho jaegi
  68.     }
  69.  
  70.     public void gameOver() {
  71.         JOptionPane.showMessageDialog(this, "GameOver", "GameOver", JOptionPane.YES_NO_OPTION);
  72.         System.exit(ABORT);
  73.     }
  74.  
  75.     public static void main(String args[]) throws InterruptedException {// main
  76.  
  77.         JalPan jp = new JalPan();
  78.         JFrame frame = new JFrame("Chota Bheem");
  79.         frame.add(jp);
  80.         frame.setBackground(Color.BLACK);
  81.         frame.setSize(500, 500);
  82.         frame.setVisible(true);
  83.         frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
  84.  
  85.         while (true) {
  86.             jp.move();
  87.             jp.repaint();
  88.             Thread.sleep(2);
  89.         }
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement