Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.clicky.main;
- import java.awt.Dimension;
- import java.awt.FlowLayout;
- import java.awt.Image;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.IOException;
- import java.util.Scanner;
- import javax.swing.ImageIcon;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.SwingUtilities;
- import javax.swing.WindowConstants;
- /*
- * author Jamie G
- * Created 03/02/17
- */
- public class Main
- {
- static JFrame frame;
- public static int Seconds;
- public static String path = "C:\\Users\\Jamix\\Desktop\\Chicken\\";
- public static int Multiplier = 1;
- public static boolean visible = true;
- public static boolean resizable = false;
- public static int x = 400;
- public static int Counter = 0;
- public static void main(String[] args) throws IOException
- {
- while (x < 401) {
- Seconds++;
- System.out.print("\nAt : " + Seconds );
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- // schedule this for the event dispatch thread (edt)
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- displayJFrame();
- }
- });
- }
- static void displayJFrame()
- {
- frame = new JFrame("Click-y Game");
- Image frameImage = new ImageIcon("C:\\Users\\Jamix\\Desktop\\Clicky Game\\src\\cursor.png").getImage();
- frame.setIconImage(frameImage);
- // create our jbutton
- JButton clickButton = new JButton("Press.");
- JButton godButton = new JButton("x99.");
- JButton resetButton = new JButton("Reset");
- JLabel label = new JLabel("This is a Swing frame", JLabel.CENTER);
- JButton jamixButton = new JButton("Jamix Button");
- JButton basicRules = new JButton("Rules");
- basicRules.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e) {
- 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);
- }
- });
- jamixButton.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent arg0) {
- Scanner scan = new Scanner(System.in);
- boolean correctLogin = false;
- String username;
- String password;
- String enteredUsername;
- String enteredPassword;
- while(correctLogin != true){
- System.out.println("Enter Username: ");
- enteredUsername = scan.nextLine();
- System.out.println("Enter Password: ");
- enteredPassword = scan.nextLine();
- if(enteredUsername.equals("username") && enteredPassword.equals("passw00rd")){
- System.out.println("You have entered the correct login info");
- System.out.println("You are now logged in, good job!");
- Counter = Counter + 200;
- Counter = Counter * 200;
- System.out.println("Your points are now " +Counter);
- label.setText("Pressed " + Counter + " times. Your Multiplier is " +Multiplier);
- correctLogin = true;
- break;
- }
- else if (enteredUsername.equalsIgnoreCase("exit")) {
- System.out.print("Exit-ing");
- break;
- }
- else{
- System.out.println("Your login info was incorrect, please try again");
- }
- }
- }
- });
- resetButton.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e) {
- Counter = Counter - Counter;
- Multiplier = Multiplier - Multiplier + 1;
- label.setText("Pressed " + Counter + " times. Your Multiplier is " +Multiplier);
- }
- });
- godButton.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e) {
- Counter = Counter + 99 * Multiplier;
- label.setText("Pressed " +Counter+ " times. Your Multiplier is " +Multiplier);
- }
- });
- // add the listener to the jbutton to handle the "pressed" event
- clickButton.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- // display/center the jdialog when the button is pressed
- Counter = Counter + 1 * Multiplier;
- label.setText("Pressed " +Counter+ " times. Your Multiplier is " +Multiplier);
- Multiplier = Counter / 100 + 1;
- if (Multiplier > 10) {
- Multiplier = 10;
- }
- System.out.println(Counter);
- }
- });
- // put the show button on the frame
- frame.add(basicRules);
- frame.getContentPane().setLayout(new FlowLayout());
- frame.add(jamixButton);
- // put the button on the frame
- frame.getContentPane().setLayout(new FlowLayout());
- frame.add(clickButton);
- frame.add(label);
- label.setText("Pressed" +Counter+ "times");
- // put the button on the frame x99 one
- frame.getContentPane().setLayout(new FlowLayout());
- frame.add(godButton);
- // put the reset button on the frame
- frame.getContentPane().setLayout(new FlowLayout());
- frame.add(resetButton);
- frame.add(label);
- // set up the jframe, then display it
- frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
- frame.setPreferredSize(new Dimension(450, 100));
- frame.pack();
- frame.setLocation(500,300);
- frame.setResizable(resizable);
- frame.setVisible(visible);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment