欢迎来到天天文库
浏览记录
ID:22284766
大小:111.97 KB
页数:7页
时间:2018-10-28
《实验五报告java语言与面向对象程序设计gui》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、洛阳理工学院实验报告系别计算机系班级学号姓名课程名称Java语言与面向对象程序设计实验曰期2015.05.2实验名称实验五GUI成绩实验目的:1.UseGUIcomponentstodesignGUIs,andhandleevents2.UseGraphics2Dtodrawgraphics3.Usestreamstoaccessfiles实验条件:电脑一台实验内容:Parti,writeawindowapplicationtocalculatethesumof2numbersinputfromthekeyboard.Thewindowsho
2、uldlooklikefig.1.Fig.1addingtonumbers源石马:packagecalculater;DButton;ZJFrame;JLabel;DPanel;DTextField;import"java.awt.Color;importjava.awt.FlowLayout;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjavax>swingimportjavax.swingimportjavax.swingimport
3、javax.swingimportjavax.swingpublicclassaddextendsDFrameimplementsActionListener{DPanelpanel;DLabeloneLabel;DLabeltwoLabel;ZJLabelthreeLabel;ZJButtonsumButton;DButtoncancelButton;DTextFieldoneTextField;DTextFieldtwoTextField;DTextFieldthreeTextField;publicadd(){panel=newDPan
4、el();this5、nListener(this);twoTextField•addActionListener(this);sumButton•addActionListener(this);cancelButton•addActionListener(this);panel.add(oneLabel);panel.add(oneTextField);panel.add(twoLabel);panelsadd(twoTextField);panel.add(threeLabel);panel.add(threeTextField);panel.add(sumB6、utton);panel.add(cancelButton);this.setSize(650,200);this.setVisible(true);}publicstaticvoidmain(String[]args){newadd();}^OverridepublicvoidactionPerformed(ActionEvente){if(e.getSource()==sumButton){Stringone=oneTextField•getText()7、im();intsum=Integer.parselnt(one)+Integer.porseInt(two);threeTextField•setText(String.vatueO/(sum));}elseif(e.getSource()==cancelButton){System>exit(0);}}}Part2.CreatethefollowingGUI.CE789/456123■攀0=+源码:importjava.awt.*;importjava8、calculatorprogram.*@seeDFrame*@seeActionListener*/publicclasscalculatorextendsJFra
5、nListener(this);twoTextField•addActionListener(this);sumButton•addActionListener(this);cancelButton•addActionListener(this);panel.add(oneLabel);panel.add(oneTextField);panel.add(twoLabel);panelsadd(twoTextField);panel.add(threeLabel);panel.add(threeTextField);panel.add(sumB
6、utton);panel.add(cancelButton);this.setSize(650,200);this.setVisible(true);}publicstaticvoidmain(String[]args){newadd();}^OverridepublicvoidactionPerformed(ActionEvente){if(e.getSource()==sumButton){Stringone=oneTextField•getText()7、im();intsum=Integer.parselnt(one)+Integer.porseInt(two);threeTextField•setText(String.vatueO/(sum));}elseif(e.getSource()==cancelButton){System>exit(0);}}}Part2.CreatethefollowingGUI.CE789/456123■攀0=+源码:importjava.awt.*;importjava8、calculatorprogram.*@seeDFrame*@seeActionListener*/publicclasscalculatorextendsJFra
7、im();intsum=Integer.parselnt(one)+Integer.porseInt(two);threeTextField•setText(String.vatueO/(sum));}elseif(e.getSource()==cancelButton){System>exit(0);}}}Part2.CreatethefollowingGUI.CE789/456123■攀0=+源码:importjava.awt.*;importjava8、calculatorprogram.*@seeDFrame*@seeActionListener*/publicclasscalculatorextendsJFra
8、calculatorprogram.*@seeDFrame*@seeActionListener*/publicclasscalculatorextendsJFra
此文档下载收益归作者所有