Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Practice;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- public class Main {
- private static int cnt = 3;
- public static void main(String[] args) {
- JFrame fr = new JFrame("Run!");
- fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- fr.setSize(250, 100);
- JLabel label = new JLabel();
- JButton button = new JButton("Click!");
- button.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- if( cnt == 3 ) {
- cnt = 2;
- label.setText("3...");
- }
- else if( cnt == 2 ) {
- cnt = 1;
- label.setText("2...");
- }
- else if( cnt == 1 ) {
- cnt = 0;
- label.setText("1...");
- }
- else if( cnt == 0 ) {
- cnt = 3;
- label.setText("GO!");
- }
- }
- });
- Container c = fr.getContentPane();
- c.setLayout(new FlowLayout());
- c.add(label);
- c.add(button);
- fr.setVisible(true);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement