Opoe

Untitled

Apr 8th, 2011
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4. import java.util.Calendar;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import javax.swing.JButton;
  8. import javax.swing.JFrame;
  9. import javax.swing.JLabel;
  10. import javax.swing.JOptionPane;
  11. import javax.swing.JPanel;
  12. import javax.swing.JTextField;
  13. import java.awt.Color;
  14. import java.awt.Toolkit;
  15. import javax.swing.JFrame;
  16.  
  17.  
  18. class tryclock9 extends JFrame {
  19.  
  20.  
  21. private JTextField _textfield1;
  22.  
  23. public tryclock9() {
  24.  
  25. JFrame frame = new JFrame();
  26. _textfield1 = new JTextField(5);
  27. _textfield1.setEditable(false);
  28. JPanel panel1 = new JPanel();
  29. panel1.add(_textfield1);
  30. JButton button1 = new JButton("stop it!");
  31. JButton button2 = new JButton("start");
  32. JButton button3 = new JButton("previous frame!");
  33. JButton button4 = new JButton("next frame");
  34.  
  35.  
  36.  
  37. this.setTitle("Text Clock 1");
  38. this.setLocationRelativeTo(null);
  39. this.setResizable(true);
  40. panel1.add(button1);
  41. panel1.add(button2);
  42. panel1.add(button4);
  43. frame.setSize(600,400);
  44. frame.add (panel1);
  45. frame.setVisible(true);
  46.  
  47.  
  48.  
  49.  
  50. ClockListener cl = new ClockListener();
  51. final Timer t = new Timer(1000, cl);
  52.  
  53.  
  54. button1.addActionListener(new ActionListener() {
  55.  
  56. public void actionPerformed(ActionEvent arg0) {
  57.  
  58. t.stop();
  59. }
  60. });
  61.  
  62. button2.addActionListener(new ActionListener() {
  63.  
  64. public void actionPerformed(ActionEvent arg0) {
  65.  
  66. t.start();
  67. }
  68. });
  69. }
  70.  
  71.  
  72.  
  73. class ClockListener implements ActionListener {
  74.  
  75. int count = 0;
  76.  
  77. public void actionPerformed(ActionEvent e) {
  78.  
  79. int fakeSecond = (count++ % 4) + 1;
  80. if (fakeSecond == 2) { System.out.println( "Hello, World!" );
  81.  
  82. }
  83. Calendar now = Calendar.getInstance();
  84. int h = now.get(Calendar.HOUR_OF_DAY);
  85. int m = now.get(Calendar.MINUTE);
  86. int s = now.get(Calendar.SECOND);
  87. _textfield1.setText("" + fakeSecond + "");
  88.  
  89.  
  90. }
  91.  
  92.  
  93. }
  94.  
  95.  
  96.  
  97.  
  98. public static void main(String[] args) {
  99. JFrame clock = new tryclock9();
  100. clock.setVisible(true);
  101. }
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment