Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Login From DataBase [2 Methods](login.php)
- // https://imgur.com/a/fFlF1jE
- /*
- con.setPost(false);
- con.addArgument("name", tnom.getText());
- */
- package com.mycompany.myapp;
- import com.codename1.io.ConnectionRequest;
- 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.io.NetworkManager;
- import com.codename1.ui.Button;
- import com.codename1.ui.TextField;
- import com.codename1.ui.Toolbar;
- import java.io.IOException;
- import com.codename1.ui.layouts.BoxLayout;
- /**
- * 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 MyApplication {
- 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);
- }
- public void start() {
- if (current != null) {
- current.show();
- return;
- }
- Form hi = new Form("Hi World", BoxLayout.y());
- TextField tnom = new TextField("", "nom");
- TextField tpassword = new TextField("", "password");
- tpassword.setConstraint(TextField.PASSWORD);
- Button btnConne = new Button("connect");
- hi.addAll(tnom, tpassword, btnConne);
- ConnectionRequest con = new ConnectionRequest();
- btnConne.addActionListener((e) -> {
- //Method 1 ( Login From server ) :
- // String url = "http://localhost/codenameoneRessource/login.php?" + "name=" + tnom.getText() + "&password=" + tpassword.getText();
- //Method 2 ( Login From server ) :
- String url = "http://localhost/codenameoneRessource/login.php";
- con.setPost(false);
- con.addArgument("name", tnom.getText());
- con.addArgument("password", tpassword.getText());
- con.setUrl(url);
- NetworkManager.getInstance().addToQueueAndWait(con);
- });
- con.addResponseListener((e) -> {
- String repo = new String(con.getResponseData());
- System.out.println(repo);
- if(repo.trim().equalsIgnoreCase("OK"))
- {
- Form f2=new Form();
- f2.add(new Label("Hi Admin You Logged in Successfully !"));
- f2.show();
- f2.getToolbar().addCommandToLeftBar("back",null, ev->{hi.show();});
- }
- else
- {
- Dialog.show("Error","login ou pwd invalid","ok",null);
- }
- });
- hi.add(new Label("username : admin , password : admin"));
- hi.show();
- }
- public void stop() {
- current = getCurrentForm();
- if (current instanceof Dialog) {
- ((Dialog) current).dispose();
- current = getCurrentForm();
- }
- }
- public void destroy() {
- }
- }
- //login.php Link : https://pastebin.com/Zc08ciaj
- //https://i.imgur.com/LB3pRGn.png
Add Comment
Please, Sign In to add comment