document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. // Revision Project 1
  2. // https://imgur.com/a/ESIghSF
  3. //MyApplication.java
  4.  
  5. package com.mycompany.myapp;
  6.  
  7. import com.codename1.components.ImageViewer;
  8. import com.codename1.db.Cursor;
  9. import com.codename1.db.Database;
  10. import com.codename1.db.Row;
  11. import com.codename1.io.ConnectionRequest;
  12. import com.codename1.ui.Display;
  13. import com.codename1.ui.Form;
  14. import com.codename1.ui.Dialog;
  15. import com.codename1.ui.Label;
  16. import com.codename1.ui.plaf.UIManager;
  17. import com.codename1.ui.util.Resources;
  18. import com.codename1.io.Log;
  19. import com.codename1.io.NetworkEvent;
  20. import com.codename1.io.NetworkManager;
  21. import com.codename1.ui.Button;
  22. import com.codename1.ui.Component;
  23. import com.codename1.ui.Container;
  24. import com.codename1.ui.EncodedImage;
  25. import com.codename1.ui.TextField;
  26. import com.codename1.ui.Toolbar;
  27. import com.codename1.ui.URLImage;
  28. import com.codename1.ui.events.ActionEvent;
  29. import com.codename1.ui.events.ActionListener;
  30. import com.codename1.ui.layouts.BoxLayout;
  31. import com.codename1.ui.layouts.FlowLayout;
  32. import com.codename1.ui.util.UIBuilder;
  33. import java.io.IOException;
  34. import java.io.UnsupportedEncodingException;
  35. import java.util.ArrayList;
  36.  
  37. /**
  38.  * This file was generated by <a href="https://www.codenameone.com/">Codename
  39.  * One</a> for the purpose of building native mobile applications using Java.
  40.  */
  41. public class MyApplication {
  42.  
  43.     private Form current;
  44.     private Resources theme;
  45.     ArrayList<Contact> contacts;
  46.     String ch;
  47.     Database db;
  48.     boolean created = false;
  49.  
  50.     public void init(Object context) {
  51.         theme = UIManager.initFirstTheme("/theme");
  52.  
  53.         // Enable Toolbar on all Forms by default
  54.         Toolbar.setGlobalToolbar(true);
  55.  
  56.         contacts = new ArrayList<>();
  57.         contacts.add(new Contact("1", "description nader", "contact_icon.png"));
  58.  
  59.         contacts.add(new Contact("2", "description hamza", "contact_icon.png"));
  60.         contacts.add(new Contact("3", "description stoura", "contact_icon.png"));
  61.         contacts.add(new Contact("4", "description ahmed", "contact_icon.png"));
  62.         created = Database.exists("revisionCN1");
  63.  
  64.         try {
  65.             db = Database.openOrCreate("revisionCN1");
  66.             if (created == false) {
  67.                 System.out.println("CREATE");
  68.                 db.execute("CREATE TABLE user(id INTEGER, nom TEXT, decription TEXT, CONSTRAINT name_unique UNIQUE (nom));");
  69.             }
  70.  
  71.         } catch (IOException ex) {
  72.             System.err.println(ex.getMessage());
  73.         }
  74.         // Pro only feature, uncomment if you have a pro subscription
  75.         // Log.bindCrashProtection(true);
  76.     }
  77.     Form f2;
  78.  
  79.     public void start() {
  80.  
  81.         UIBuilder ui = new UIBuilder();
  82.         FlowLayout layout = new FlowLayout(Component.CENTER);
  83.  
  84.         Form f = new Form(layout);
  85.  
  86.         TextField tfNom = new TextField("", "Nom");
  87.         TextField tfPrenom = new TextField("", "PrĂ©nom");
  88.         f.add(tfNom);
  89.         f.add(tfPrenom);
  90.         Button btn = new Button("Valider");
  91.         f.add(btn);
  92.  
  93.         f2 = new Form(BoxLayout.y());
  94.  
  95.         btn.addActionListener(new ActionListener() {
  96.  
  97.             @Override
  98.             public void actionPerformed(ActionEvent evt) {
  99.                 f2.setTitle(tfNom.getText() + " " + tfPrenom.getText());
  100.                 for (Contact c : contacts) {
  101.  
  102.                     addItem(c);
  103.                     f2.refreshTheme();
  104.                 }
  105.  
  106.                 f2.show();
  107.             }
  108.         });
  109.         f.show();
  110.     }
  111.  
  112.     public void addItem(Contact contact) {
  113.  
  114.         Container C1 = new Container(new BoxLayout(BoxLayout.X_AXIS));
  115.  
  116.         ImageViewer img = new ImageViewer(theme.getImage("round.png"));
  117.  
  118.         Container C2 = new Container(new BoxLayout(BoxLayout.Y_AXIS));
  119.         Label l = new Label(contact.getNom());
  120.         Label tel = new Label(contact.getDescription());
  121.  
  122.         l.addPointerPressedListener(new ActionListener() {
  123.  
  124.             @Override
  125.             public void actionPerformed(ActionEvent evt) {
  126.                 Form f3 = new Form(BoxLayout.y());
  127.  
  128.                 EncodedImage encImg
  129.                         = EncodedImage.createFromImage(theme.getImage("round.png"), false);
  130.                 URLImage imgUrl
  131.                         = URLImage.createToStorage(encImg, "cache", "file:///C:/wamp64/www/serveur/cn1revision/" + contact.getImg());
  132.                 imgUrl.fetch();              
  133.                 ImageViewer img = new ImageViewer(imgUrl);
  134.  
  135.                 f3.add(img);
  136.                 Label lNom = new Label();
  137.                 Label lDesc = new Label();
  138.  
  139.                 ConnectionRequest req = new ConnectionRequest();
  140.                 //C:\\wamp64\\www\\serveur\\cn1revision\\getDetails.php
  141.                 req.setUrl("http://localhost/serveur/cn1revision/getDetails.php?id=" + contact.getNom());
  142.                 req.addResponseListener(new ActionListener<NetworkEvent>() {
  143.  
  144.                     @Override
  145.                     public void actionPerformed(NetworkEvent evt) {
  146.                         byte data[] = (byte[]) evt.getMetaData();
  147.  
  148.                         try {
  149.                             ch = new String(data, "utf-8");
  150.                         } catch (UnsupportedEncodingException ex) {
  151.                         }
  152.  
  153.                         System.out.println(ch);
  154.                         lDesc.setText(ch);
  155.                         f3.add(lDesc);
  156.                         f3.refreshTheme();
  157.  
  158.                     }
  159.                 });
  160.                 NetworkManager.getInstance().addToQueue(req);
  161.  
  162.                 f3.getToolbar().addCommandToOverflowMenu("Add", null, new ActionListener() {
  163.  
  164.                     @Override
  165.                     public void actionPerformed(ActionEvent evt) {
  166.                         try {
  167.                             db.execute("insert into user (nom, decription) values (\'" + contact.getNom() + "\', \'" + lDesc.getText() + "\' );");
  168.                         } catch (IOException ex) {
  169.                             System.err.println(ex.getMessage());
  170.                         }
  171.  
  172.                     }
  173.                 });
  174.  
  175.                 f3.getToolbar().addCommandToOverflowMenu("Select", null, new ActionListener() {
  176.  
  177.                     @Override
  178.                     public void actionPerformed(ActionEvent evt) {
  179.                         Form f4 = new Form(BoxLayout.y());
  180.                         try {
  181.                             Cursor c = db.executeQuery("select * from user");
  182.  
  183.                             while (c.next()) {
  184.                                 Row r = c.getRow();
  185.                                 String nom = r.getString(1);
  186.                                 String prenom = r.getString(2);
  187.                                 Label l = new Label(nom + " " + prenom);
  188.                                 f4.add(l);
  189.                             }
  190.  
  191.                         } catch (IOException ex) {
  192.                             System.err.println(ex.getMessage());
  193.                         }
  194.                         f4.getToolbar().addCommandToRightBar("Back to home", theme.getImage("back-command.png"),
  195.                                 e -> f2.showBack());
  196.                         f4.show();
  197.                     }
  198.                 });
  199.  
  200.                 f3.show();
  201.             }
  202.         });
  203.  
  204.         C2.add(l);
  205.         C2.add(tel);
  206.         C1.add(img);
  207.         C1.add(C2);
  208.         C1.setLeadComponent(l);
  209.         f2.add(C1);
  210.         f2.refreshTheme();
  211.  
  212.     }
  213.  
  214.     public void stop() {
  215.         current = Display.getInstance().getCurrent();
  216.         if (current instanceof Dialog) {
  217.             ((Dialog) current).dispose();
  218.             current = Display.getInstance().getCurrent();
  219.         }
  220.     }
  221.  
  222.     public void destroy() { }
  223.  
  224. }
');