JAVA编写售货机代码.docx
- 文档编号:27496877
- 上传时间:2023-07-02
- 格式:DOCX
- 页数:8
- 大小:16.30KB
JAVA编写售货机代码.docx
《JAVA编写售货机代码.docx》由会员分享,可在线阅读,更多相关《JAVA编写售货机代码.docx(8页珍藏版)》请在冰豆网上搜索。
JAVA编写售货机代码
package课题设计售货机;
importjava.awt.BorderLayout;
importjava.awt.Button;
importjava.awt.Dialog;
importjava.awt.Frame;
importjava.awt.Label;
importjava.awt.Panel;
importjava.awt.TextArea;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjavax.swing.text.AbstractDocument.BranchElement;
publicclassallmoneyextendsDialogimplementsActionListener{TextAreah=newTextArea();
Labela,money=newLabel(),b;
Buttonok=newButton("确定");
Panelc=newPanel();
allmoney(Framef,Strings,booleanm,TextAreat,Labell){super(f,s,m);
setBounds(400,300,200,400);
h=t;
money=l;
a=newLabel("总计:
");
b=newLabel("元”);
setBounds(400,300,300,300);add(h,BorderLayout.NORTH);
c.add(a);
c.add(money);
c.add(b);
add(c,BorderLayout.CENTER);add(ok,BorderLayout.SOUTH);ok.addActionListener(this);setVisible(true);}publicvoidactionPerformed(ActionEvente){
setVisible(false);}}
package课题设计售货机;
importjava.awt.BorderLayout;
importjava.awt.Button;
importjava.awt.Checkbox;
importjava.awt.Frame;
importjava.awt.GridBagLayout;
importjava.awt.GridLayout;
importjava.awt.Label;
importjava.awt.Panel;
importjava.awt.TextArea;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjava.awt.event.WindowAdapter;
importjava.awt.event.WindowEvent;
importjavax.crypto.Cipher;
publicclasswindowextendsFrameimplementsActionListener{Buttoncoffee=newButton("咖啡"),
coke二newButton(”可乐"),
bread二newButton(”面包"),
soda二newButton(”苏打(水?
)”),
chips二newButton(”薯片"),
gum二newButton(”口香糖"),jerky=newButton("牛肉干"),wafer=newButton("威化"),ok=newButton(”结账"),reset二newButton(”重置");
Labelcoffee_money二newLabel(售价35Y剩余:
"),
coke_money二newLabel(售价:
3.0Y剩余:
"),soda_money二newLabelC售价25Y剩余:
"),
chips_money二newLabel('售价:
3.5Y剩余:
"),
gum_money二newLabel('售价:
1.5Y剩余:
"),
jerky_money二newLabel("售价:
4Y剩余:
"),
wafer_money二newLabel("售价:
2.5Y剩余:
"),
bread_money二newLabelC售价:
1.5Y剩余:
"),
a,b,c,d,e,f,g,h;
Stringcoffee_remaing="10",coke_remaing="10",soda_reaming="10",chips_reaming="10",gum_reaming="10",jerky_reaming="10",wafer_reaming="10",
bread_reaming="10";floatsum=0;
intIcoffee=10,Icoke=10,Isoda=10,Ichips=10,Igum=10,Ijerky=10,Iwafer=10,Ibread=10;
Paneloverall=newPanel(),Pcoffee=newPanel(),Pcoke=newPanel(),Psoda=newPanel(),Pchips=newPanel(),Pgum=newPanel(),Pjerky=newPanel(),Pwafer=newPanel(),Pbread=newPanel(),sou=newPanel();
TextAreaT=newTextArea(货物清单",10,30);
window(){
setLayout(newBorderLayout());add(overall,BorderLayout.WEST);overall.setLayout(newGridLayout(4,2));overall.setSize(400,100);
Pcoffee.add(coffee);
Pcoffee.add(coffee_money);
Pcoffee.add(a=newLabel(coffee_remaing));overall.add(Pcoffee);//加入咖啡组件Pcoke.add(coke);
Pcoke.add(coke_money);
Pcoke.add(b=newLabel(coke_remaing));
overall.add(Pcoke);//加入可乐组件
Psoda.add(soda);
Psoda.add(soda_money);
Psoda.add(c=newLabel(soda_reaming));
overall.add(Psoda);//加入汽水组件
Pchips.add(chips);
Pchips.add(chips_money);
Pchips.add(d=newLabel(chips_reaming));
overall.add(Pchips);//加入薯片组件
Pgum.add(gum);
}Pgum.add(gum_money);
Pgum.add(e=newLabel(gum_reaming));
overall.add(Pgum);//加入口香糖组件
Pjerky.add(jerky);
Pjerky.add(jerky_money);
Pjerky.add(f=newLabel(jerky_reaming));
overall.add(Pjerky);//加入牛肉干组件
Pwafer.add(wafer);
Pwafer.add(wafer_money);
Pwafer.add(g=newLabel(wafer_reaming));
overall.add(Pwafer);//加入威化组价
Pbread.add(bread);
Pbread.add(bread_money);
Pbread.add(h=newLabel(bread_reaming));
overall.add(Pbread);//加入面包组件
T.setEditable(false);
add(T,BorderLayout.EAST);
sou.add(ok);
sou.add(reset);
add(sou,BorderLayout.SOUTH);
coffee.addActionListener(this);
coke.addActionListener(this);bread.addActionListener(this);soda.addActionListener(this);chips.addActionListener(this);gum.addActionListener(this);jerky.addActionListener(this);ok.addActionListener(this);reset.addActionListener(this);wafer.addActionListener(this);setTitle("******这是一个售货机~~(>_<)~~******");setBounds(400,100,750,320);
setVisible(true);setResizable(false);
addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){System.exit
(0);}});
publicvoidactionPerformed(ActionEvente){if(e.getSource()==coffee){if(Icoffee!
=0){
T.append("\n咖啡");
Icoffee-=1;
coffee_remaing=Integer.toString(Icoffee);a.setText(coffee_remaing);
sum+=3.5;}else{
a.setText(‘没了..");
T.append("\n咖啡卖完啦..~~(>_<)~~");}}elseif(e.getSource()==coke){if(Icoke!
=0){
T.append("\n可乐");
Icoke-=1;
coke_remaing=Integer.toString(Icoke);
b.setText(coke_remaing);
sum+=3;}else{
b.setText(”没了..");
T.append("\n可乐卖完啦..~~(>_<)~~");}}
elseif(e.getSource()==bread){
if(Ibread!
=0){
T.append("\n面包");
Ibread-=1;
bread_reaming=Integer.toString(Ibread);
h•S2.Texf(breadlreaming)八sum+H」.5」e-se宀h.saTeM二萍7•■)T.append>nsi®粉电匡••〜〜(VIA)〜〜二)p
e-seif(e.gefsource()HHSOdaxif(一sodaHo)宀
T.append>n序決》-Sodahnsodal「eaminglln(Dge「.fos5ng(-sodax
c.s2.Texf(sodal「eamingxsum+H2.5」e-se宀
c.saTexf(二萍7•■=)八
T.append>n••〜〜(VIA)〜〜二)pe-seif(e.gefsource()HHChipsx
if(-chipsHo)宀
T.append>n*午=)八
-ChipshnchipslreamingILn(Dger.fos3ng(-chips=
d•S2.Texf(chiPSIreamingysum+H3.5」e-se宀
d.saTeM二萍7•■)
-0二2
T.append("\n薯片卖完啦..~~(>_<)~~");}}
elseif(e.getSource()==gum){
if(Igum!
=0){
T.append("\n口香糖");
Igum-=1;
gum_reaming=Integer.toString(Igum);this.e.setText(gum_reaming);sum+=3.5;}else{
this.e.setText(”没了..");
T.append("\n口香糖卖完啦..~~(>_<)~~");}}
elseif(e.getSource()==jerky){
if(Ijerky!
=0){
T.append("\nxx");
Ijerky-=1;
jerky_reaming=Integer.toString(Ijerky);
f.setText(jerky_reaming);
sum+=3.5;}else{
f.setText(”没了..");
T.append("\n牛肉干卖完啦..~~(>_<)~~");}}
package课题设计售货机;
publicclasswindowmain{
publicstaticvoidmain(String[]args){windowwin=newwindow();}}
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- JAVA 编写 售货 代码
![提示](https://static.bdocx.com/images/bang_tan.gif)