Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. try {
  2. String fname = txt_Fname.getText();
  3. String lname = txt_Lname.getText();
  4. String mobile = txt_mobile.getText();
  5. String home = txt_home.getText();
  6. String work = txt_work.getText();
  7. String fax = txt_fax.getText();
  8. byte[] image_detail;
  9.  
  10. PersonDAO perDAO = new PersonDAO(); //create person object
  11. if (status == 1) // used status for check whether Jlabed is clicked
  12. {
  13. File image = new File(path);
  14. FileInputStream fis = new FileInputStream(image);
  15. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  16. byte[] buf = new byte[1024];
  17.  
  18. for (int readNum; (readNum = fis.read(buf)) != -1; )
  19. {
  20. baos.write(buf, 0,readNum);
  21. }
  22. image_detail = baos.toByteArray();
  23.  
  24. Person person1 = new Person(fname, lname, mobile, home, work, fax, image_detail); // call the person
  25. // constructer when there is an image. I did validate with status variable
  26. perDAO.InsertPerson(person1); // call the personDAO to insert the Person to database
  27. }
  28. else
  29. {
  30. Person person2 = new Person(lname, lname, mobile, home, work, fax); // if there is not an image call this constructer .
  31. perDAO.InsertPerson(person2); // then call to personDAO object to insert the person to databasee
  32. }
  33. }
  34. catch (Exception exc)
  35. {
  36. System.out.println(exc + "sssssss");
  37. }
  38.  
  39.  
  40. // >>> when click on the JLabel, the JFileChooser appears
  41. int i = jFileChooser2.showOpenDialog(this);
  42. try {
  43. f = jFileChooser2.getSelectedFile();
  44. path = f.getAbsolutePath();
  45. ImageIcon image = new ImageIcon(path);
  46. status = 1;
  47. personImage.setIcon(image);
  48. }
  49. catch (Exception exc)
  50. {
  51. System.out.println(exc);
  52. }
  53.  
  54. if (label.getIcon() == null) {
  55. // this means there is no icon
  56. }
  57.  
  58. if (label.getIcon() == null) {
  59. // What you want as response should come here
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement