Advertisement
Opoe

if statement

Apr 3rd, 2011
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.75 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.         t.start();
  42.             }
  43.    
  44.  
  45.        
  46. class ClockListener implements ActionListener {
  47.     int count = 0;
  48.    
  49.     public void actionPerformed(ActionEvent e) {
  50.         int fakeSecond = (count++ % 4) + 1;
  51.         Calendar now = Calendar.getInstance();
  52.         int h = now.get(Calendar.HOUR_OF_DAY);
  53.         int m = now.get(Calendar.MINUTE);
  54.         int s = now.get(Calendar.SECOND);
  55.         _textfield1.setText("" + fakeSecond + "");
  56.    
  57.    
  58.     }
  59.      
  60. }
  61.  
  62.  
  63.    
  64.  
  65.     public static void main(String[] args) {
  66.         JFrame clock = new clockexample1();
  67.         clock.setVisible(true);
  68.     }
  69.    
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement