Opoe

Untitled

Apr 12th, 2011
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 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.  
  16.  
  17. class clockExample1 extends JFrame {
  18.  
  19.  
  20. private JTextField _textfield1;
  21.  
  22. public clockExample1() {
  23.  
  24. _textfield1 = new JTextField(5);
  25. _textfield1.setEditable(false);
  26. JPanel panel1 = new JPanel();
  27. panel1.setLayout(new FlowLayout());
  28. panel1.add(_textfield1);
  29. JButton button1 = new JButton("click here");
  30.  
  31.  
  32. this.setContentPane(panel1);
  33. this.setTitle("Text Clock 1");
  34. this.pack();
  35. this.setLocationRelativeTo(null);
  36. this.setResizable(true);
  37. panel1.add(button1);
  38.  
  39.  
  40.  
  41.  
  42. ClockListener cl = new ClockListener();
  43. Timer t = new Timer(1000, cl);
  44. t.start();
  45.  
  46.  
  47. }
  48.  
  49.  
  50.  
  51. class ClockListener implements ActionListener {
  52.  
  53. int count = 0;
  54.  
  55. public void actionPerformed(ActionEvent e) {
  56.  
  57. int fakeSecond = (count++ % 4) + 1;
  58. if (fakeSecond == 1) { System.out.println( "Hello, World!" );
  59.  
  60. }
  61. Calendar now = Calendar.getInstance();
  62. int h = now.get(Calendar.HOUR_OF_DAY);
  63. int m = now.get(Calendar.MINUTE);
  64. int s = now.get(Calendar.SECOND);
  65. _textfield1.setText("" + fakeSecond + "");
  66.  
  67.  
  68. }
  69.  
  70.  
  71. }
  72.  
  73.  
  74.  
  75.  
  76. public static void main(String[] args) {
  77. JFrame clock = new clockExample1();
  78. clock.setVisible(true);
  79. }
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment