Bienvenido: ( Identificarse | Registrarse )      
Foros de Trucos Windows
 
Closed TopicStart new topicStart Poll

Outline · [ Estándar ] · Lineal+

> Ambiguiedad con Timer y Date

blizknight
post Jul 31 2006, 01:09 AM
Publicado: #1


Maestro
*****

Grupo: Members
Mensajes: 265
Registrado: 12-September 04
Miembro nº: 18.538



hola rob, de nuevo molestandote XD
oie compilalo y mira lo que sale, yo lo probe en el proyecto4 que creo que tienes y no me andaba y me da el mismo error, lo pase a este que es mas chico para que se entienda y da el mismo error, creo que hay que definir el timer con toda su ruta , pero no se como hacerto

java.util.timer time= new java.util.timerd,,,,,, >> no se si ta bien, nunca aprendi a usarlo Y.Y

pero creo que necesita eso

saludos notengoidea.gif flowers.gif


CODE
/*
* Reloj.java
*/

/**
*
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Date;
import java.text.*;
import java.util.*; //agregue esta linea para lo del Gregorian calendar

public class Reloj extends JFrame
{

Date hora, fecha,f1,f2;
String patrón, mod;
JLabel jlbHoraActual, lbl;
JButton btn;
ActionListener al;
Timer timer1, timer2;  
SimpleDateFormat formato, format2;

 public Reloj()
 {
   jlbHoraActual = new JLabel();
   getContentPane().setLayout(null);
   setResizable(false);
   setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
   //jlbHoraActual.setFont(new Font("Arial", 1, 24));
   jlbHoraActual.setHorizontalAlignment(SwingConstants.CENTER);
   jlbHoraActual.setText("00:00:00");
   getContentPane().add(jlbHoraActual);
   jlbHoraActual.setBounds(40, 90, 210, 40);
   
   setSize(290, 260);
   
   lbl = new JLabel("");
   lbl.setBounds(40, 130, 210, 40);
   getContentPane().add(lbl);
   lbl.setBackground(Color.red);
   lbl.setOpaque(true);
   
   btn = new JButton("Time");
   btn.setBounds(40, 170, 210, 40);
   getContentPane().add(btn);
   
   
   
 

    al = new ActionListener()
   {
     public void actionPerformed(ActionEvent e)
    {
   
       onTimer();
     }
   };
   // Crear un temporizador e iniciarlo
   timer1 = new Timer(1000, al);
   timer1.start();
   //desde aqui inserto lo nuevo
   GregorianCalendar g = new GregorianCalendar();
  long horas = g.get(GregorianCalendar.HOUR_OF_DAY);
  long mins = g.get(GregorianCalendar.MINUTE);
   
   lbl.setText(horas + mins);
  //hasta aqui se inserto lo nuevo
  /* timer2 = new Timer(1000, al);
   timer2.start();*/
   
  }
 

 private void onTimer()
 {
   hora = new Date();
   patrón = "dd' de 'MMMM' del 'yy' 'hh:mm:ss";//dd:hh:mm:ss yy/mm/dd  dd.MMMMM.yy
   
 
   
   formato = new SimpleDateFormat(patrón);
   jlbHoraActual.setText(formato.format(hora));
   
   
   
   /*fecha = new Date();
   mod  = "dd' de 'MMMM' del 'yyyy ";
   
   format2 = new SimpleDateFormat(mod);
   lbl.setText(format2.format(fecha));*/
 }
 
 
 

 public static void main(String args[])
 {
   new Reloj().setVisible(true);
 }

}



User is online!Profile CardPM
Go to the top of the page
+Quote Post
rob1104
post Jul 31 2006, 05:10 PM
Publicado: #2


Xbox Live... The best thing ever happened around videogames
Group Icon

Grupo: Moderadores
Mensajes: 1.624
Registrado: 7-March 05
Desde: Matamoros, Tamaulipas, Mexico
Miembro nº: 93.342



Hola blizknight, el problema es qu existen dos clases con el mismo nombre pero en diferente paquete:
QUOTE
javax.swing.Timer
java.util.Timer


Usando la logica existen varias soluciones, pero esta es la mas sencilla

CODE
/*
* Reloj.java
*/

/**
*
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Date;
import java.text.*;
import java.util.GregorianCalendar; //agregue esta linea para lo del Gregorian calendar

public class Reloj extends JFrame
{

Date hora, fecha,f1,f2;
String patrón, mod;
JLabel jlbHoraActual, lbl;
JButton btn;
ActionListener al;
Timer timer1, timer2;  
SimpleDateFormat formato, format2;

public Reloj()
{
  jlbHoraActual = new JLabel();
  getContentPane().setLayout(null);
  setResizable(false);
  setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  //jlbHoraActual.setFont(new Font("Arial", 1, 24));
  jlbHoraActual.setHorizontalAlignment(SwingConstants.CENTER);
  jlbHoraActual.setText("00:00:00");
  getContentPane().add(jlbHoraActual);
  jlbHoraActual.setBounds(40, 90, 210, 40);
 
  setSize(290, 260);
 
  lbl = new JLabel("");
  lbl.setBounds(40, 130, 210, 40);
  getContentPane().add(lbl);
  lbl.setBackground(Color.red);
  lbl.setOpaque(true);
 
  btn = new JButton("Time");
  btn.setBounds(40, 170, 210, 40);
  getContentPane().add(btn);
 
 
 


   al = new ActionListener()
  {
    public void actionPerformed(ActionEvent e)
   {
 
      onTimer();
    }
  };
  // Crear un temporizador e iniciarlo
  timer1 = new Timer(1000, al);
  timer1.start();
  //desde aqui inserto lo nuevo
  GregorianCalendar g = new GregorianCalendar();
 long horas = g.get(GregorianCalendar.HOUR_OF_DAY);
 long mins = g.get(GregorianCalendar.MINUTE);
 
  lbl.setText(""+horas + mins);
 //hasta aqui se inserto lo nuevo
 /* timer2 = new Timer(1000, al);
  timer2.start();*/
 
 }


private void onTimer()
{
  hora = new Date();
  patrón = "dd' de 'MMMM' del 'yy' 'hh:mm:ss";//dd:hh:mm:ss yy/mm/dd  dd.MMMMM.yy
 

 
  formato = new SimpleDateFormat(patrón);
  jlbHoraActual.setText(formato.format(hora));
 
 
 
  /*fecha = new Date();
  mod  = "dd' de 'MMMM' del 'yyyy ";
 
  format2 = new SimpleDateFormat(mod);
  lbl.setText(format2.format(fecha));*/
}




public static void main(String args[])
{
  new Reloj().setVisible(true);
}

}


Saludos thumbsup.gif


User is offlineProfile CardPM
Go to the top of the page
+Quote Post

 
Closed TopicTopic OptionsStart new topic

Collapse

> Topicos similares

Timer-Applet - Alarma. K3RN3L P4N1C 410 0 Jan 11 2008, 01:17 AM
By: K3RN3L P4N1C
Como puedo crear un scrolling con un timer? almanake 263 0 Feb 27 2006, 08:31 PM
By: almanake
ayuda pa instalar sims - hot date luchi_3436 2.064 1 Nov 9 2005, 01:09 PM
By: Oxkr

Google
Web www.trucoswindows.net