Advertisement
Guest User

Untitled

a guest
May 25th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. private void clear_buttActionPerformed(java.awt.event.ActionEvent evt) {
  2. // TODO add your handling code here:
  3. num_text.setText("");
  4. out_text.setText("");
  5. }
  6.  
  7. private void exit_buttActionPerformed(java.awt.event.ActionEvent evt) {
  8. // TODO add your handling code here:
  9. System.exit(busyIconIndex);
  10. }
  11.  
  12. private void out_textActionPerformed(java.awt.event.ActionEvent evt) {
  13.  
  14. }
  15.  
  16. private void fact_buttActionPerformed(java.awt.event.ActionEvent evt) {
  17. // TODO add your handling code here:
  18.  
  19. //Declare variables
  20. String fact_out;
  21. int total, k, num;
  22.  
  23. //initiliaze for invalid data
  24. num = 1;
  25.  
  26. if ((num_text.getText().equals("")))
  27. { num_text.setText("");
  28.  
  29. //put error message out
  30. JOptionPane.showMessageDialog(null, "Lack of information!", "Error message", JOptionPane.ERROR_MESSAGE );
  31. }
  32.  
  33. else
  34. {
  35.  
  36. //get the information off the form
  37. num = Integer.parseInt(num_text.getText());
  38.  
  39. //Calculate
  40. total = 1;
  41. for (k = 1; k <= num; k++)
  42. total = total * k;
  43.  
  44.  
  45. //Put results on forum
  46. out_text.setText(String.valueOf(num) + "! is equal to " + String.valueOf(total) );
  47.  
  48. if ((num <0))
  49. { num_text.setText("");
  50. out_text.setText("");
  51. //put error message out
  52. JOptionPane.showMessageDialog(null, "You entered a negative number", "Error message", JOptionPane.ERROR_MESSAGE );
  53.  
  54. }
  55.  
  56.  
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement