iifast

AddTaskForm.java

Jun 11th, 2020
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.51 KB | None | 0 0
  1. //File Name : AddTaskForm.java
  2.  
  3. package com.mycompany.myapp.gui;
  4.  
  5. import com.codename1.ui.FontImage;
  6. import com.codename1.ui.Form;
  7. import com.mycompany.myapp.entities.Task;
  8.  
  9. /**
  10. *
  11. *@author
  12. */
  13.  
  14. public class AddTaskForm extends Form {
  15.  
  16. public AddTaskForm(Form previous) {
  17. setTitle(" Add a new task ");
  18. setLayout(BoxLayout.y());
  19. //Creer l'interface d'ajout
  20. TextField tfName = new TextField("","TaskName");
  21. TextField tfStatus = new TextField("","Status :  0   -   1 ");
  22. Button btnValider = new Button("Add task" );
  23.  
  24. btnValider.addActionListener(new ActionListener(){
  25. @Override
  26.     public void actionPerformed(ActionEvent evt){
  27. // Verifier les donnees saisies par l'utilisateur
  28.         if( (tfName.getText().length==0)||(tfStatus.getText().length()==0))              
  29.     Dialog.show("Alter", "Please fill all the fields" , new Command("OK"));
  30.       else
  31.        {
  32.         try {
  33.           Task t = new Task(Integer.ParseInt(tfStatus.getText()), tfName.getText());
  34.          
  35.         //invoquer la method ajout
  36.          if (new ServiceTask().addTask(t))
  37.             //verifier son retour
  38.           Dialog.show("Success","Connection accepted" , new Commad("OK"));
  39.         else
  40.             Dialog.show("ERROR","Server error",new Command("OK")); 
  41.        
  42.     } catch(NumberFormatException e) {
  43.         Dialog.show("ERROR","Status must be a number", new Commad("OK") );
  44.         }
  45.                                  
  46.           }
  47.    
  48.            }
  49.  });
  50.  
  51. addAll(tfName,tfStatus,btnValider);
  52. getToolbar().addMaterialCommandToLeftBar("",FontImage.MATERIAL_ARROW_BACK,e->previous.showBack());
  53. }
  54.   }
Add Comment
Please, Sign In to add comment