Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Test4 extends JPanel {
- static int count = 0;
- static Timer timer;
- public static void main(String[] args) {
- JFrame frame = new JFrame("Gui");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- Container contentPane = frame.getContentPane();
- contentPane.setLayout ( new BorderLayout () );
- int timerSpeed = 1; //1 милисекунда
- ActionListener al = (ActionEvent e) -> {
- System.out.println("W");
- if (count > 10000)
- {
- timer.stop(); //По достижении 10 секунд таймер должен остановиться
- }
- count++;
- };
- timer = new Timer(timerSpeed, al);
- timer.start();
- frame.setSize(new Dimension(200, 200));
- frame.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement