当我从购物车中删除产品时,我想刷新我的表单我尝试了所有方法但没有成功,有什么方法可以做到这一点吗?
我的 Cart 类显示了我的购物车中的产品,当我从购物车中删除产品时,我想刷新整个表单,但不知道该怎么做,我几乎尝试了所有方法,但仍然可以'完成了
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();
不要重新加载。重新创建并展示。
将所有代码从构造函数移动到名为的方法createCartForm()
。然后构造函数会执行以下操作:
f = createCartForm();
重新加载就会变成:
setF(h.createCartForm());
getCurrentForm().setTransitionOut(CommonTransitions.createEmpty());
h.getF().show();
我用新实例替换表单并删除默认过渡,这样替换就不会动画化。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)