import java.awt.*; 
import java.awt.event.*; 
import javax.swing.*;

// A terrible program. Intended as a bad example.
// The thread running main will probably never see changes to x.

public class ST5 extends JFrame implements ActionListener{
    int x = 0;

    public void setX(int x) {
        this.x = x;
    }

    public int getX() {
        return x;
    }

    public ST5 () {
        JPanel pane = new JPanel();
        JButton knapp1 = new JButton ("Blip");
        JButton knapp2 = new JButton ("Blup");


        knapp1.addActionListener(this);
        knapp2.addActionListener(this);
        pane.add(knapp1);
        pane.add(knapp2);
        add(pane);

        setBounds(100,100,300,200);
	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        setVisible(true);

    }

    public void actionPerformed(ActionEvent event) {
        System.out.println(((JButton)event.getSource()).getText());
        x = x +1;
        System.out.println("Frame: x is now "+x);
    }

    public static void main(String[] arg) {
        ST5 frame = new ST5();
        int y = frame.getX();
        while (true) {
            if (y != frame.getX()) {
                y = frame.getX();
                System.out.println("Main: x is now "+y);
            }
        }
    }
}

            
