Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.cookieclicker;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.JButton;
- import java.awt.CardLayout;
- import java.awt.Color;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- public class Frame extends JFrame implements ActionListener{
- private JButton click;
- private JButton shop;
- JPanel panelCont = new JPanel(); //Panel
- JPanel panelMain = new JPanel(); //Panel
- JPanel panelShop = new JPanel(); //Panel
- CardLayout cl = new CardLayout(); //Panel
- int counter;
- public static void main(String[] args) {
- new Frame("Cookie Clicker");
- }
- @SuppressWarnings("deprecation")
- public Frame(String title) {
- super(title);
- panelCont.setLayout(cl); //Panel
- click = new JButton("Click");
- click.setBounds(175, 300, 150, 30);
- click.addActionListener(this);
- add(click);
- panelMain.add(click); //Panel
- shop = new JButton("Shop");
- shop.setBounds(-1, 437, 500, 25);
- shop.addActionListener(this);
- add(shop);
- panelMain.add(shop); //Panel
- panelCont.add(panelMain, "1"); //Panel
- panelCont.add(panelShop, "2"); //Panel
- cl.show(panelCont, "1"); //Panel
- panelMain.setBackground(Color.RED);
- this.setSize(500, 500);
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- this.setLayout(null);
- this.setVisible(true);
- this.add(panelCont); //Panel
- }
- public void actionPerformed(ActionEvent e) {
- if (e.getSource() == click) {
- zaehler();
- } else if (e.getSource() == shop) {
- cl.show(panelCont, "2"); //Panel
- }
- }
- public void zaehler() {
- counter++;
- System.out.println("Counter: " + counter);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement