Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.EventQueue;
- import java.awt.Font;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.IOException;
- import java.net.CookieManager;
- import java.util.Random;
- import java.util.Timer;
- import java.util.TimerTask;
- import javax.swing.ImageIcon;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JPanel;
- import javax.swing.SwingConstants;
- import qc.simonbt.cookie.cookieManager;
- import qc.simonbt.open.openFile;
- import qc.simonbt.save.SaveData;
- public class CookieClicker {
- private JFrame frame;
- private int cookie;
- protected String open;
- public static int xSize;
- private static int xCoord;
- private int multipliers = 1;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- new cookieManager();
- try {
- CookieClicker window = new CookieClicker();
- window.frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the application.
- */
- public CookieClicker() {
- initialize();
- }
- /**
- * Initialize the contents of the frame.
- */
- private void initialize() {
- frame = new JFrame();
- frame.getContentPane().setBackground(new Color(189, 183, 107));
- frame.setBounds(100, 100, 629, 465);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.getContentPane().setLayout(null);
- frame.setResizable(false);
- xCoord = (int) frame.getAlignmentX();
- xSize = (int) frame.getWidth();
- // Title Label
- JLabel lblClickerHero = new JLabel("Cookie Clicker");
- lblClickerHero.setFont(new Font("Nanum Brush Script", Font.BOLD, 36));
- lblClickerHero.setForeground(new Color(128, 0, 0));
- lblClickerHero.setHorizontalAlignment(SwingConstants.CENTER);
- lblClickerHero.setBounds(201, 6, 198, 40);
- frame.getContentPane().add(lblClickerHero);
- // Information Button
- JButton btnNewButton = new JButton("?");
- btnNewButton.setBounds(607, 417, 16, 20);
- frame.getContentPane().add(btnNewButton);
- // Cookie Counter Label
- JLabel lblCookie = new JLabel("Cookies: 0");
- lblCookie.setForeground(new Color(128, 0, 0));
- lblCookie.setFont(new Font("Lucida Grande", Font.BOLD, 18));
- lblCookie.setBounds(201, 87, 198, 29);
- frame.getContentPane().add(lblCookie);
- // Create the Main Menu Frame
- // Buy Button
- // Buy Menu Button
- JButton btnBuyMenu = new JButton("Buy Menu");
- btnBuyMenu.setBounds(142, 413, 328, 29);
- frame.getContentPane().add(btnBuyMenu);
- btnBuyMenu.addActionListener(new ActionListener() {
- int x = xCoord + xSize;
- public void actionPerformed (ActionEvent e) {
- JFrame frame2 = new JFrame("Buy Menu");
- frame2.setVisible(true);
- frame2.getContentPane().setLayout(null);
- frame2.setBounds(x, 100, 200, 400);
- JLabel label = new JLabel("Buy Menu");
- JPanel panel = new JPanel();
- JLabel lab = new JLabel("Auto click");
- lab.setBounds(5, 20, 90, 30);
- JButton btn1 = new JButton("200");
- btn1.setBounds(100, 20, 95, 30);
- btn1.addActionListener(new ActionListener() {
- // Button auto click 200 cookies
- @Override
- public void actionPerformed(ActionEvent e) {
- if(!(cookie < 200 )){
- cookie = new cookieManager().cookieSub(cookie, 200);
- lblCookie.setText( "Cookies: "+ cookie);
- Timer t = new Timer();
- t.schedule(new TimerTask() {
- @Override
- public void run() {
- cookie = new cookieManager().cookieAdd(cookie, 1);
- lblCookie.setText("Cookies: " +cookie);
- }
- }, 0, 1000);
- }else{
- final ImageIcon icon = new ImageIcon("/Users/sbtherrien/Desktop/cookie2.png");
- JOptionPane.showMessageDialog(frame, "You need more money to buy this upgrade!", "Not enought cookie", 1, icon);
- System.out.println("Error: Not enought money");
- return;
- }
- }
- });
- // Boost x2 Button
- JButton btnx2 = new JButton("100");
- btnx2.setBounds(100, 55, 95, 30);
- btnx2.addActionListener(new ActionListener() {
- // Button x2 Multipliers
- @Override
- public void actionPerformed(ActionEvent e) {
- if(!(cookie < 100)){
- cookie = new cookieManager().cookieSub(cookie, 100);
- multipliers = 2;
- }else{
- final ImageIcon icon = new ImageIcon("/Users/sbtherrien/Desktop/cookie2.png");
- JOptionPane.showMessageDialog(frame, "You need more money to buy this upgrade!", "Not enought cookie", 1, icon);
- System.out.println("Error: Not enought money");
- }
- }
- });
- // Boost x2 Label
- JLabel labelx2 = new JLabel("x2 Cookie");
- labelx2.setBounds(5, 55, 95, 30);
- // Boost x5 Button
- JButton btnx5 = new JButton("1000");
- btnx5.setBounds(100, 90, 95, 30);
- btnx5.addActionListener(new ActionListener() {
- // Button x2 Multipliers
- @Override
- public void actionPerformed(ActionEvent e) {
- if(!(cookie < 1000)){
- cookie = new cookieManager().cookieSub(cookie, 1000);
- multipliers = 5;
- }else{
- final ImageIcon icon = new ImageIcon("/Users/sbtherrien/Desktop/cookie2.png");
- JOptionPane.showMessageDialog(frame, "You need more money to buy this upgrade!", "Not enought cookie", 1, icon);
- System.out.println("Error: Not enought money");
- }
- }
- });
- // Boost x5 Label
- JLabel labelx5 = new JLabel("x5 Cookie");
- labelx5.setBounds(5, 90, 95, 30);
- // Bonus bg button
- JButton bonusbg = new JButton("100");
- bonusbg.setBounds(100, 125, 95, 30);
- bonusbg.addActionListener(new ActionListener() {
- // Button x2 Multipliers
- @Override
- public void actionPerformed(ActionEvent e) {
- if(!(cookie < 10)){
- cookie = new cookieManager().cookieSub(cookie, 10);
- lblCookie.setForeground((Color)new cookieManager().randomColor());
- }else{
- final ImageIcon icon = new ImageIcon("/Users/sbtherrien/Desktop/cookie2.png");
- JOptionPane.showMessageDialog(frame, "You need more money to buy this upgrade!", "Not enought cookie", 1, icon);
- System.out.println("Error: Not enought money");
- }
- }
- });
- // Boost x2 Label
- JLabel labelbg = new JLabel("Bonus Background");
- labelbg.setBounds(5, 125, 95, 30);
- frame2.getContentPane().add(bonusbg);
- frame2.getContentPane().add(labelbg);
- frame2.getContentPane().add(btnx5);
- frame2.getContentPane().add(labelx5);
- frame2.getContentPane().add(labelx2);
- frame2.getContentPane().add(panel);
- panel.add(label);
- frame2.getContentPane().add(btnx2);
- frame2.getContentPane().add(lab);
- frame2.getContentPane().add(btn1);
- }
- });
- // Cookie Button
- JButton btnClick = new JButton("Cookie");
- btnClick.setIcon(new ImageIcon("/Users/sbtherrien/Desktop/cookie.png"));
- btnClick.setFont(new Font("Lucida Grande", Font.BOLD, 35));
- btnClick.setForeground(new Color(128, 0, 0));
- btnClick.setBounds(201, 128, 198, 178);
- btnClick.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- cookie = cookie + multipliers;
- lblCookie.setText("Cookies: " + cookie);
- new SaveData().Save(cookie + "");
- }
- });
- frame.getContentPane().add(btnClick);
- JButton btnopen = new JButton("Open game");
- btnopen.setBounds(10, 410, 80, 30);
- btnopen.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- open = new openFile().readFile();
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- lblCookie.setText("Cookies: " + cookie);
- }
- });
- frame.getContentPane().add(btnopen);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement