package lt.bit.timeout; import javax.swing.*; import java.awt.*; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; public class Vykdymas { public static void main(String[] args) { JFrame f=new JFrame("Timer"); f.setSize(400,300); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); JTextField time=new JTextField("60"); JLabel timeOut=new JLabel("0.0", SwingConstants.CENTER); timeOut.setFont(new Font("Serif", Font.BOLD, 64)); JPanel p = new JPanel(); JButton start=new JButton("Start"); JButton pause=new JButton("Pause/Resume"); JButton restart=new JButton("Restart"); p.add(start); p.add(pause); p.add(restart); f.add(time, BorderLayout.PAGE_START); f.add(p, BorderLayout.PAGE_END); f.add(timeOut); f.setVisible(true); Timer t=new Timer(time, timeOut); t.start(); start.addActionListener((e)->{ t.startTimer(); }); pause.addActionListener((e)->{ t.pauseResume(); }); restart.addActionListener((e)->{ t.restart(); }); time.addActionListener((e)->{ t.startTimer(); }); /* time.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) { } @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode()==10 ){ t.startTimer(); } } @Override public void keyReleased(KeyEvent e) { } }); */ } }