Código Java Swing: Mostrar Datos de Pilotos y Carreras de Fórmula 1

Clasificado en Informática

Escrito el en español con un tamaño de 2,56 KB

Mostrar datos de un piloto en Java Swing

private void mostrarPiloto() {
//borrarCampos();
Piloto pilotoBuscado = (Piloto) cmbPiloto.getSelectedItem();
txfNombre.setText(pilotoBuscado.getNombre());
txfDorsal.setText(pilotoBuscado.getDorsal() + "");
txfEscuderia.setText(pilotoBuscado.getEscuderia());
lblFotoP.setIcon(pilotoBuscado.getFoto());
txfPais.setText(pilotoBuscado.getPais());
/* UNA FORMA DE PONER UNA FECHA */
txfFechaN.setText(formatoFechaUno.format(pilotoBuscado.getFecha_nac().getTime()));
txfPuntosPiloto.setText(pilotoBuscado.getPuntos() + "");
}

Formateo de fechas con SimpleDateFormat

private String getFecha(java.util.Date fecha) {
java.text.SimpleDateFormat formatoFecha;
formatoFecha = new java.text.SimpleDateFormat("dd/MM/yyyy");
return formatoFecha.format(fecha);
}

Gestión de eventos en la interfaz

Evento del combo de pilotos

private void cmbPilotoActionPerformed(java.awt.event.ActionEvent evt) {
mostrarPiloto();
}

Evento de selección en la lista de carreras

private void listaMouseClicked(java.awt.event.MouseEvent evt) {
//javax.swing.DefaultListModel<Carrera> modelo = (javax.swing.DefaultListModel<Carrera>) lista.getModel();
Carrera c = (Carrera) lista.getSelectedValue();
txfNumero.setText(c.getNumero() + "");
txfFecha.setText(getFecha(c.getFecha()));
txfCarrera.setText(c.getNombre());
txfCircuito.setText(c.getCircuito());
java.text.DecimalFormat formato2 = new java.text.DecimalFormat("##.000");
txfKm.setText(formato2.format(c.getKm()));
txfNVueltas.setText(c.getnVueltas() + "");
llenarTabla();
}

Evento del botón para mostrar el mapa

private void btnMapaActionPerformed(java.awt.event.ActionEvent evt) {
Carrera c = (Carrera) lista.getSelectedValue();
lblMapa.setIcon(c.getMapaCircuito());
dlgMapa.setBounds(0, 0, 500, 500);
dlgMapa.setTitle(c.getCircuito());
dlgMapa.setVisible(true);
}

Entradas relacionadas: