Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import javax.swing.*;
- import java.awt.event.*;
- public class CookieClicker extends JFrame{
- //variables
- final int WINDOW_WIDTH = 500, WINDOW_HEIGHT = 700;
- JLabel total;
- JLabel cursor;
- JLabel grandma;
- JLabel farm;
- JButton plus1Button;
- JButton plus1Cursor;
- JButton plus1Grandma;
- JButton plus1Farm;
- JPanel panel;
- //constructor
- public CookieClicker(){
- buildPanel();
- setTitle("Cookie Clicker");
- setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- add(panel);
- setVisible(true);
- }
- //build panel
- private void buildPanel(){
- String cookies = "0.0";
- total = new JLabel(cookies);
- cursor = new JLabel("Cursor");
- grandma = new JLabel("Grandma");
- farm = new JLabel("Farm");
- //numTextField = new JTextField(10);
- //tempTextField = new JTextField(10);
- plus1Button = new JButton("Click");
- plus1Button.addActionListener(new CookieButtonListener());
- plus1Cursor = new JButton("Cursor");
- //plus1Cursor.addActionListener(new CursorButtonListener());
- plus1Grandma = new JButton("Grandma");
- //plus1Grandma.addActionListener(new GrandmaButtonListener());
- plus1Farm = new JButton("Farm");
- //plus1Farm.addActionListener(new FarmButtonListener());
- panel = new JPanel();
- panel.add(total);
- panel.add(plus1Button);
- //panel.add(cursor);
- panel.add(plus1Cursor);
- //panel.add(grandma);
- panel.add(plus1Grandma);
- //panel.add(farm);
- panel.add(plus1Farm);
- //panel.add(numLabel);
- //panel.add(tempLabel);
- //panel.add(tempTextField);
- //panel.add(calculateButton);
- }
- //button listener
- private class CookieButtonListener implements ActionListener {
- public void actionPerformed(ActionEvent e) {
- String cookie;
- Double cookieNum;
- String cookieTotal;
- cookie = total.getText();
- cookieNum = (Double.parseDouble(cookie));
- total.setText("" + cookieNum++);
- //cookieNum++;
- //cookieTotal = convertCookies(cookieNum);
- /*
- //num = numTextField.getText();
- //numText = (Double.parseDouble(num));
- //temp = tempTextField.getText();
- String total = cookieTotal;
- JOptionPane.showMessageDialog(null, cookieTotal);
- //System.exit(0);*/
- }
- }
- //main method
- public static void main (String[] args){
- CookieClicker converterGUI = new CookieClicker();
- }
- //conversion method
- public static String convertCookies(double cookieNum){
- double cookies = cookieNum;
- cookies++;
- String num = ("" + cookies);
- return num;
- }
- /*public static void main (String [] args){
- Scanner keyboard = new Scanner(System.in);
- //get temp
- System.out.println("Hello. This program will convert Fahrenheit to Celsius, or vise versa.");
- System.out.print("To get started please enter a temperature: ");
- double temperature = keyboard.nextInt();
- String temperatureScale = "";
- System.out.println("You've entered " + temperature);
- //f or c
- System.out.println("Did you submit Fahrenheit or Celsius?");
- System.out.print("Type f for Fahrenheit, or c for Celsius: ");
- temperatureScale = keyboard.next();
- convertTemp(temperature, temperatureScale);
- }*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement