如何在按钮Codenameone上执行某些操作后重新加载整个表单

时间:2018-04-23 12:58:53

标签: codenameone

当我从购物车中移除产品时,我想刷新我的表单我尝试了所有但是没有工作是否有办法做到这一点?

有我的购物车类显示我的购物车中的产品以及我想从我的购物车中删除产品时的位置我想刷新整个表单但我不知道该怎么做我几乎没有尝试过方法但仍无法完成

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;
  }
}

我可以通过此页面来查看我的购物车

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

1 个答案:

答案 0 :(得分:1)

不要重装。重新创建和展示。

将构造中的所有代码移动到名为Target Performance Summary: 0 ms PrepareResources 3 calls 0 ms SetWin32ManifestProperties 3 calls 0 ms ResGen 3 calls 0 ms AfterResGen 3 calls 0 ms CreateSatelliteAssemblies 3 calls 0 ms BeforeResGen 3 calls 0 ms PrepareResourceNames 3 calls 0 ms CreateCustomManifestResourceNames 3 calls 0 ms ComputeIntermediateSatelliteAssemblies 1 calls 0 ms GetTargetPath 3 calls 0 ms Compile 3 calls 0 ms AfterMarkupCompilePass1 3 calls 0 ms ResolveReferences 3 calls 0 ms BeforeCompile 3 calls 0 ms _CopySourceItemsToOutputDirectory 3 calls 0 ms PrepareForRun 3 calls 0 ms AfterResolveReferences 3 calls 0 ms PrepareProjectReferences 3 calls 0 ms ValidateToolsVersions 1 calls 0 ms ValidateProjects 1 calls 0 ms GetNativeManifest 2 calls 0 ms BeforeBuild 3 calls 0 ms BuildOnlySettings 3 calls 0 ms _AfterCompileWinFXInternal 3 calls 0 ms CoreBuild 3 calls 0 ms BeforeResolveReferences 3 calls 0 ms AfterCompileWinFX 3 calls 0 ms AfterBuild 3 calls 0 ms AfterCompile 3 calls 1 ms GetTargetFrameworks 2 calls 1 ms ExpandSDKReferences 3 calls 2 ms _BeforeVBCSCoreCompile 3 calls 2 ms GenerateSatelliteAssemblies 1 calls 2 ms ExpressionBuildExtension 3 calls 2 ms ValidationExtension 3 calls 3 ms _CheckForCompileOutputs 3 calls 3 ms FileClassification 3 calls 5 ms CopySilverlightApplications 1 calls 6 ms _CopyAppConfigFile 1 calls 9 ms ResolveKeySource 3 calls 13 ms PrepareForBuild 3 calls 14 ms _SetEmbeddedWin32ManifestProperties 3 calls 17 ms _SplitProjectReferencesByFileExistence 3 calls 20 ms GenerateTargetFrameworkMonikerAttribute 3 calls 25 ms GetCopyToOutputDirectoryXamlAppDefs 3 calls 34 ms _GenerateCompileInputs 3 calls 35 ms GetFrameworkPaths 3 calls 38 ms AssignProjectConfiguration 3 calls 45 ms CleanXsdCodeGen 3 calls 55 ms ResolveCodeAnalysisRuleSet 3 calls 56 ms PreXsdCodeGen 3 calls 58 ms _SetTargetFrameworkMonikerAttribute 3 calls 62 ms GetTargetPathWithTargetPlatformMoniker 3 calls 66 ms CoreCompile 3 calls 66 ms _GenerateSatelliteAssemblyInputs 3 calls 71 ms GetReferenceAssemblyPaths 3 calls 76 ms ImplicitlyExpandDesignTimeFacades 3 calls 81 ms ValidateSolutionConfiguration 1 calls 82 ms GetCopyToOutputDirectoryItems 3 calls 88 ms CopyFilesToOutputDirectory 3 calls 97 ms ResolveSDKReferences 3 calls 105 ms _CheckForInvalidConfigurationAndPlatform 3 calls 611 ms SplitResourcesByCulture 3 calls 642 ms CreateManifestResourceNames 1 calls 798 ms ResolveNuGetPackageAssets 2 calls 1008 ms FindReferenceAssembliesForReferences 3 calls 1177 ms _BuiltWebOutputGroupOutput 1 calls 1249 ms CoreResGen 3 calls 1632 ms IncrementalClean 3 calls 1659 ms _CopyFilesMarkedCopyLocal 2 calls 1984 ms _HandlePackageFileConflicts 3 calls 2005 ms _GetProjectReferenceTargetFrameworkProperties 3 calls 2292 ms AssignTargetPaths 3 calls 3007 ms _GenerateCompileDependencyCache 3 calls 4538 ms ResolveAssemblyReferences 3 calls 6253 ms _CleanGetCurrentAndPriorFileWrites 3 calls 25037 ms ResolveProjectReferences 3 calls 41369 ms Build 4 calls Task Performance Summary: 3 ms FindAppConfigFile 2 calls 6 ms MakeDir 3 calls 7 ms ResolveKeySource 3 calls 7 ms WriteLinesToFile 3 calls 7 ms Touch 2 calls 8 ms GetFrameworkPath 3 calls 12 ms GetReferenceAssemblyPaths 3 calls 27 ms AssignProjectConfiguration 3 calls 35 ms Message 10 calls 42 ms Delete 6 calls 52 ms CallTarget 3 calls 55 ms ResolveCodeAnalysisRuleSet 3 calls 99 ms GetReferenceNearestTargetFrameworkTask 2 calls 128 ms ReadLinesFromFile 3 calls 163 ms AssignCulture 3 calls 300 ms CreateCSharpManifestResourceName 2 calls 463 ms ResolveNuGetPackageAssets 2 calls 590 ms GenerateResource 1 calls 1007 ms ResolvePackageFileConflicts 3 calls 1177 ms CreateItem 3 calls 1498 ms Hash 3 calls 1661 ms ConvertToAbsolutePath 3 calls 1712 ms Copy 9 calls 2040 ms RemoveDuplicates 6 calls 2104 ms AssignTargetPath 18 calls 2583 ms FindUnderPath 15 calls 4530 ms ResolveAssemblyReference 3 calls 68091 ms MSBuild 10 calls 的方法中。然后构造函数将执行:

createCartForm()

重装将成为:

f = createCartForm();

我用新实例替换表单并删除默认转换,以便替换不会被动画化。