elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: AIO elhacker.NET 2021 Compilación herramientas análisis y desinfección malware


  Mostrar Temas
Páginas: [1]
1  Programación / Java / Crear Programa Activacion De Licencia En Java Netbeans en: 29 Octubre 2019, 05:36 am
Hola, estoy creando una aplicacion en netbeans para activar un programa, cree un contador para poner los dias que estara activo el programa, pero mi problema es que al momento de cerrar el jframe hice que detuviera el tiempo del contador y lo guardara en un txt, pero a la hora de llamar los minutos y segundos del txt solo lo imprime pero no lo inicializa.
Espero y puedan ayudarme.

Aqui el codigo :

Código
  1.  
  2.    private Timer t;
  3.    private int M = 0, S = 0;
  4.  
  5.    File Guardar = new File("C:\\Users\\Admin\\Downloads\\Tiempo.txt");
  6.  
  7.    private ActionListener acciones = new ActionListener(){
  8.  
  9.        @Override
  10.        public void actionPerformed(ActionEvent ae) {
  11.  
  12.            S--;
  13.            if( S == -1){
  14.                M = M - 1;
  15.                S = 60;
  16.            }if( M == -1){
  17.                M = 5;
  18.                S = S - 0;
  19.            }if( M == 1 && S == 1){
  20.                Lbl_Aviso.setText("Tu Licencia Esta Por Expirar");
  21.            }if( M == 0 && S == 1){
  22.                Lbl_Aviso.setText("Tu Licencia Expiro");
  23.                M = 0; S = 0;
  24.                t.stop();
  25.                Pasar();
  26.            }
  27.            Actualizar();
  28.        }
  29.    };
  30.  
  31.    public Crono() {
  32.        initComponents();
  33.        this.setLocationRelativeTo(null);
  34.        t = new Timer(1000, acciones);
  35.        if( t.isRunning()){
  36.        t.stop();
  37.        Cargar();
  38.        Actualizar();
  39.        t = new Timer(1000, acciones);
  40.        t.start();
  41.        }else{
  42.        t.start();
  43.        }
  44.    }
  45.  
  46.    Conectar cc = new Conectar();
  47.    Connection cn = cc.conexion();
  48.  
  49.    ResultSet rs;
  50.  
  51.  
  52.    public void Guardar(){
  53.        try{
  54.            if(!Guardar.exists()){
  55.                    Guardar.createNewFile();
  56.            }{
  57.            BufferedWriter BW = new BufferedWriter(new FileWriter(Guardar.getAbsolutePath()));
  58.            BW.write(Lbl_Cronometro.getText());
  59.            BW.close();
  60.            }
  61.  
  62.        } catch (IOException ex) {
  63.                    ex.getMessage();
  64.        }
  65.    }
  66.  
  67.    private void Cargar(){
  68.        try {
  69.            if (Guardar.exists()){
  70.  
  71.            Scanner sc = new Scanner(Guardar);
  72.  
  73.            Lbl_Cronometro.setText(sc.nextLine());
  74.            sc.close();
  75.            }
  76.         } catch (FileNotFoundException ex) {
  77.                ex.getMessage();
  78.        }
  79.    }
  80.  
  81.    private void Actualizar() {
  82.        String Tiempo = ( M+" : "+S);
  83.        Lbl_Cronometro.setText(Tiempo);
  84.    }
  85.  
  86. private void Lbl_SalirMouseClicked(java.awt.event.MouseEvent evt) {
  87.        if(t.isRunning())
  88.        {
  89.            t.stop();
  90.            Guardar();
  91.            System.exit(0);
  92.        }
  93.    }
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines