document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. //Formulaire + Details : https://imgur.com/a/jseeuHk
  2. //change Label text color : label.getAllStyles().setFgColor(ColorUtil.rgb(255, 0, 0));
  3. //change button background color (doesnt work if you have an already set theme in "theme.res") :
  4.       //button.getAllStyles().setBgColor(ColorUtil.GREEN,true);
  5.  
  6. package com.mycompany.myapp;
  7.  
  8. import com.codename1.components.OnOffSwitch;
  9. import com.codename1.components.SpanLabel;
  10. import static com.codename1.ui.CN.*;
  11. import com.codename1.ui.Display;
  12. import com.codename1.ui.Form;
  13. import com.codename1.ui.Dialog;
  14. import com.codename1.ui.Label;
  15. import com.codename1.ui.plaf.UIManager;
  16. import com.codename1.ui.util.Resources;
  17. import com.codename1.io.Log;
  18. import com.codename1.ui.Button;
  19. import com.codename1.ui.CheckBox;
  20. import com.codename1.ui.Container;
  21. import com.codename1.ui.TextField;
  22. import com.codename1.ui.Toolbar;
  23. import java.io.IOException;
  24. import com.codename1.ui.layouts.BoxLayout;
  25. import com.codename1.ui.layouts.FlowLayout;
  26. import com.codename1.ui.spinner.Picker;
  27.  
  28. /**
  29.  * This file was generated by <a href="https://www.codenameone.com/">Codename
  30.  * One</a> for the purpose of building native mobile applications using Java.
  31.  */
  32. public class Formulaire {
  33.  
  34.     private Form current;
  35.     private Resources theme;
  36.  
  37.     public void init(Object context) {
  38.         theme = UIManager.initFirstTheme("/theme");
  39.  
  40.         // Enable Toolbar on all Forms by default
  41.         Toolbar.setGlobalToolbar(true);
  42.  
  43.         // Pro only feature
  44.         Log.bindCrashProtection(true);
  45.     }
  46.  
  47.     public void start() {
  48.         if (current != null) {
  49.             current.show();
  50.             return;
  51.         }
  52.        
  53. /************************************** ↓↓ Formulaire Form ↓↓ **************************************/        
  54.  
  55. Form formulaire = new Form("Formulaire", BoxLayout.y());
  56.        
  57.         TextField tnom= new TextField("","nom");
  58.        
  59.         TextField tprenom = new TextField();
  60.         tprenom.setHint("prenom");
  61.        
  62.         TextField tpass = new TextField();
  63.         tpass.setHint("password");
  64.         tpass.setConstraint(TextField.PASSWORD);
  65.        
  66.         /********** formulaire :  gender label + OnOffSwitch  **********/
  67.         Container cnt1 = new Container(BoxLayout.x());
  68.        
  69.         Label lbg = new Label("Gender :");
  70.         Label femme = new Label("Femme");
  71.         OnOffSwitch gender = new OnOffSwitch();
  72.         gender.setOn("Femme");
  73.         gender.setOff("Homme");
  74.         Label homme = new Label("Homme");
  75.        
  76.         cnt1.add(lbg);
  77.         cnt1.add(homme);
  78.         cnt1.add(gender);
  79.         cnt1.add(femme);
  80.        
  81.         Picker date = new Picker();
  82.        
  83.         CheckBox checkbox1 = new CheckBox("Swimming");
  84.         CheckBox checkbox2 = new CheckBox("Lecture");
  85.         CheckBox checkbox3 = new CheckBox("Tennis");
  86.         CheckBox checkbox4 = new CheckBox("Foot");
  87.        
  88.         Button btnval = new Button("valider");
  89.        
  90.        
  91.         formulaire.add(tnom);
  92.         formulaire.add(tprenom);
  93.         formulaire.add(tpass);
  94.         formulaire.add(cnt1);
  95.         formulaire.add(date);
  96.         formulaire.add(checkbox1);
  97.         formulaire.add(checkbox2);
  98.         formulaire.add(checkbox3);
  99.         formulaire.add(checkbox4);
  100.         formulaire.add(btnval);
  101.        
  102. /************************************** ↓↓ Detaille Form ↓↓ **************************************/
  103.  
  104.     Form DetailsForm = new Form("Détaille", BoxLayout.y());
  105.        
  106.         Label lbnom = new Label("nom :");
  107.         Label lbprenom = new Label("prenom :");
  108.         Label lbdate = new Label("Date :");
  109.         Label lbgender = new Label("Gender :");
  110.         SpanLabel lbhobbie = new SpanLabel("Hobbies :");
  111.        
  112.         Button btnback = new Button("Back");
  113.    
  114.     DetailsForm.addAll(lbnom, lbprenom, lbdate, lbgender);      
  115.     DetailsForm.add(lbhobbie);
  116.     DetailsForm.add(btnback);
  117.        
  118. btnval.addActionListener((e) -> {
  119.             lbnom.setText("nom :" + tnom.getText());
  120.             lbprenom.setText(lbprenom.getText() + tprenom.getText());
  121.             lbdate.setText("Date de naissance :" + date.getText());
  122.            
  123.            
  124.             if (gender.isValue()) {
  125.                 lbgender.setText("Gender :" + gender.getOn());
  126.             } else {
  127.                 lbgender.setText("Gender :" + gender.getOff());
  128.             }
  129.            
  130.             //Hobbies :
  131.            
  132.             String str = lbhobbie.getText() + "\\n";
  133.             if (checkbox1.isSelected()) {
  134.                 str += checkbox1.getText() + "\\n";
  135.             }
  136.             if (checkbox2.isSelected()) {
  137.                 str += checkbox2.getText() + "\\n";
  138.             }
  139.             if (checkbox3.isSelected()) {
  140.                 str += checkbox3.getText() + "\\n";
  141.             }
  142.             if (checkbox4.isSelected()) {
  143.                 str += checkbox4.getText() + "\\n";
  144.             }
  145.             lbhobbie.setText(str);
  146.             DetailsForm.show();
  147.         });
  148.         btnback.addActionListener((e) -> {
  149.             formulaire.show();
  150.         });
  151. /************************************** ↑↑ END Details ↑↑ **************************************/
  152.        
  153.         formulaire.show();
  154.     }
  155.  
  156.    
  157.     public void stop() {
  158.         current = getCurrentForm();
  159.         if (current instanceof Dialog) {
  160.             ((Dialog) current).dispose();
  161.             current = getCurrentForm();
  162.         }
  163.     }
  164.  
  165.     public void destroy() {
  166.     }
  167.  
  168. }
');