Opoe

Untitled

Apr 3rd, 2011
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 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.         final Toolkit tk = Toolkit.getDefaultToolkit();tk.beep();
  31.        
  32.        
  33.         this.setContentPane(panel1);
  34.         this.setTitle("Text Clock 1");
  35.         this.pack();
  36.         this.setLocationRelativeTo(null);
  37.         this.setResizable(true);
  38.         panel1.add(button1);
  39.        
  40.          javax.swing.Timer t = new javax.swing.Timer(1000, new ClockListener());
  41.         ClockListener cl = new ClockListener();
  42.         Timer t = new Timer(1000, cl);
  43.         t.start();
  44.         if (cl.count == 2) { t.stop(); }
  45.  
  46.             }
  47.    
  48.  
  49.        
  50. class ClockListener implements ActionListener {
  51.     int count = 0;
  52.    
  53.     public void actionPerformed(ActionEvent e) {
  54.         int fakeSecond = (count++ % 4) + 1;
  55.         Calendar now = Calendar.getInstance();
  56.         int h = now.get(Calendar.HOUR_OF_DAY);
  57.         int m = now.get(Calendar.MINUTE);
  58.         int s = now.get(Calendar.SECOND);
  59.         _textfield1.setText("" + fakeSecond + "");
  60.    
  61.    
  62.     }
  63.      
  64. }
  65.  
  66.  
  67.    
  68.  
  69.     public static void main(String[] args) {
  70.         JFrame clock = new clockexample1();
  71.         clock.setVisible(true);
  72.     }
  73.    
  74. }
Advertisement
Add Comment
Please, Sign In to add comment