Advertisement
Guest User

Untitled

a guest
Feb 11th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.10 KB | None | 0 0
  1. package com.clicky.main;
  2.  
  3.  
  4. import java.awt.Dimension;
  5. import java.awt.FlowLayout;
  6. import java.awt.Image;
  7. import java.awt.event.ActionEvent;
  8. import java.awt.event.ActionListener;
  9. import java.io.IOException;
  10. import java.util.Scanner;
  11.  
  12. import javax.swing.ImageIcon;
  13. import javax.swing.JButton;
  14. import javax.swing.JFrame;
  15. import javax.swing.JLabel;
  16. import javax.swing.JOptionPane;
  17. import javax.swing.SwingUtilities;
  18. import javax.swing.WindowConstants;
  19.  
  20.  
  21.  
  22. /*
  23. * author Jamie G
  24. * Created 03/02/17
  25. */
  26.  
  27.  
  28. public class Main
  29. {
  30. static JFrame frame;
  31.  
  32. public static int Seconds;
  33.  
  34. public static String path = "C:\\Users\\Jamix\\Desktop\\Chicken\\";
  35.  
  36. public static int Multiplier = 1;
  37.  
  38. public static boolean visible = true;
  39.  
  40. public static boolean resizable = false;
  41.  
  42. public static int x = 400;
  43.  
  44.  
  45.  
  46. public static int Counter = 0;
  47.  
  48. public static void main(String[] args) throws IOException
  49. {
  50.  
  51.  
  52.  
  53.  
  54.  
  55. while (x < 401) {
  56. Seconds++;
  57. System.out.print("\nAt : " + Seconds );
  58. try {
  59. Thread.sleep(1000);
  60. } catch (InterruptedException e) {
  61.  
  62. e.printStackTrace();
  63. }
  64. }
  65.  
  66.  
  67.  
  68.  
  69. // schedule this for the event dispatch thread (edt)
  70. SwingUtilities.invokeLater(new Runnable()
  71. {
  72. public void run()
  73. {
  74. displayJFrame();
  75. }
  76. });
  77. }
  78.  
  79.  
  80.  
  81.  
  82. static void displayJFrame()
  83. {
  84. frame = new JFrame("Click-y Game");
  85. Image frameImage = new ImageIcon("C:\\Users\\Jamix\\Desktop\\Clicky Game\\src\\cursor.png").getImage();
  86. frame.setIconImage(frameImage);
  87.  
  88. // create our jbutton
  89. JButton clickButton = new JButton("Press.");
  90. JButton godButton = new JButton("x99.");
  91. JButton resetButton = new JButton("Reset");
  92. JLabel label = new JLabel("This is a Swing frame", JLabel.CENTER);
  93. JButton jamixButton = new JButton("Jamix Button");
  94. JButton basicRules = new JButton("Rules");
  95.  
  96. basicRules.addActionListener(new ActionListener()
  97. {
  98.  
  99. @Override
  100. public void actionPerformed(ActionEvent e) {
  101. JOptionPane.showMessageDialog(frame,/*Text in the chat here ->*/"Click the button to get score. Your score reflects on your multiplier, This is only\na beta at this moment, more will be added", /*title ->*/"Clik-y Game - Rules", 1, null);
  102.  
  103. }
  104.  
  105. });
  106.  
  107. jamixButton.addActionListener(new ActionListener()
  108. {
  109.  
  110. @Override
  111. public void actionPerformed(ActionEvent arg0) {
  112. Scanner scan = new Scanner(System.in);
  113.  
  114. boolean correctLogin = false;
  115. String username;
  116. String password;
  117. String enteredUsername;
  118. String enteredPassword;
  119.  
  120. while(correctLogin != true){
  121. System.out.println("Enter Username: ");
  122. enteredUsername = scan.nextLine();
  123.  
  124. System.out.println("Enter Password: ");
  125. enteredPassword = scan.nextLine();
  126.  
  127.  
  128. if(enteredUsername.equals("username") && enteredPassword.equals("passw00rd")){
  129. System.out.println("You have entered the correct login info");
  130. System.out.println("You are now logged in, good job!");
  131. Counter = Counter + 200;
  132. Counter = Counter * 200;
  133. System.out.println("Your points are now " +Counter);
  134. label.setText("Pressed " + Counter + " times. Your Multiplier is " +Multiplier);
  135. correctLogin = true;
  136. break;
  137. }
  138.  
  139. else if (enteredUsername.equalsIgnoreCase("exit")) {
  140. System.out.print("Exit-ing");
  141. break;
  142. }
  143. else{
  144. System.out.println("Your login info was incorrect, please try again");
  145. }
  146. }
  147.  
  148.  
  149. }
  150.  
  151.  
  152. });
  153.  
  154.  
  155.  
  156. resetButton.addActionListener(new ActionListener()
  157. {
  158.  
  159. public void actionPerformed(ActionEvent e) {
  160. Counter = Counter - Counter;
  161. Multiplier = Multiplier - Multiplier + 1;
  162. label.setText("Pressed " + Counter + " times. Your Multiplier is " +Multiplier);
  163.  
  164.  
  165. }
  166.  
  167. });
  168.  
  169.  
  170.  
  171. godButton.addActionListener(new ActionListener()
  172. {
  173.  
  174. public void actionPerformed(ActionEvent e) {
  175. Counter = Counter + 99 * Multiplier;
  176. label.setText("Pressed " +Counter+ " times. Your Multiplier is " +Multiplier);
  177.  
  178. }
  179. });
  180.  
  181.  
  182.  
  183.  
  184. // add the listener to the jbutton to handle the "pressed" event
  185. clickButton.addActionListener(new ActionListener()
  186. {
  187. @Override
  188. public void actionPerformed(ActionEvent e)
  189. {
  190. // display/center the jdialog when the button is pressed
  191.  
  192. Counter = Counter + 1 * Multiplier;
  193. label.setText("Pressed " +Counter+ " times. Your Multiplier is " +Multiplier);
  194. Multiplier = Counter / 100 + 1;
  195. if (Multiplier > 10) {
  196. Multiplier = 10;
  197. }
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207. System.out.println(Counter);
  208. }
  209. });
  210.  
  211.  
  212. // put the show button on the frame
  213. frame.add(basicRules);
  214. frame.getContentPane().setLayout(new FlowLayout());
  215. frame.add(jamixButton);
  216.  
  217. // put the button on the frame
  218. frame.getContentPane().setLayout(new FlowLayout());
  219. frame.add(clickButton);
  220. frame.add(label);
  221. label.setText("Pressed" +Counter+ "times");
  222.  
  223. // put the button on the frame x99 one
  224. frame.getContentPane().setLayout(new FlowLayout());
  225. frame.add(godButton);
  226.  
  227. // put the reset button on the frame
  228. frame.getContentPane().setLayout(new FlowLayout());
  229. frame.add(resetButton);
  230. frame.add(label);
  231.  
  232. // set up the jframe, then display it
  233. frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  234. frame.setPreferredSize(new Dimension(450, 100));
  235. frame.pack();
  236. frame.setLocation(500,300);
  237. frame.setResizable(resizable);
  238. frame.setVisible(visible);
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280. }
  281.  
  282.  
  283. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement