Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.KeyEvent;
- import java.awt.event.KeyListener;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.Timer;
- public class Pacman extends JPanel implements KeyListener,ActionListener {
- static Color colorArray[]={Color.white};
- static JFrame f;
- static int rowNum = 0;
- static int [] y = {370,470};
- static board b;
- boolean drawboard;
- public static void main(String[] args) {
- {
- Pacman p=new Pacman();
- b=new board();
- f=new JFrame();
- f.add(p);
- f.setSize(800,600);
- f.setBackground(Color.black);
- f.setVisible(true);
- f.setResizable(false);
- f.addKeyListener(p);
- }
- }
- public void paintComponent(Graphics g){
- g.setFont(new Font("Helvetica", Font.BOLD,100));
- g.setColor(Color.yellow);
- g.drawString("Play",550, 425);
- g.drawString("Quit", 550, 525);
- g.setColor(Color.BLUE);
- g.fillOval(480, y[rowNum], 50, 50);
- if (drawboard == true) f.paint(g);
- }
- public void actionPerformed(ActionEvent arg0) {
- }
- public void keyPressed(KeyEvent e) {
- if (e.getKeyCode()==KeyEvent.VK_UP && rowNum>0) {
- rowNum--;
- f.repaint();
- }
- else if(e.getKeyCode()==KeyEvent.VK_UP && rowNum==0)rowNum=1;
- f.repaint();
- if (e.getKeyCode()==KeyEvent.VK_DOWN && rowNum<1) {
- rowNum++;
- f.repaint();
- }
- else if (e.getKeyCode()==KeyEvent.VK_DOWN && rowNum==1)rowNum=0;
- if (e.getKeyCode()==KeyEvent.VK_ENTER && rowNum==0) {
- //new board();
- boolean drawboard= true;
- f.repaint();
- }
- if (e.getKeyCode()==KeyEvent.VK_ENTER && rowNum==0) {
- JFrame f = new JFrame("Pac board");
- f.add(new board());
- f.setSize (755, 855);
- f.setVisible(true);
- }
- if (e.getKeyCode()==KeyEvent.VK_ENTER && rowNum==1) {
- System.exit(0);
- }
- }
- public void keyReleased(KeyEvent arg0) {
- }
- public void keyTyped(KeyEvent arg0) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement