Advertisement
Guest User

menuscreen

a guest
Jan 22nd, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Font;
  3. import java.awt.Graphics;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.awt.event.KeyEvent;
  7. import java.awt.event.KeyListener;
  8.  
  9. import javax.swing.JFrame;
  10. import javax.swing.JPanel;
  11. import javax.swing.Timer;
  12.  
  13. public class Pacman extends JPanel implements KeyListener,ActionListener {
  14. static Color colorArray[]={Color.white};
  15. static JFrame f;
  16. static int rowNum = 0;
  17. static int [] y = {370,470};
  18. static board b;
  19. boolean drawboard;
  20. public static void main(String[] args) {
  21. {
  22. Pacman p=new Pacman();
  23. b=new board();
  24. f=new JFrame();
  25. f.add(p);
  26. f.setSize(800,600);
  27. f.setBackground(Color.black);
  28. f.setVisible(true);
  29. f.setResizable(false);
  30. f.addKeyListener(p);
  31. }
  32. }
  33. public void paintComponent(Graphics g){
  34. g.setFont(new Font("Helvetica", Font.BOLD,100));
  35. g.setColor(Color.yellow);
  36. g.drawString("Play",550, 425);
  37. g.drawString("Quit", 550, 525);
  38. g.setColor(Color.BLUE);
  39. g.fillOval(480, y[rowNum], 50, 50);
  40. if (drawboard == true) f.paint(g);
  41. }
  42. public void actionPerformed(ActionEvent arg0) {
  43. }
  44. public void keyPressed(KeyEvent e) {
  45. if (e.getKeyCode()==KeyEvent.VK_UP && rowNum>0) {
  46. rowNum--;
  47. f.repaint();
  48. }
  49. else if(e.getKeyCode()==KeyEvent.VK_UP && rowNum==0)rowNum=1;
  50. f.repaint();
  51. if (e.getKeyCode()==KeyEvent.VK_DOWN && rowNum<1) {
  52. rowNum++;
  53. f.repaint();
  54. }
  55. else if (e.getKeyCode()==KeyEvent.VK_DOWN && rowNum==1)rowNum=0;
  56. if (e.getKeyCode()==KeyEvent.VK_ENTER && rowNum==0) {
  57. //new board();
  58. boolean drawboard= true;
  59. f.repaint();
  60. }
  61. if (e.getKeyCode()==KeyEvent.VK_ENTER && rowNum==0) {
  62. JFrame f = new JFrame("Pac board");
  63. f.add(new board());
  64. f.setSize (755, 855);
  65. f.setVisible(true);
  66. }
  67. if (e.getKeyCode()==KeyEvent.VK_ENTER && rowNum==1) {
  68. System.exit(0);
  69. }
  70. }
  71. public void keyReleased(KeyEvent arg0) {
  72. }
  73. public void keyTyped(KeyEvent arg0) {
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement