how to check is DOUBLE JTEXTFIELD is empty?
hi I've been working this for 2 days and even google it but I can't figured the right answer.
I can check STRING if it is empty.
here is my code
Code :
private void saveButton3ActionPerformed(java.awt.event.ActionEvent evt) {
String inventcodef = inventCodeField.getText();
String inventnamef = inventNameField.getText();
String categ = cmbname.getSelectedItem().toString();
double inventreorderf = Double.parseDouble(inventReorderField.getText());
String inventlocf = inventLocationField.getText();
String inventstat = inventStatusArea.getText();
if ((inventcodef.trim().length()==0) || (inventnamef.trim().length()== 0)||(inventreorderf == 0))
{
JOptionPane.showMessageDialog(null,"Item Code / Item Name / ReOrderpoint is empty!");
}
else
try {
String SQL2 = "INSERT INTO inventory VALUES ("
+ "'" + inventcodef + "'" + ","
+ "'" + inventnamef + "'" + ","
+ "'" + categ + "'" + ","
+ "'" + inventreorderf + "'" + ","
+ "'" + inventlocf + "'" + ","
+ "'" + inventstat + "'"
+ ")";
PreparedStatement stamt = connect.prepareStatement(SQL2);
stamt.executeUpdate();
Double.parseDouble(inventReorderField.getText());
JOptionPane.showMessageDialog(null,"Item Code: " + inventcodef + " Successfully saved!");
}
catch (NumberFormatException e)
{
JOptionPane.showMessageDialog(null,e.getMessage());
inventReorderField.selectAll();
inventReorderField.requestFocus();
return;
}
catch (Exception f)
{
JOptionPane.showMessageDialog(null,(f.getMessage()));
}
}
Thank you!
Re: how to check is DOUBLE JTEXTFIELD is empty?
== null;
? does that not work?
I looked using Google and I found this as well,
jtextfield.getText().trim().length() >=0
unfortunately I don't know much about GUI form methods, so i don't even know if DOUBLE jtextfield is a special type of jtextfield.
anyway, maybe the generic ideas help anyway.
Good-luck,
Jonathan
Re: how to check is DOUBLE JTEXTFIELD is empty?
a) You should learn how to use a PreparedStatement correctly (eg using parameters) b) You can use Double.parseDouble and catch any exceptions that may be thrown - alternatively use a regular expressions to check the entered value matches the appropriate pattern
Quote:
== null;
? does that not work?
I looked using Google and I found this as well,
jtextfield.getText().trim().length() >=0
unfortunately I don't know much about GUI form methods, so i don't even know if DOUBLE jtextfield is a special type of jtextfield.
I would recommend you become familiar with the API and methods being used prior to trying to make recommendations to others