SHARE
TWEET

CC

a guest Jul 18th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2. import javax.swing.*;
  3. import java.awt.event.*;
  4. public class CookieClicker extends JFrame{
  5.    //variables
  6.    final int WINDOW_WIDTH = 500, WINDOW_HEIGHT = 700;
  7.    JLabel total;
  8.    JLabel cursor;
  9.    JLabel grandma;
  10.    JLabel farm;
  11.    JButton plus1Button;
  12.    JButton plus1Cursor;
  13.    JButton plus1Grandma;
  14.    JButton plus1Farm;
  15.    JPanel panel;
  16.    //constructor
  17.    public CookieClicker(){
  18.    buildPanel();
  19.    setTitle("Cookie Clicker");
  20.    setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
  21.    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  22.    add(panel);
  23.    setVisible(true);
  24.    }
  25.    //build panel
  26.    private void buildPanel(){
  27.    String cookies = "0.0";
  28.    total = new JLabel(cookies);
  29.    cursor = new JLabel("Cursor");
  30.    grandma = new JLabel("Grandma");
  31.    farm = new JLabel("Farm");
  32.    //numTextField = new JTextField(10);
  33.    //tempTextField = new JTextField(10);  
  34.    plus1Button = new JButton("Click");
  35.    plus1Button.addActionListener(new CookieButtonListener());
  36.    plus1Cursor = new JButton("Cursor");
  37.    //plus1Cursor.addActionListener(new CursorButtonListener());
  38.    plus1Grandma = new JButton("Grandma");
  39.    //plus1Grandma.addActionListener(new GrandmaButtonListener());
  40.    plus1Farm = new JButton("Farm");
  41.    //plus1Farm.addActionListener(new FarmButtonListener());
  42.    
  43.    panel = new JPanel();
  44.    panel.add(total);
  45.    panel.add(plus1Button);
  46.    //panel.add(cursor);
  47.    panel.add(plus1Cursor);  
  48.    //panel.add(grandma);
  49.    panel.add(plus1Grandma);
  50.    //panel.add(farm);
  51.    panel.add(plus1Farm);
  52.    //panel.add(numLabel);
  53.    //panel.add(tempLabel);
  54.    //panel.add(tempTextField);
  55.    //panel.add(calculateButton);
  56.    
  57.    }
  58.    //button listener
  59.    private class CookieButtonListener implements ActionListener {
  60.       public void actionPerformed(ActionEvent e) {
  61.          
  62.          String cookie;
  63.          Double cookieNum;
  64.          String cookieTotal;
  65.          cookie = total.getText();
  66.          cookieNum = (Double.parseDouble(cookie));
  67.          total.setText("" + cookieNum++);
  68.          
  69.          //cookieNum++;
  70.          //cookieTotal = convertCookies(cookieNum);
  71.          /*
  72.          //num = numTextField.getText();
  73.          //numText = (Double.parseDouble(num));
  74.          //temp = tempTextField.getText();
  75.          String total = cookieTotal;
  76.          JOptionPane.showMessageDialog(null, cookieTotal);
  77.          //System.exit(0);*/
  78.       }  
  79.    }
  80.    //main method
  81.    public static void main (String[] args){
  82.    CookieClicker converterGUI = new CookieClicker();
  83.    
  84.    }
  85.    
  86.    
  87.    //conversion method
  88.    public static String convertCookies(double cookieNum){
  89.       double cookies = cookieNum;
  90.       cookies++;
  91.       String num = ("" + cookies);
  92.       return num;
  93.    }
  94.    /*public static void main (String [] args){            
  95.  
  96.       Scanner keyboard = new Scanner(System.in);
  97.       //get temp    
  98.       System.out.println("Hello. This program will convert Fahrenheit to Celsius, or vise versa.");
  99.       System.out.print("To get started please enter a temperature: ");
  100.       double temperature = keyboard.nextInt();
  101.       String temperatureScale = "";      
  102.       System.out.println("You've entered " + temperature);
  103.       //f or c
  104.       System.out.println("Did you submit Fahrenheit or Celsius?");
  105.       System.out.print("Type f for Fahrenheit, or c for Celsius: ");
  106.       temperatureScale = keyboard.next();      
  107.       convertTemp(temperature, temperatureScale);
  108.      
  109.    
  110.    }*/
  111. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top