java购物车和订单 java购物车代码

09-27 游戏 投稿:简香旋

大家好,小衣来为大家解答以上的问题。java购物车和订单,java购物车代码这个很多人还不知道,现在让我们一起来看看吧!

1、import java.awt.*;import java.awt.event.*;class ShopFrame extends Frame implements ActionListener{ Label label1,label2,label3,label4; Button button1,button2,button3,button4,button5; TextArea text; Panel panel1,panel2; static float sum=0.0f; ShopFrame(String s) { super(s); setLayout(new BorderLayout()); label1=new Label("面纸:3元",Label.LEFT); label2=new Label("钢笔:5元",Label.LEFT); label3=new Label("书:10元",Label.LEFT); label4=new Label("袜子:8元",Label.LEFT); button1=new Button("加入购物车"); button2=new Button("加入购物车"); button3=new Button("加入购物车"); button4=new Button("加入购物车"); button5=new Button("查看购物车"); text=new TextArea("商品有:"+"",5,10); text.setEditable(false); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } } ); button1.addActionListener(this); button2.addActionListener(this); button3.addActionListener(this); button4.addActionListener(this); button5.addActionListener(this); panel1=new Panel(); panel2=new Panel(); panel1.add(label1); panel1.add(button1); panel1.add(label2); panel1.add(button2); panel1.add(label3); panel1.add(button3); panel1.add(label4); panel1.add(button4); panel2.setLayout(new BorderLayout()); panel2.add(button5,BorderLayout.NORTH); panel2.add(text,BorderLayout.SOUTH); this.add(panel1,BorderLayout.CENTER); this.add(panel2,BorderLayout.SOUTH); setBounds(100,100,350,250); setVisible(true); validate(); } public void actionPerformed(ActionEvent e) { if(e.getSource()==button1) { text.append("一个面纸、"); sum=sum+3; } else if(e.getSource()==button2) { text.append("一只钢笔、"); sum=sum+5; } else if(e.getSource()==button3) { text.append("一本书、"); sum=sum+10; } else if(e.getSource()==button4) { text.append("一双袜子、"); sum=sum+8; } else if(e.getSource()==button5) { text.append(""+"总价为:"+""+sum); } } }public class Shopping { public static void main(String[] args) { new ShopFrame("购物车"); }}我没用Swing可能显示不出来你的效果。

2、不满意得话我在给你编一个。

3、楼上你太有才了,20分 你还在编一个!!赞一个,人品!这个问题,估计没人回答你,为什么 自己去想吧网上不是一大堆么。

本文到此分享完毕,希望对大家有所帮助。

免责声明:本文由用户上传,如有侵权请联系删除!

声明:生活头条网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系admin@gdcyjd.com