Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Formulaire + Details : https://imgur.com/a/jseeuHk
- //change Label text color : label.getAllStyles().setFgColor(ColorUtil.rgb(255, 0, 0));
- //change button background color (doesnt work if you have an already set theme in "theme.res") :
- //button.getAllStyles().setBgColor(ColorUtil.GREEN,true);
- package com.mycompany.myapp;
- import com.codename1.components.OnOffSwitch;
- import com.codename1.components.SpanLabel;
- import static com.codename1.ui.CN.*;
- import com.codename1.ui.Display;
- import com.codename1.ui.Form;
- import com.codename1.ui.Dialog;
- import com.codename1.ui.Label;
- import com.codename1.ui.plaf.UIManager;
- import com.codename1.ui.util.Resources;
- import com.codename1.io.Log;
- import com.codename1.ui.Button;
- import com.codename1.ui.CheckBox;
- import com.codename1.ui.Container;
- import com.codename1.ui.TextField;
- import com.codename1.ui.Toolbar;
- import java.io.IOException;
- import com.codename1.ui.layouts.BoxLayout;
- import com.codename1.ui.layouts.FlowLayout;
- import com.codename1.ui.spinner.Picker;
- /**
- * This file was generated by <a href="https://www.codenameone.com/">Codename
- * One</a> for the purpose of building native mobile applications using Java.
- */
- public class Formulaire {
- private Form current;
- private Resources theme;
- public void init(Object context) {
- theme = UIManager.initFirstTheme("/theme");
- // Enable Toolbar on all Forms by default
- Toolbar.setGlobalToolbar(true);
- // Pro only feature
- Log.bindCrashProtection(true);
- }
- public void start() {
- if (current != null) {
- current.show();
- return;
- }
- /************************************** ↓↓ Formulaire Form ↓↓ **************************************/
- Form formulaire = new Form("Formulaire", BoxLayout.y());
- TextField tnom= new TextField("","nom");
- TextField tprenom = new TextField();
- tprenom.setHint("prenom");
- TextField tpass = new TextField();
- tpass.setHint("password");
- tpass.setConstraint(TextField.PASSWORD);
- /********** formulaire : gender label + OnOffSwitch **********/
- Container cnt1 = new Container(BoxLayout.x());
- Label lbg = new Label("Gender :");
- Label femme = new Label("Femme");
- OnOffSwitch gender = new OnOffSwitch();
- gender.setOn("Femme");
- gender.setOff("Homme");
- Label homme = new Label("Homme");
- cnt1.add(lbg);
- cnt1.add(homme);
- cnt1.add(gender);
- cnt1.add(femme);
- Picker date = new Picker();
- CheckBox checkbox1 = new CheckBox("Swimming");
- CheckBox checkbox2 = new CheckBox("Lecture");
- CheckBox checkbox3 = new CheckBox("Tennis");
- CheckBox checkbox4 = new CheckBox("Foot");
- Button btnval = new Button("valider");
- formulaire.add(tnom);
- formulaire.add(tprenom);
- formulaire.add(tpass);
- formulaire.add(cnt1);
- formulaire.add(date);
- formulaire.add(checkbox1);
- formulaire.add(checkbox2);
- formulaire.add(checkbox3);
- formulaire.add(checkbox4);
- formulaire.add(btnval);
- /************************************** ↓↓ Detaille Form ↓↓ **************************************/
- Form DetailsForm = new Form("Détaille", BoxLayout.y());
- Label lbnom = new Label("nom :");
- Label lbprenom = new Label("prenom :");
- Label lbdate = new Label("Date :");
- Label lbgender = new Label("Gender :");
- SpanLabel lbhobbie = new SpanLabel("Hobbies :");
- Button btnback = new Button("Back");
- DetailsForm.addAll(lbnom, lbprenom, lbdate, lbgender);
- DetailsForm.add(lbhobbie);
- DetailsForm.add(btnback);
- btnval.addActionListener((e) -> {
- lbnom.setText("nom :" + tnom.getText());
- lbprenom.setText(lbprenom.getText() + tprenom.getText());
- lbdate.setText("Date de naissance :" + date.getText());
- if (gender.isValue()) {
- lbgender.setText("Gender :" + gender.getOn());
- } else {
- lbgender.setText("Gender :" + gender.getOff());
- }
- //Hobbies :
- String str = lbhobbie.getText() + "\n";
- if (checkbox1.isSelected()) {
- str += checkbox1.getText() + "\n";
- }
- if (checkbox2.isSelected()) {
- str += checkbox2.getText() + "\n";
- }
- if (checkbox3.isSelected()) {
- str += checkbox3.getText() + "\n";
- }
- if (checkbox4.isSelected()) {
- str += checkbox4.getText() + "\n";
- }
- lbhobbie.setText(str);
- DetailsForm.show();
- });
- btnback.addActionListener((e) -> {
- formulaire.show();
- });
- /************************************** ↑↑ END Details ↑↑ **************************************/
- formulaire.show();
- }
- public void stop() {
- current = getCurrentForm();
- if (current instanceof Dialog) {
- ((Dialog) current).dispose();
- current = getCurrentForm();
- }
- }
- public void destroy() {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment