Advertisement
Guest User

Untitled

a guest
Apr 21st, 2020
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.18 KB | None | 0 0
  1. // dev notes:
  2. // 1. Fix the issue with the layout of the cookie button. V1.1
  3. // 1. Add a cookie factory for a cost of 100 cookie, make 1 cookie per second. V1.2
  4.  
  5. import java.awt.BorderLayout;
  6. import java.awt.GridLayout;
  7. import java.awt.event.ActionEvent;
  8. import java.awt.event.ActionListener;
  9. import javax.swing.BorderFactory;
  10. import javax.swing.ImageIcon;
  11. import javax.swing.JButton;
  12. import javax.swing.JFrame;
  13. import javax.swing.JLabel;
  14. import javax.swing.JPanel;
  15.  
  16.  
  17. public class GUI implements ActionListener {
  18.    
  19.     private int count = 0;
  20.     private JLabel label;
  21.     private JFrame frame;
  22.     private JPanel panel;
  23.    
  24.     public GUI() {
  25.        
  26.        
  27.         frame = new JFrame();
  28.        
  29.         JButton buttonA = new JButton(new ImageIcon("C:\\Users\\LENOVO\\eclipse-workspace\\OurFirstGUI\\cookie.png"));
  30.         buttonA.addActionListener(this);
  31.        
  32.        
  33.         label = new JLabel("Number of cookies: 0");
  34.         label = new JLabel("V1.0 By Someone on Internet");
  35.        
  36.          
  37.         panel = new JPanel();
  38.         panel.setBorder(BorderFactory.createEmptyBorder(10, 30, 30, 30));
  39.         panel.setLayout(new GridLayout(0, 1));
  40.         panel.add(buttonA);
  41.         panel.add(label);
  42.        
  43.        
  44.         frame.add(panel, BorderLayout.CENTER);
  45.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  46.         frame.setTitle("Cookie Clicker");
  47.         frame.pack();
  48.         frame.setVisible(true);
  49.     }
  50.    
  51.     public static void main(String[] args) {
  52.         new GUI();
  53.     }
  54.  
  55.     @Override
  56.     public void actionPerformed(ActionEvent e) {
  57.         count++;
  58.         label.setText("Number of cookies: "+ count );
  59.  
  60.     }
  61. }
  62.  
  63. // Sources for this project (to make my french teacher happy):
  64. // Youtube Video of Alex Lee: https://www.youtube.com/watch?v=5o3fMLPY7qY
  65. // to place a cookie as the image for the button: https://stackoverflow.com/questions/4801386/how-do-i-add-an-image-to-a-jbutton
  66. // https://stackoverflow.com/questions/5657469/how-do-i-go-about-adding-an-image-into-a-java-project-with-eclipse
  67. // https://stackoverflow.com/questions/38046684/importing-images-into-eclipse
  68. // https://stackoverflow.com/questions/13594139/swing-change-image-with-a-button
  69. // to import an image on eclipse as a source
  70. // The famous cookie by Ryan Morrison JSY: https://pixabay.com/illustrations/cookies-food-dessert-biscuits-3551296/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement