Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package income;
- import java.awt.BorderLayout;
- import java.awt.Canvas;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- public class passive extends Canvas implements Runnable {
- public boolean running = false;
- public static int money;
- public passive(){
- JFrame frame = new JFrame();
- JButton button = new JButton("Click me for money!");
- JPanel panel = new JPanel();
- JLabel cash = new JLabel("You have " + money + "$");
- button.setVisible(true);
- frame.setVisible(true);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setTitle("Clicker");
- frame.setSize(400, 400);
- frame.setLayout(new BorderLayout());
- frame.add(this, BorderLayout.CENTER);
- frame.add(panel);
- panel.add(cash);
- panel.setSize(200, 200);
- panel.add(button);
- }
- static class Action implements ActionListener {
- public void actionPerformed (ActionEvent e) {
- money += 1;
- }
- }
- public static void delay(int millis) {
- try {
- Thread.sleep(millis);
- } catch (InterruptedException exp) {
- }
- }
- public synchronized void start() {
- running = true;
- new Thread(this).start();
- }
- public synchronized void stop() {
- running = false;
- }
- @Override
- public void run() {
- int time;
- time = 1;
- while(running) {
- System.out.println(money);
- delay(1000);
- money += 1;
- }
- }
- public static void main(String[] args) {
- new passive().start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement