I'm using NetBeans, and I can not show the value formatted as currency, for example $ 1,200.00. When I type in the text field, the zeros do not appear. I have a form with two fields: one for name and one for salary. In both, I'm using text field to receive the data, and a button to display the data in a dialog box.
IhaveaCallEmployeeclass,asperthecodebelow:
publicclassFuncionario{publicStringnome;publicdoublesalario;}
Displaybuttoncode,asbelow:
privatevoidbtnExibirActionPerformed(java.awt.event.ActionEventevt){//TODOaddyourhandlingcodehere:Funcionariofuncionario1=newFuncionario();DecimalFormatdf=newDecimalFormat();try{//Passaoconteúdodigitadoparaasvariáveisfuncionario1.nome=txtNome.getText();funcionario1.salario=(Double.parseDouble(txtSalario.getText()));JOptionPane.showMessageDialog(null,"\n*** Resultado ***" + "\n" +
"Nome : " + funcionario1.nome.toUpperCase() + "\n"+
"Salário. .......: " + df.format(funcionario1.salario));
}
catch(Exception erro)
{
JOptionPane.showMessageDialog(null, erro + "Verifique se Você deixou algum campo vazio !!!", "Erro na Entrada de Dados", JOptionPane.INFORMATION_MESSAGE);
}
}
I would also like to know how to test if the fields are empty and the salary field is only numeric.