laman

Rabu, 21 Desember 2011

Test thread

public class SimpleGUITester {

    /** Creates a new instance of SimpleGUITester */
    public SimpleGUITester() {
    }

    public static void main(String[] args) {
        SimpleGUI test = new SimpleGUI();
    }
}
 -------------------------------------------------------------------------------------
public class SimpleGUI extends JFrame {

    private JButton clickButton, stopButton;
    private JLabel counterLabel;
    private Counter counter;

    /** Creates a new instance of SimpleGUI */
    public SimpleGUI() {
        clickButton = new JButton("Start");
        stopButton = new JButton("Stop");
        counterLabel = new JLabel("Counter: ");
        this.setLayout(new FlowLayout());
        this.add(clickButton);
        this.add(counterLabel);
        this.add(stopButton);
        this.setTitle("Thread application");
        this.setSize(500, 100);
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        clickButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                clickAction();
            }
        });
        stopButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                stopAction();
            }
        });
    }

    public void clickAction() {
        counter = new Counter(counterLabel);
    }

    public void stopAction() {
        counter.setStart(false);
    }
}

Tidak ada komentar:

Posting Komentar