Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Font;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.ImageIcon;
- import static javax.swing.UIManager.get;
- /**
- *
- * @author david
- */
- public class CLickerTest2 {
- JLabel counterLabel, perSeclabel;
- int cookieCounter;
- Font font1,font2;
- CookieHandler cHandler= new CookieHandler();
- public static void main(String[] args) {
- new CLickerTest2();
- }
- public CLickerTest2(){
- cookieCounter=0;
- createFont();
- createUI();
- }
- public void createFont(){
- font1=new Font("Comic Sans MS",Font.PLAIN,32);
- font2 =new Font("Comic Sans MS",Font.PLAIN,15);
- }
- public void createUI(){
- JFrame window = new JFrame();
- window.setSize(1200,800);
- window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- window.getContentPane().setBackground(Color.black);
- window.setLayout(null);
- JPanel cookiePanel= new JPanel();
- cookiePanel.setBounds(100, 220, 200, 200);
- cookiePanel.setBackground(Color.black);
- window.add(cookiePanel);
- ImageIcon cookie;
- cookie = new ImageIcon(getClass().getClassLoader().getResource("richtigercookie.png"));
- JButton cookieButton =new JButton();
- cookieButton.setBackground(Color.black);
- cookieButton.setFocusPainted(false);
- cookieButton.setBorder(null);
- cookieButton.setIcon(cookie);
- cookieButton.addActionListener(cHandler);
- cookiePanel.add(cookieButton);
- JPanel counterPanel = new JPanel();
- counterPanel.setBounds(100,100,200,100);
- counterPanel.setBackground(Color.black);
- counterPanel.setLayout(new GridLayout(2,1));
- window.add(counterPanel);
- counterLabel= new JLabel(cookieCounter+ " Kekse");
- counterLabel.setForeground(Color.white);
- counterLabel.setFont(font1);
- counterPanel.add(counterLabel);
- JLabel perSecLabel = new JLabel();
- perSecLabel.setForeground(Color.white);
- perSecLabel.setFont(font2);
- counterPanel.add(perSecLabel);
- window.setVisible(true);
- }
- public class CookieHandler implements ActionListener{
- /**
- *
- * @param event
- */
- @Override
- public void actionPerformed(ActionEvent event){
- cookieCounter++;
- counterLabel.setText(cookieCounter+ " Kekse");
- }}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement