iifast

MyApplication.java

Mar 9th, 2020
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.77 KB | None | 0 0
  1. // List3A →Print in cmd
  2. //Label , Button , ArrayList ( forEach )
  3. package com.mycompany.myapp;
  4.  
  5. import static com.codename1.ui.CN.*;
  6. import com.codename1.ui.Display;
  7. import com.codename1.ui.Form;
  8. import com.codename1.ui.Dialog;
  9. import com.codename1.ui.Label;
  10. import com.codename1.ui.plaf.UIManager;
  11. import com.codename1.ui.util.Resources;
  12. import com.codename1.io.Log;
  13. import com.codename1.ui.Button;
  14. import com.codename1.ui.Container;
  15. import com.codename1.ui.Toolbar;
  16. import java.io.IOException;
  17. import com.codename1.ui.layouts.BoxLayout;
  18. import java.util.ArrayList;
  19. import java.util.List;
  20.  
  21. /**
  22.  * This file was generated by <a href="https://www.codenameone.com/">Codename One</a> for the purpose
  23.  * of building native mobile applications using Java.
  24.  */
  25. public class MyApplication {
  26.  
  27.     private Form current;
  28.     private Resources theme;
  29.  
  30.     public void init(Object context) {
  31.         theme = UIManager.initFirstTheme("/theme");
  32.  
  33.         // Enable Toolbar on all Forms by default
  34.         Toolbar.setGlobalToolbar(true);
  35.  
  36.         // Pro only feature
  37.        // Log.bindCrashProtection(true);
  38.     }
  39.    
  40.     public void start() {
  41.         if(current != null){
  42.             current.show();
  43.             return;
  44.         }
  45.         Form hi = new Form("Liste des personnes ", BoxLayout.y());
  46.        Personne p1=new Personne("sana", "ben",
  47.                "[email protected]", "round.png", 10,222222);
  48.        Personne p2=new Personne("onsa", "ben",
  49.                "[email protected]", "round.png", 10,222222);
  50.        Personne p3=new Personne("sinda", "ben",
  51.                "[email protected]", "round.png", 10,222222);
  52.           List<Personne> lis=new ArrayList();
  53.           lis.add(p1);
  54.           lis.add(p2);
  55.           lis.add(p3);
  56.           for(Personne p:lis)
  57.               hi.add(addItem(p));
  58. //        hi.add(addItem(p1));
  59. //        hi.add(addItem(p2));
  60. //        hi.add(addItem(p3));
  61.         hi.show();
  62.     }
  63.     public Container addItem(Personne p)
  64.     {
  65.      Label lbnom=new Label(p.getNom());
  66.         Button btn=new Button(p.getMail());  
  67.         Label lbimg=new Label(theme.getImage(p.getNomimg()));
  68.         Container cnt1=new Container(BoxLayout.y());
  69.        
  70.         cnt1.add(lbnom);
  71.         cnt1.add(btn);
  72.        
  73.         Container cnt2=new Container(BoxLayout.x());
  74.         cnt2.add(cnt1);
  75.         cnt2.add(lbimg);
  76.        
  77.         btn.addActionListener(l->{
  78.             System.out.println(p);
  79.         });
  80.         cnt2.setLeadComponent(btn);
  81.         return cnt2;
  82.        
  83.     }
  84.     public void stop() {
  85.         current = getCurrentForm();
  86.         if(current instanceof Dialog) {
  87.             ((Dialog)current).dispose();
  88.             current = getCurrentForm();
  89.         }
  90.     }
  91.    
  92.     public void destroy() {
  93.     }
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment