Advertisement
silentkiler029

2

Oct 7th, 2021
792
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. package Practice;
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7.  
  8. public class Main {
  9.     private static int cnt = 3;
  10.     public static void main(String[] args) {
  11.         JFrame fr = new JFrame("Run!");
  12.         fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  13.         fr.setSize(250, 100);
  14.  
  15.         JLabel label = new JLabel();
  16.         JButton button = new JButton("Click!");
  17.  
  18.         button.addActionListener(new ActionListener() {
  19.             @Override
  20.             public void actionPerformed(ActionEvent e) {
  21.                 if( cnt == 3 ) {
  22.                     cnt = 2;
  23.                     label.setText("3...");
  24.                 }
  25.                 else if( cnt == 2 ) {
  26.                     cnt = 1;
  27.                     label.setText("2...");
  28.                 }
  29.                 else if( cnt == 1 ) {
  30.                     cnt = 0;
  31.                     label.setText("1...");
  32.                 }
  33.                 else if( cnt == 0 ) {
  34.                     cnt = 3;
  35.                     label.setText("GO!");
  36.                 }
  37.             }
  38.         });
  39.  
  40.         Container c = fr.getContentPane();
  41.         c.setLayout(new FlowLayout());
  42.         c.add(label);
  43.         c.add(button);
  44.  
  45.         fr.setVisible(true);
  46.     }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement