Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- */
- package com.shreesoft.so;
- /**
- * @author srihari
- *
- */
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.RenderingHints;
- import java.awt.event.KeyEvent;
- import java.awt.event.KeyListener;
- import javax.swing.JFrame;
- import javax.swing.JOptionPane;
- import javax.swing.JPanel;
- public class JalPan extends JPanel {
- /**
- *
- */
- private static final long serialVersionUID = -1653358556165127083L;
- int x = 0;
- int y = 0;
- Ball ball = new Ball(this);
- Plate plate = new Plate(this);
- void move() {// move
- ball.move();
- plate.move();
- }
- JalPan() {
- // constructor
- KeyListener k = new KeyListener() {
- @Override
- public void keyPressed(KeyEvent e) {
- plate.keyPressed(e);
- }
- public void keyReleased(KeyEvent e) {
- // TODO Auto-generated method stub
- plate.keyReleased(e);
- }
- @Override
- public void keyTyped(KeyEvent e) {
- // TODO Auto-generated method stub
- }
- };
- addKeyListener(k);
- setFocusable(true);
- }
- public void paint(Graphics g) {
- super.paint(g);// pehle screen saaf karo pehle jaisi
- setBackground(Color.black);
- Graphics2D g2d = (Graphics2D) g;
- g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
- ball.paint(g2d);
- plate.paint(g2d);
- // super.paint(g);//agar yaha to puri screen pehle jaisi saaf ho jaegi
- }
- public void gameOver() {
- JOptionPane.showMessageDialog(this, "GameOver", "GameOver", JOptionPane.YES_NO_OPTION);
- System.exit(ABORT);
- }
- public static void main(String args[]) throws InterruptedException {// main
- JalPan jp = new JalPan();
- JFrame frame = new JFrame("Chota Bheem");
- frame.add(jp);
- frame.setBackground(Color.BLACK);
- frame.setSize(500, 500);
- frame.setVisible(true);
- frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
- while (true) {
- jp.move();
- jp.repaint();
- Thread.sleep(2);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement