Advertisement
Guest User

Java Problem

a guest
Jan 23rd, 2016
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. package de.cookieclicker;
  2.  
  3. import javax.swing.JFrame;
  4. import javax.swing.JPanel;
  5. import javax.swing.JButton;
  6. import java.awt.CardLayout;
  7. import java.awt.Color;
  8. import java.awt.event.ActionEvent;
  9. import java.awt.event.ActionListener;
  10.  
  11.  
  12.  
  13. public class Frame extends JFrame implements ActionListener{
  14.  
  15. private JButton click;
  16. private JButton shop;
  17.  
  18. JPanel panelCont = new JPanel(); //Panel
  19. JPanel panelMain = new JPanel(); //Panel
  20. JPanel panelShop = new JPanel(); //Panel
  21.  
  22. CardLayout cl = new CardLayout(); //Panel
  23.  
  24. int counter;
  25.  
  26. public static void main(String[] args) {
  27. new Frame("Cookie Clicker");
  28.  
  29. }
  30.  
  31. @SuppressWarnings("deprecation")
  32. public Frame(String title) {
  33. super(title);
  34.  
  35. panelCont.setLayout(cl); //Panel
  36.  
  37. click = new JButton("Click");
  38. click.setBounds(175, 300, 150, 30);
  39. click.addActionListener(this);
  40. add(click);
  41. panelMain.add(click); //Panel
  42.  
  43. shop = new JButton("Shop");
  44. shop.setBounds(-1, 437, 500, 25);
  45. shop.addActionListener(this);
  46. add(shop);
  47. panelMain.add(shop); //Panel
  48.  
  49. panelCont.add(panelMain, "1"); //Panel
  50. panelCont.add(panelShop, "2"); //Panel
  51. cl.show(panelCont, "1"); //Panel
  52.  
  53. panelMain.setBackground(Color.RED);
  54.  
  55. this.setSize(500, 500);
  56. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  57. this.setLayout(null);
  58. this.setVisible(true);
  59. this.add(panelCont); //Panel
  60.  
  61. }
  62.  
  63. public void actionPerformed(ActionEvent e) {
  64. if (e.getSource() == click) {
  65. zaehler();
  66.  
  67. } else if (e.getSource() == shop) {
  68. cl.show(panelCont, "2"); //Panel
  69. }
  70. }
  71.  
  72. public void zaehler() {
  73. counter++;
  74. System.out.println("Counter: " + counter);
  75.  
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement