Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 KB | None | 0 0
  1. package income;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.Canvas;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7.  
  8. import javax.swing.JButton;
  9. import javax.swing.JFrame;
  10. import javax.swing.JLabel;
  11. import javax.swing.JPanel;
  12.  
  13. public class passive extends Canvas implements Runnable  {
  14.     public boolean running = false;
  15.     public static int money;
  16.     public passive(){
  17.         JFrame frame = new JFrame();
  18.         JButton button = new JButton("Click me for money!");
  19.         JPanel panel = new JPanel();
  20.         JLabel cash = new JLabel("You have " + money + "$");
  21.        
  22.        
  23.         button.setVisible(true);
  24.         frame.setVisible(true);
  25.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  26.         frame.setTitle("Clicker");
  27.         frame.setSize(400, 400);
  28.         frame.setLayout(new BorderLayout());
  29.         frame.add(this, BorderLayout.CENTER);
  30.         frame.add(panel);
  31.         panel.add(cash);
  32.        
  33.         panel.setSize(200, 200);
  34.         panel.add(button);
  35.     }
  36.        
  37.        
  38.     static class Action implements ActionListener {
  39.        
  40.         public void actionPerformed (ActionEvent e) {
  41.             money += 1;
  42.         }
  43.     }
  44.    
  45.     public static void delay(int millis) {
  46.         try {
  47.             Thread.sleep(millis);
  48.         } catch (InterruptedException exp) {
  49.            
  50.         }
  51.     }
  52.     public synchronized void start() {
  53.         running = true;
  54.         new Thread(this).start();
  55.     }
  56.    
  57.     public synchronized void stop() {
  58.         running = false;
  59.     }
  60.  
  61.     @Override
  62.     public void run() {
  63.     int time;
  64.     time = 1;
  65.     while(running) {
  66.     System.out.println(money);
  67.     delay(1000);
  68.     money += 1;
  69.         }
  70.     }
  71.  
  72.  
  73.     public static void main(String[] args) {
  74.         new passive().start();
  75.        
  76.         }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement