在按钮Codenameone上执行某些操作后如何重新加载整个表单 [英] how to reload the whole form after certain action on button Codenameone

查看:42
本文介绍了在按钮Codenameone上执行某些操作后如何重新加载整个表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从购物车中删除产品时,我想刷新表格,我尝试了所有但都没有解决的办法吗?

I want to refresh my form when I remove a product from my cart I tried everything but didn't work is there a way to do it?

我的Cart类有一个显示购物车中的产品的类,当我从购物车中删除产品时我想在哪里显示,我想刷新整个表格,但不知道该怎么做,我几乎没有尝试过每种方法,但是仍然无法完成

There is my Cart class which displays the products in my cart and where I want to when I remove a product from my cart I want to refresh the whole form but didn't know how to do it I barely tried every method but still can't be done

public class Cart {
  Form f;

  public Cart() throws IOException {
      f = new Form("cart",BoxLayout.y());

      Button b = new Button("back");
      b.addActionListener(e->{
         AfficherProduits sp;
          try {
              sp = new AfficherProduits();
              sp.getF().show();
          } catch (IOException ex) {
              System.out.println("ERREUR DANS RETOUR LISTE PRODUITS ");
          }
      });
      f.add(b);

      //**********************************instanciation du panier********************************************************
      Panier panier=Panier.getInstance();


      //********************************Parcourir le panier**************************************************************
       ComponentGroup cg = new ComponentGroup();
      for (Lignedecommande c : panier.p)
      {
          Container c4 =new Container(BoxLayout.x());
          Container c3 =new Container(BoxLayout.y());
          Container c2=new Container(BoxLayout.x());
          Container c1=new Container(BoxLayout.y());
          Container c5=new Container(BoxLayout.y());

      //***************************les elements du containers************************************************************
          ImageViewer iv=new ImageViewer();
          iv.setImage(Image.createImage("/"+ c.getProduct().getImage()).scaled(80, 80));

          Button bt=new Button("X");

          bt.addActionListener(e->{
             panier.removeLine(c);
             //ShowListProduct sp=new ShowListProduct();
             //sp.getF().show();
             f.removeComponent(cg);
             f.refreshTheme();
          });
          //********************les boutons de modif quantite******************************************
          Button b1=new Button("+");
          Button b2=new Button("-");
          bt.getStyle().setPadding(0,0,0,0);

          //*****************************mettre le bouton X au milieu****************************************************
          Label lb1=new Label(".");
          Label lb2=new Label(".");
          lb1.setVisible(false);
          lb2.setVisible(false);
          c1.add(lb1);
          c1.add(bt);
          c1.add(lb2);

          c5.add(b1);
          c5.add(b2);

          c4.add(c1);
          c4.add(iv);

          c2.add(new Label(Integer.toString(c.getQuantite())));
          c2.add(c5);
          //c2.add(b2);

          //c3.add(new SpanLabel(c.getProduct().getName()));
          c3.add(c2);


          c4.add(c3);
          c4.add(new Label("$"+Float.toString(c.getProduct().getPrix()*c.getQuantite())));

          cg.add(c4);
      }
      f.add(cg);
  }

  public Form getF() {
      return f;
  }

  public void setF(Form f) {
      this.f = f;
  }
}

这是我如何称呼此页面来查看我的购物车

and there is how I call this page to see my cart

  h = new AfficherProduits();
  h.getF().show();

推荐答案

不重新加载.重新创建并显示.

Don't reload. Recreate and show.

将所有代码从构造函数中移至名为 createCartForm()的方法中.然后,构造函数将执行以下操作:

Move all the code from the constructorto a method called createCartForm(). The constructor would then do:

f = createCartForm();

重新加载将变成:

setF(h.createCartForm());
getCurrentForm().setTransitionOut(CommonTransitions.createEmpty());
h.getF().show();

我将表单替换为新实例,并删除默认的过渡版本,以免替换没有生气.

I replace the form with a new instance and remove the default transition out so the replacement won't be animated.

这篇关于在按钮Codenameone上执行某些操作后如何重新加载整个表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆