Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4. import java.io.*;
  5. import java.util.ArrayList;
  6.  
  7. public class ColorFlash implements ActionListener {
  8. private JFrame f_MainMenu;
  9. private JButton b_play, b_htp, b_highscores, b_quit;
  10. ArrayList<String> button = new ArrayList<String>();
  11. int r = 255;
  12. int g = 4;
  13. int b = 4;
  14.  
  15.  
  16. public static void main(String[]args) {
  17. new ColorFlash();
  18. }
  19.  
  20. public ColorFlash(){
  21. f_MainMenu = new JFrame("Color Flash!");
  22. f_MainMenu.setSize(800,500);
  23. f_MainMenu.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  24. f_MainMenu.setVisible(true);
  25. f_MainMenu.setResizable(false);
  26. f_MainMenu.setLayout(null);
  27. f_MainMenu.setLocationRelativeTo(null);
  28.  
  29. b_play = new JButton("Play");
  30. f_MainMenu.add(b_play);
  31. b_play.setBounds(300,150,200,65);
  32. b_play.setBackground(new Color(0, 77, 255));
  33. //b_play.setForeground(Color.white);
  34. b_play.setFocusPainted(false);
  35. b_play.setFont(new Font("Tahoma", Font.BOLD, 12));
  36. b_play.addActionListener(this);
  37.  
  38. b_htp = new JButton("How to Play");
  39. f_MainMenu.add(b_htp);
  40. b_htp.setBounds(300,225,200,65);
  41. b_htp.setBackground(new Color(170, 34, 228));
  42. //b_htp.setForeground(Color.white);
  43. b_htp.setFont(new Font("Tahoma", Font.BOLD, 12));
  44. b_htp.addActionListener(this);
  45.  
  46. b_highscores = new JButton("Highscores");
  47. f_MainMenu.add(b_highscores);
  48. b_highscores.setBounds(300,300,200,65);
  49. b_highscores.setBackground(new Color(0, 199, 13));
  50. //b_highscores.setForeground(Color.white);
  51. b_highscores.setFont(new Font("Tahoma", Font.BOLD, 12));
  52. b_highscores.addActionListener(this);
  53.  
  54. b_quit = new JButton("Quit");
  55. f_MainMenu.add(b_quit);
  56. b_quit.setBounds(300,375,200,65);
  57. b_quit.setBackground(Color.RED);
  58. //b_quit.setForeground(Color.white);
  59. b_quit.setFont(new Font("Tahoma", Font.BOLD, 12));
  60. b_quit.addActionListener(this);
  61.  
  62. JLabel title = new JLabel("Color Flash!");
  63. f_MainMenu.add(title);
  64. title.setBounds(261,40,300,50);
  65. title.setFont(new Font("SansSerif", Font.BOLD, 48));
  66.  
  67. Timer colortimer = new Timer(3,this);
  68. colortimer.start();
  69. }
  70.  
  71. public void actionPerformed(ActionEvent e) {
  72.  
  73. if (r==255 && g<255 && b==4) {
  74. g++;
  75. f_MainMenu.getContentPane().setBackground( new Color(r,g,b));
  76. }
  77. if(r>4 && g==255 && b==4) {
  78. r--;
  79. f_MainMenu.getContentPane().setBackground( new Color(r,g,b));
  80. }
  81. if(r==4 && g==255 && b<255) {
  82. b++;
  83. f_MainMenu.getContentPane().setBackground( new Color(r,g,b));
  84. }
  85. if(r==4 && g>4 && b==255) {
  86. g--;
  87. f_MainMenu.getContentPane().setBackground( new Color(r,g,b));
  88. }
  89. if(r<255 && g==4 && b==255) {
  90. r++;
  91. f_MainMenu.getContentPane().setBackground( new Color(r,g,b));
  92. }
  93. if(r==255 && g==4 && b>4) {
  94. b--;
  95. f_MainMenu.getContentPane().setBackground( new Color(r,g,b));
  96. }
  97.  
  98.  
  99. if(e.getSource()==b_play) {
  100. f_MainMenu.dispose();
  101. new Game();
  102. }
  103. if(e.getSource()==b_htp) {
  104. f_MainMenu.dispose();
  105. Game.howToPlay();
  106. }
  107. if(e.getSource()==b_highscores) {
  108. f_MainMenu.dispose();
  109. Game.highscores();
  110.  
  111. }
  112. if(e.getSource()==b_quit) {
  113. System.exit(0);
  114. }
  115.  
  116.  
  117. }
  118.  
  119.  
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement