Advertisement
Pr1smZ

ABC

Feb 23rd, 2024
902
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.35 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Font;
  3. import javax.swing.JButton;
  4. import javax.swing.JFrame;
  5. import javax.swing.JLabel;
  6. import javax.swing.JPanel;
  7. import java.awt.GridLayout;
  8. import java.awt.event.ActionEvent;
  9. import java.awt.event.ActionListener;
  10. import javax.swing.ImageIcon;
  11. import static javax.swing.UIManager.get;
  12.  
  13. /**
  14. *
  15. * @author david
  16. */
  17. public class CLickerTest2 {
  18. JLabel counterLabel, perSeclabel;
  19. int cookieCounter;  
  20. Font font1,font2;
  21. CookieHandler cHandler= new CookieHandler();
  22. public static void main(String[] args) {
  23.  
  24.         new CLickerTest2();        
  25.     }
  26.    
  27.     public CLickerTest2(){
  28.         cookieCounter=0;
  29.        
  30.         createFont();
  31.         createUI();
  32. }
  33.     public void createFont(){
  34.     font1=new Font("Comic Sans MS",Font.PLAIN,32);
  35.     font2 =new Font("Comic Sans MS",Font.PLAIN,15);
  36.     }
  37. public void createUI(){
  38. JFrame window = new JFrame();
  39. window.setSize(1200,800);
  40. window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  41. window.getContentPane().setBackground(Color.black);
  42. window.setLayout(null);
  43.  
  44. JPanel cookiePanel= new JPanel();
  45. cookiePanel.setBounds(100, 220, 200, 200);
  46. cookiePanel.setBackground(Color.black);
  47. window.add(cookiePanel);
  48.  
  49.  
  50. ImageIcon cookie;
  51.     cookie = new ImageIcon(getClass().getClassLoader().getResource("richtigercookie.png"));
  52.  
  53. JButton cookieButton =new JButton();
  54. cookieButton.setBackground(Color.black);
  55. cookieButton.setFocusPainted(false);
  56. cookieButton.setBorder(null);
  57. cookieButton.setIcon(cookie);
  58. cookieButton.addActionListener(cHandler);
  59. cookiePanel.add(cookieButton);
  60.  
  61.  
  62. JPanel counterPanel = new JPanel();
  63. counterPanel.setBounds(100,100,200,100);
  64. counterPanel.setBackground(Color.black);
  65. counterPanel.setLayout(new GridLayout(2,1));
  66. window.add(counterPanel);
  67.  
  68. counterLabel= new JLabel(cookieCounter+ " Kekse");
  69. counterLabel.setForeground(Color.white);
  70. counterLabel.setFont(font1);
  71. counterPanel.add(counterLabel);
  72.  
  73.     JLabel perSecLabel = new JLabel();
  74. perSecLabel.setForeground(Color.white);
  75. perSecLabel.setFont(font2);
  76. counterPanel.add(perSecLabel);
  77.  
  78. window.setVisible(true);
  79. }
  80.  
  81. public  class CookieHandler implements ActionListener{
  82.  
  83.     /**
  84.      *
  85.      * @param event
  86.      */
  87.     @Override
  88.     public void actionPerformed(ActionEvent event){
  89.         cookieCounter++;
  90.         counterLabel.setText(cookieCounter+ " Kekse");
  91.     }}
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement