2
I’m using Netbeans, and I can’t show the formatted value as a currency, for example R$1,200.00. When I type in the text field, zeros do not appear. I have a form with two fields: One for name and one for salary. In both, I am using text field to receive the data, and a button to display the data in a dialog box.
I have a class called Employee, as code below:
public class Funcionario {
public String nome;
public double salario;
}
Button code Display as below:
private void btnExibirActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Funcionario funcionario1 = new Funcionario();
DecimalFormat df = new DecimalFormat();
try
{
// Passa o conteúdo digitado para as variáveis
funcionario1.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 do it to test if the fields are empty and if the salary field is only numerical.
Do you want it to format as it is typed? If it is, it is not that way, but using mask in a Jformattedtextfield field.
– user28595
I remember an answer from an old question about this, masks for Jformatted here, Help yourself, @Montesuma.
– Gustavo Cinque