Ver Mensaje Individual
  #5 (permalink)  
Antiguo 07/04/2010, 10:49
liderzen
 
Fecha de Ingreso: abril-2010
Mensajes: 3
Antigüedad: 14 años
Puntos: 0
Respuesta: Manejo de excepcion dentro de addActionListener

MUCHAS GRACIAS POR SU AYUDA:

Para solucionar el problema elimine el throws del actionPerformed y cree un metodo llamado retirar he hice lo siguiente:

btnRetirar.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
double saldo = MappedCuentas.obtenerSaldo(Integer.parseInt(txtId. getText()));
double retiro = Double.parseDouble(txtRetiro.getText());
lblSaldoAnteriorDato.setText(String.valueOf(saldo) );
try
{
retirar(retiro, saldo);
}
catch(RetiroException re)
{
lblMensaje.setText(re.getMessage());
d.add(lblMensaje);
d.setTitle("Se produjo una excepción");
d.setSize(200,200);
d.setVisible(true);

}
}
});

Cree un Jdialog llamado d y una Label lblMensaje para mostar el mensaje de excepción y el metodo retirar quedo asi:

public void retirar(double retiro, double saldo) throws RetiroException
{
if(retiro <= saldo)
{
saldo = saldo - retiro;
lblSaldoActualDato.setText(""+saldo);
MappedCuentas.guardarCuenta(Integer.parseInt(txtId .getText()),saldo);
}
else
{
throw new RetiroException("NO SE PUEDE REALIZAR EL RETIRO");
}
}

Agradecería me dijeran si esta solucion es óptima o si hay una mejor solucion...

GRACIAS Y QUE DIOS LOS BENDIGA!!!!!