Guest User

Untitled

a guest
Jan 7th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Font;
  3. import java.awt.Graphics;
  4. import java.awt.Graphics2D;
  5. import java.awt.Image;
  6. import java.awt.event.KeyEvent;
  7. import java.awt.event.MouseEvent;
  8.  
  9. public class main_menu extends state
  10. {
  11. private String title;
  12. private String play;
  13. private String quit;
  14.  
  15. private int selected;
  16.  
  17. public main_menu()
  18. {
  19. this.title = "Saper";
  20. this.play = "Play";
  21. this.quit = "Quit";
  22.  
  23. this.selected = 0;
  24. }
  25.  
  26. public void Update(KeyEvent e, app a, MouseEvent m)
  27. {
  28. if(m == null) {
  29. switch(e.getKeyCode())
  30. {
  31. case 40:
  32. this.selected += 1;
  33. break;
  34. case 38:
  35. this.selected -= 1;
  36. break;
  37. case 32:
  38. if(this.selected == 0)
  39. a.coreState = new game(a);
  40. else if(this.selected == 1)
  41. System.exit(0);
  42. break;
  43. }
  44. if (this.selected > 1)
  45. {
  46. this.selected = 0;
  47. }
  48. if (this.selected < 0)
  49. {
  50. this.selected = 1;
  51. }
  52. a.repaint();
  53. }
  54. }
  55.  
  56. public void Render(Graphics g, app a) {
  57. Image img = a.createImage(a.getSize().width, a.getSize().height);
  58. Graphics2D g2 =(Graphics2D)img.getGraphics();
  59.  
  60. g2.setFont(new Font("Arial",Font.BOLD,64));
  61. g2.setColor(Color.black.darker());
  62. g2.drawString(this.title, a.getSize().width / 2 - (this.title.length()) / 2 * 50, 120);
  63.  
  64. g2.setFont(new Font("Arial",Font.BOLD,32));
  65.  
  66.  
  67. if(this.selected == 0)
  68. {
  69. g2.setColor(Color.green.darker());
  70. g2.drawString(this.play, a.getSize().width / 2 - this.play.length() / 2 * 22, a.getSize().height / 2);
  71. g2.setColor(Color.black.darker());
  72. g2.drawString(this.quit, a.getSize().width / 2 - this.quit.length() / 2 * 22, 520);
  73. }
  74. else if(this.selected == 1)
  75. {
  76. g2.setColor(Color.black.darker());
  77. g2.drawString(this.play, a.getSize().width / 2 - this.play.length() / 2 * 22, a.getSize().height / 2);
  78. g2.setColor(Color.green.darker());
  79. g2.drawString(this.quit, a.getSize().width / 2 - this.quit.length() / 2 * 22, 520);
  80. }
  81.  
  82. g.drawImage(img, 0, 0, a);
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment