Opoe

Untitled

Apr 3rd, 2011
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.83 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 tryclock4 extends JFrame {
  18.    
  19.  
  20.     private JTextField _textfield1;
  21.  
  22.     public tryclock4() {
  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.        
  41.         ClockListener cl = new ClockListener();
  42.         Timer t = new Timer(1000, cl);
  43.         t.start();
  44.        
  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.         if (fakeSecond == 2) {  System.out.println( "Hello, World!" );
  56.  }
  57.         Calendar now = Calendar.getInstance();
  58.         int h = now.get(Calendar.HOUR_OF_DAY);
  59.         int m = now.get(Calendar.MINUTE);
  60.         int s = now.get(Calendar.SECOND);
  61.         _textfield1.setText("" + fakeSecond + "");
  62.    
  63.    
  64.     }
  65.    
  66.      
  67. }
  68.  
  69.  
  70.    
  71.  
  72.     public static void main(String[] args) {
  73.         JFrame clock = new tryclock4();
  74.         clock.setVisible(true);
  75.     }
  76.    
  77. }
Advertisement
Add Comment
Please, Sign In to add comment