Java - PROBLEMA ACTUALIZAR VALOR DE UN JLABEL DENTRO DE UNA TABLA, quiero

 
Vista:
sin imagen de perfil

PROBLEMA ACTUALIZAR VALOR DE UN JLABEL DENTRO DE UNA TABLA, quiero

Publicado por hernan (1 intervención) el 02/03/2018 18:24:39
Hola buenos dias, gracias anticipadas por el aporte.
Sucede que estoy haciendo un aplicativo para controlar las horas de una cabina de internet, en una de sus columnas agrego jlabel, para que aqui me muestre lo minutos en tiempo regresivo, asu vez queria que se actualice constantemente cada segundo mostrando los minutos que le queda en cada pc.
FRAME-PRINCIPAL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
public class Tabla {
 
    public ArrayList<Pc> listPc = new ArrayList<>();
//    JLabel lblTiempoRest = new JLabel();
    //Tiempos[] t = new Tiempos[15];
    Connection con;
    Tiempos t;   //clase de hilo
    Pc pc;
 
    public void ver_tabla(JTable tabla) {
        con = Conectar.getConexion();
        tabla.setDefaultRenderer(Object.class, new Render());
        String[] titulo = {"ID", "PC", "H. INCIO", "H. SALIDA", "TIEMPO TOT.", "PAGO", "T. RESTANTE", "CONTINUAR", "SALIR"};
        DefaultTableModel modelo = new DefaultTableModel(null, titulo) {
            public boolean isCellEditable(int row, int column) {//bloquear edicion
                return false;
            }
        };
        tabla.setModel(modelo);
        tabla.setRowHeight(30);
        tabla.setPreferredScrollableViewportSize(tabla.getPreferredSize());
        tabla.getColumnModel().getColumn(0).setPreferredWidth(25);
        tabla.getColumnModel().getColumn(1).setPreferredWidth(80);
        tabla.getColumnModel().getColumn(2).setPreferredWidth(100);
        tabla.getColumnModel().getColumn(3).setPreferredWidth(80);
        tabla.getColumnModel().getColumn(4).setPreferredWidth(100);
        tabla.getColumnModel().getColumn(5).setPreferredWidth(40);
 
        JLabel lblTimeRestante = new JLabel("00:00:00");
        lblTimeRestante.setName("lblTrest");
        JButton btnIniciar = new JButton("CONTINUAR");
        btnIniciar.setName("C");
        JButton btnEliminar = new JButton("TERMINAR");
        btnEliminar.setName("T");
        pc = new Pc();
        listPc = SentenciasPc.ListarDatosPc();                   //CARGAR DATOS DE LA BASE DE DATOS
        if (listPc.size() > 0) {
            Pc pc1 = listPc.get(0);  //para probar si inicia el hilo
            t = new Tiempos(pc, lblTimeRestante);   //hilo para que mostrar los minutos regresivos
            t.start();
            System.out.println("PC " + pc1.getPc() + lblTimeRestante.getText());
 
            for (int i = 0; i < listPc.size(); i++) {
                Object fila[] = new Object[9];
                pc = listPc.get(i);                            //PASAR DE UN ARRAYLIST A UN OBJETO DE LA MISMA CLASE
                fila[0] = pc.getId();
                fila[1] = pc.getPc();
                fila[2] = pc.getHoraIngreso();
                fila[3] = pc.getHoraSalida();
                fila[4] = pc.formatoTimeRest(pc.getTiempoTotal() * 60);
                fila[5] = pc.getPagoInternet();
                fila[6] = lblTimeRestante.getText();
                fila[7] = btnIniciar;
                fila[8] = btnEliminar;
                modelo.addRow(fila);
            }
        }
 
    }}
Eh creado la clase Tabla1, para configurar el model e ingresar los labels y botones al jtable y para que carge de la base de datos

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public class Tiempos extends Thread {
 
    Pc pc;
    JLabel lblHora;
    public Tiempos( Pc pc, JLabel lblHora) {
        this.pc = pc;
        this.lblHora = lblHora;
    }
 
    @Override
    public void run() {
        long diferencia = 0;
        //pc.cabinaPc(minutos);
        do {
            try {
                diferencia = (pc.getHoraSalida().getTime() - new Date().getTime()) / 1000;      //seg
                Thread.sleep(1000);
                lblHora.setText(pc.formatoTimeRest(diferencia));
                if (diferencia==0) {
                    int i=JOptionPane.showConfirmDialog(null, "¿Continuas?");
                    System.out.println("i: "+i);
                    if (i==0) {
                    }
 
 
                }
            } catch (Exception e) {
            }
        } while (diferencia > 0);
 
    }}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder