Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.13 KB | None | 0 0
  1. private JPanel contentPane;
  2. public Parameters Parameters;
  3. public JPanel panel1;
  4. public JPanel panel2;
  5. public JPanel field;
  6.  
  7. public Color rightcolor1;
  8. public Color wrongcolor1;
  9.  
  10. public int a;
  11. public int b;
  12.  
  13.  
  14. /**
  15. * Launch the application
  16. */
  17.  
  18. public static void main(String[] args) {
  19. EventQueue.invokeLater(new Runnable() {
  20. public void run() {
  21. try {
  22. P frame = new P();
  23. frame.setVisible(true);
  24. } catch (Exception e) {
  25. e.printStackTrace();
  26. }
  27. }
  28. });
  29. }
  30.  
  31. /**
  32. * Create the frame.
  33. * @return
  34. */
  35.  
  36. public void param(){
  37.  
  38. boolean[] wrongcolor = new boolean[2];
  39. wrongcolor[0] = Parameters.isG1();
  40. wrongcolor[1] = Parameters.isR1();
  41.  
  42. if (wrongcolor[0] = true){
  43. wrongcolor1 = Color.GREEN;
  44. } else wrongcolor1 = Color.RED;
  45.  
  46. boolean[] rightcolor = new boolean[2];
  47. rightcolor[0] = Parameters.isG2();
  48. rightcolor[1] = Parameters.isR2();
  49.  
  50. if (rightcolor[0] = true){
  51. rightcolor1 = Color.GREEN;
  52. } else rightcolor1 = Color.RED;
  53.  
  54. boolean[] size = new boolean[3];
  55. size[0] = Parameters.isS1();
  56. size[1] = Parameters.isS2();
  57. size[2] = Parameters.isS3();
  58.  
  59. if (size[0] = true) {
  60. a = 1;
  61. } else if (size[1] = true) {
  62. a = 2;
  63. } else a = 3;
  64.  
  65. boolean[] speed = new boolean[3];
  66. speed[0] = Parameters.isSp1();
  67. speed[1] = Parameters.isSp2();
  68. speed[2] = Parameters.isSp3();
  69.  
  70. if (speed[0] = true) {
  71. b = 1;
  72. } else if (speed[1] = true) {
  73. b = 2;
  74. } else b = 3;
  75. }
  76.  
  77. public int randomRange(int min, int max){
  78. double rnd = Math.random();
  79. return min + (int)(rnd * ((max - min) + 1));
  80. }
  81.  
  82. public int randomRange (int max){
  83. return randomRange(0, max);
  84. }
  85.  
  86.  
  87. public void addingpanel1() {
  88.  
  89. int max = 100;
  90. for (int i = 0; i < max; i++) {
  91. panel1 = new JPanel();
  92. panel1.setBackground(rightcolor1);
  93.  
  94. /*Dimension kek = panel1.getPreferredSize();
  95. int h = size.height;
  96. int w = size.width;
  97. int h = size.height;
  98. int w = size.width; */
  99.  
  100. /*panel1.setSize(a, a);*/
  101.  
  102. int x = randomRange(getWidth() - a);
  103. int y = randomRange(getHeight() - a);
  104. panel1.setBounds(x, y, a, a);
  105.  
  106. field.add(panel1);
  107. field.setComponentZOrder(panel1, 0);
  108.  
  109. panel1.addMouseListener(new MouseAdapter() {
  110. @Override
  111. public void mouseClicked(MouseEvent arg) {
  112. if(arg.getButton() != MouseEvent.BUTTON3) return;
  113. field.remove(panel1);
  114. field.updateUI();
  115. }
  116.  
  117. });
  118.  
  119. }
  120. }
  121.  
  122. public void addingpanel2() {
  123.  
  124. int max = 100;
  125. for (int i = 0; i < max; i++) {
  126. JPanel panel2 = new JPanel();
  127. panel2.setBackground(wrongcolor1);
  128.  
  129. int x = randomRange(getWidth() - a);
  130. int y = randomRange(getHeight() - a);
  131. panel2.setBounds(x, y, a, a);
  132.  
  133. field.add(panel2);
  134. field.setComponentZOrder(panel2, 0);
  135.  
  136. panel2.addMouseListener(new MouseAdapter() {
  137. @Override
  138. public void mouseClicked(MouseEvent arg) {
  139. if(arg.getButton() != MouseEvent.BUTTON3) return;
  140. String s = "Ты проиграл!";
  141. JLabel lose = new JLabel(s);
  142. lose.setForeground(Color.RED);
  143. lose.setFont(new Font("Tahoma", Font.PLAIN, 25));
  144. lose.setHorizontalAlignment(SwingConstants.CENTER);
  145. lose.setBounds(0, 66, 434, 114);
  146. field.add(lose);
  147.  
  148. }
  149.  
  150. });
  151.  
  152. }
  153. }
  154.  
  155. public P() {
  156. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  157. setBounds(100, 100, 450, 300);
  158. contentPane = new JPanel();
  159. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  160. setContentPane(contentPane);
  161. contentPane.setLayout(null);
  162.  
  163. JPanel field = new JPanel();
  164. field.setBounds(0, 26, 434, 205);
  165. contentPane.add(field);
  166.  
  167. try {
  168. Parameters = new Parameters(this);
  169. Parameters.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
  170. } catch (Exception e) {
  171. e.printStackTrace();
  172. }
  173.  
  174. JButton newgame = new JButton("u041Du043Eu0432u0430u044F u0438u0433u0440u0430");
  175. newgame.addActionListener(new ActionListener() {
  176. public void actionPerformed(ActionEvent arg0) {
  177. Parameters.setVisible(true);
  178. }
  179. });
  180.  
  181. newgame.setBounds(0, 0, 101, 23);
  182. contentPane.add(newgame);
  183.  
  184. JButton statistika = new JButton("u0421u0442u0430u0442u0438u0441u0442u0438u043Au0430");
  185. statistika.setBounds(333, 0, 101, 23);
  186. contentPane.add(statistika);
  187.  
  188. JButton info = new JButton("u041E u043Fu0440u043Eu0433u0440u0430u043Cu043Cu0435");
  189. info.setBounds(333, 238, 101, 23);
  190. contentPane.add(info);
  191.  
  192. JButton exit = new JButton("u0412u044Bu0445u043Eu0434");
  193. exit.setBounds(234, 238, 89, 23);
  194. contentPane.add(exit);
  195.  
  196. JLabel proshlo = new JLabel("u041Fu0440u043Eu0448u043Bu043E u0432u0440u0435u043Cu0435u043Du0438:");
  197. proshlo.setBounds(10, 238, 107, 23);
  198. contentPane.add(proshlo);
  199.  
  200. JLabel timer = new JLabel("");
  201. timer.setBounds(119, 238, 105, 23);
  202. contentPane.add(timer);
  203. param();
  204. addingpanel1();
  205. addingpanel2();
  206. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement