Manual Proyecto Cronometro

Páginas: 6 (1287 palabras) Publicado: 26 de mayo de 2013






























Definición.
El cronómetro es un reloj cuya precisión ha sido comprobada y certificada por algún instituto o centro de control de precisión. 
Práctica.
La práctica consiste en hacer un código que genere un cronometro con minutos, segundos y milisegundos que tenga la función de poder arrancar, detener, continuar y reiniciar sinninguna dificultad.
Herramientas.
En clase se ha proporcionado el método de Thread los cuales nos ayudaran a construir nuestro programa ya que Un hilo es una secuencia de instrucciones que está controlada por un planificador que se comporta como un flujo de control secuencial. El planificador gestiona el tiempo de ejecución del procesador y asigna de alguna manera dicho tiempo a los diferentes hilosactualmente presentes.









Código fuente.
1 ÏÏÏimport java.awt.BorderLayout;
2 ÏÏÏimport java.awt.Color;
3 ÏÏÏimport java.awt.Font;
4 ÏÏÏimport java.awt.event.ActionEvent;
5 ÏÏÏimport java.awt.event.ActionListener;
6 ÏÏÏimport javax.swing.JButton;
7 ÏÏÏimport javax.swing.JFrame;
8 ÏÏÏimport javax.swing.JLabel;
9 ÏÏÏimport javax.swing.UIManager;
10 ÏÏÏ11 ÏÕÖ×public class Cronometro extends JFrame implements Runnable, ActionListener {
12 ÏϧÏÞßàpublic Cronometro()
13 ÏϧÏϧ{
14 ÏϧÏϨ¹¹ÏsetTitle("Cronometro");
15 ÏϧÏϨ¹¹ÏsetSize( 500, 300 );
16 ÏϧÏϨ¹¹ÏsetDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
17 ÏϧÏϨ¹¹ÏsetLayout(null);
18 ÏϧÏϨ¹¹Ïtiempo = new JLabel( "00:00:000" );
19 ÏϧÏϨ¹¹Ïtiempo.setFont( new Font(Font.SERIF, Font.PLAIN, 60 ) );
20 ÏϧÏϨ¹¹Ïtiempo.setHorizontalAlignment( JLabel.CENTER );
21 ÏϧÏϨ¹¹Ïtiempo.setForeground( Color.CYAN );
22 ÏϧÏϨ¹¹Ïtiempo.setBackground( Color.BLACK );
23 ÏϧÏϨ¹¹Ïtiempo.setOpaque( true );
24 ÏϧÏϨ¹¹Ïtiempo.setBounds(80,10,300,50);
25 ÏϧÏϨ¹¹Ïadd(tiempo);
26 ÏϧÏϧ
27 ÏϧÏϨ¹íÏJButton btn = new JButton( "Iniciar" );
28ÏϧÏϨ¹¹Ïbtn.addActionListener( this );
29 ÏϧÏϨ¹¹Ïbtn.setFont( new Font( Font.SERIF, Font.ITALIC, 20 ) );
30 ÏϧÏϨ¹¹Ïbtn.setBounds(60,100,150,50);
31 ÏϧÏϨ¹¹Ïadd(btn);
32 ÏϧÏϧ
33 ÏϧÏϨ¹íÏJButton btnP = new JButton( "Reiniciar" );
34 ÏϧÏϨ¹¹ÏbtnP.addActionListener( this );
35 ÏϧÏϧ
36 ÏϧÏϨ¹¹ÏbtnP.setFont( new Font( Font.SERIF, Font.ITALIC, 20 ) );
37 ÏϧÏϨ¹¹ÏbtnP.setBounds(230,180,150,50);38 ÏϧÏϨ¹¹Ïadd(btnP);
39 ÏϧÏϧ
40 ÏϧÏϨ¹íÏJButton btnR = new JButton( "Detener" );
41 ÏϧÏϨ¹¹ÏbtnR.addActionListener( this );
42 ÏϧÏϨ¹¹ÏbtnR.setFont( new Font( Font.SERIF, Font.ITALIC, 20 ) );
43 ÏϧÏϨ¹¹ÏbtnR.setBounds(230,100,150,50);
44 ÏϧÏϨ¹¹Ïadd(btnR);
45 ÏϧÏϧ
46 ÏϧÏϨ¹íÏJButton btnC = new JButton( "Continuar" );
47 ÏϧÏϨ¹¹ÏbtnC.addActionListener( this );48 ÏϧÏϨ¹¹ÏbtnC.setFont( new Font( Font.SERIF, Font.ITALIC, 20 ) );
49 ÏϧÏϨ¹¹ÏbtnC.setBounds(60,180,150,50);
50 ÏϧÏϨ¹¹Ïadd(btnC);
51 ÏϧÏϨ¹¹Ïthis.setLocationRelativeTo( null );
52 ÏϧÏϨ¹¹ÏsetVisible( true );
53 ÏϧÏÏ©}
54 Ïϧ
55 ÏϧÏÞßàpublic void run(){
56 ÏϧÏϨ¹íÏInteger minutos = 0 , segundos = 0, milesimas = 0;
57 ÏϧÏϨ¹íÏString min="", seg="", mil="";
58ÏϧÏϨ¹¹´try
59 ÏϧÏϧÏ6§{
60 ÏϧÏϧÏ6¨¹¹±while( cronometroActivo )
61 ÏϧÏϧÏ6§ÏÏ5{
62 ÏϧÏϧÏ6§ÏÏ7¹¹ÏThread.sleep( 4 );
63 ÏϧÏϧÏ6§ÏÏ7¹¹Ïmilesimas += 4;
64 ÏϧÏϧÏ6§ÏÏ5
65 ÏϧÏϧÏ6§ÏÏ7¹³´if( milesimas == 1000 )
66 ÏϧÏϧÏ6§ÏÏ5Ï6§{
67 ÏϧÏϧÏ6§ÏÏ5Ï6¨¹¹Ïmilesimas = 0;
68 ÏϧÏϧÏ6§ÏÏ5Ï6¨¹¹Ïsegundos += 1;
69 ÏϧÏϧÏ6§ÏÏ5Ï6§
70 ÏϧÏϧÏ6§ÏÏ5Ï6§
71 ÏϧÏϧÏ6§ÏÏ5Ï6¾¹³´if( segundos ==60 )
72 ÏϧÏϧÏ6§ÏÏ5Ï6ÏÏ6§{
73 ÏϧÏϧÏ6§ÏÏ5Ï6ÏÏ6¨¹¹Ïsegundos = 0;
74 ÏϧÏϧÏ6§ÏÏ5Ï6ÏÏ6¾¹¹Ïminutos++;
75 ÏϧÏϧÏ6§ÏÏ5Ï6Ï϶Ï}
76 ÏϧÏϧÏ6§ÏÏ5϶Ï}
77 ÏϧÏϧÏ6§ÏÏ5
78 ÏϧÏϧÏ6§ÏÏ7¹³¹if( minutos < 10 ) min = "0" + minutos;
79 ÏϧÏϧÏ6§ÏÏ5Ïö¹else min = minutos.toString();
80 ÏϧÏϧÏ6§ÏÏ7¹³¹if( segundos < 10 ) seg = "0" + segundos;
81 ÏϧÏϧÏ6§ÏÏ5Ïö¹else seg =...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Manual de proyecto
  • proyecto de manualidades
  • PROYECTO DE MANUALIDADES
  • proyecto de manualidades
  • Proyecto de manualidades
  • Manual de proyectos
  • Manual de proyecto
  • MANUAL DEL PROYECTISTA

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS