import javax.swing.*; import java.awt.BorderLayout; import java.awt.event.*; public class TimerTest5 extends JFrame implements ActionListener{ Timer timer; JLabel label; JButton startButton; public static void main(String[] args){ TimerTest5 frame = new TimerTest5(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setBounds(10, 10, 300, 200); frame.setTitle("ƒ^ƒCƒgƒ‹"); frame.setVisible(true); } TimerTest5(){ label = new JLabel(); JPanel labelPanel = new JPanel(); labelPanel.add(label); timer = new Timer(1000 , this); timer.setRepeats(false); startButton = new JButton("start"); startButton.addActionListener(this); startButton.setActionCommand("start"); JPanel buttonPanel = new JPanel(); buttonPanel.add(startButton); getContentPane().add(labelPanel, BorderLayout.CENTER); getContentPane().add(buttonPanel, BorderLayout.PAGE_END); } public void actionPerformed(ActionEvent e){ if (e.getSource() == timer){ label.setText("Timer Action"); }else if (e.getSource() == startButton){ timer.start(); } }