刘敏1305110145java课设.docx

上传人:b****6 文档编号:13353301 上传时间:2023-06-13 格式:DOCX 页数:17 大小:150.09KB
下载 相关 举报
刘敏1305110145java课设.docx_第1页
第1页 / 共17页
刘敏1305110145java课设.docx_第2页
第2页 / 共17页
刘敏1305110145java课设.docx_第3页
第3页 / 共17页
刘敏1305110145java课设.docx_第4页
第4页 / 共17页
刘敏1305110145java课设.docx_第5页
第5页 / 共17页
刘敏1305110145java课设.docx_第6页
第6页 / 共17页
刘敏1305110145java课设.docx_第7页
第7页 / 共17页
刘敏1305110145java课设.docx_第8页
第8页 / 共17页
刘敏1305110145java课设.docx_第9页
第9页 / 共17页
刘敏1305110145java课设.docx_第10页
第10页 / 共17页
刘敏1305110145java课设.docx_第11页
第11页 / 共17页
刘敏1305110145java课设.docx_第12页
第12页 / 共17页
刘敏1305110145java课设.docx_第13页
第13页 / 共17页
刘敏1305110145java课设.docx_第14页
第14页 / 共17页
刘敏1305110145java课设.docx_第15页
第15页 / 共17页
刘敏1305110145java课设.docx_第16页
第16页 / 共17页
刘敏1305110145java课设.docx_第17页
第17页 / 共17页
亲,该文档总共17页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

刘敏1305110145java课设.docx

《刘敏1305110145java课设.docx》由会员分享,可在线阅读,更多相关《刘敏1305110145java课设.docx(17页珍藏版)》请在冰点文库上搜索。

刘敏1305110145java课设.docx

刘敏1305110145java课设

武汉轻工大学

数学与计算机学院

JAVA

课程设计

题目:

JAVA课程设计

专业:

计算机类

班级:

1303班

学号:

1305110145

姓名:

刘敏

指导老师:

蒋祖国老师

2015年 6月 2日

 

目录

实验一:

基于Swing的小游戏

1设计任务与要求······································3

1.1设计任务与要求··································3

1.2选题目的与意义··································3

2系统总体设计·········································3

2.1总体设计分析····································3

2.2程序结构········································3

3测试运行·············································4

3.1源程序··········································4

3.2运行结果········································6

4总结·················································7

实验二:

基于JSPservlet

 

实验一

1,设计任务与要求

1.1设计任务与要求

功能要求:

该程序用图形界面实现下面功能:

用计算机产生一个100以内的随机数,游戏者进行猜数,猜中即胜,猜不中,提示是大了还是小了,继续猜,直至猜对为止。

具体要求:

1)欢迎界面:

通过这里提供的选项(或按钮),进入游戏界面。

2)游戏界面提供“得到一个随机数”按钮,系统获取到随机数,游戏者输入自己的猜测结果,通过按“确认”按钮完成输入。

每次提示输入猜测结果时,给出猜测的准确度提示。

3)按“得到一个随机数”按钮,继续游戏。

1.2选题目的与意义

通过猜数游戏这个课题我可以学到文本框、标签框、按钮、布局、对话框方面的知识和应用,达到设计登陆界面、加入图像显示功能以及设计按钮的目的,让我更加的掌握和理解java面向对象语言的需求分析、系统设计,所以我选择猜数游戏这个课题。

2、系统设计

2.1总体设计分析

1随机数的获取:

玩家输入一个数字,数字的范围在1-100之间,系统获取随机数。

2输入输出模块:

对玩家输入的数字进行判断和提示。

如果玩家输入的不是系统要求的数字,系统将提示您,您输入的不是数字请重新输入.。

如果玩家输入的数字与随机生成数相比较,比随机生成数小.系统提示您,数字太小请您重新输入。

如果玩家输入的数字与随机生成数相比较,比随机生成数大.系统提示您,数字太大请您重新输入。

3结果输出模块:

直到用户猜到数字为止,提示信息是否继续猜数字,如果继续将进入下一次游戏,如果退出将退出游戏系统.

2.2程序结构点击“得到一个随机数”按钮,系统获取到一个随机数。

玩家输入一个数,如果玩家输入的数比系统给出的随机数小,系统会提示“猜小了”。

如果玩家输入的数比系统给出的随机数大,系统提示“猜大了”。

如果玩家猜对了数,系统会提示“猜对了”。

 

3、测试运行

3.1源程序

importjava.awt.Color;

importjava.awt.Container;

importjava.awt.FlowLayout;

importjava.awt.event.ActionEvent;

importjava.awt.event.ActionListener;

importjavax.swing.Box;

importjavax.swing.JButton;

importjavax.swing.JFrame;

importjavax.swing.JLabel;

importjavax.swing.JOptionPane;

importjavax.swing.JTextField;

classWindowButtonextendsJFrameimplementsActionListener{

privatestaticfinallongserialVersionUID=1L;

intnumber;

JTextFieldinputNumber;

JLabelfeedBack;

JButtonbuttonGetNumber,buttonEnter;

WindowButton(Strings){

super("猜数字小游戏");

buttonGetNumber=newJButton("得到一个随机数");

feedBack=newJLabel("无反馈信息",JLabel.CENTER);

feedBack.setBackground(Color.green);

inputNumber=newJTextField("0",5);

buttonEnter=newJButton("确定");

buttonEnter.addActionListener(this);

buttonGetNumber.addActionListener(this);

BoxboxH1=Box.createHorizontalBox();

boxH1.add(newJLabel("获取1-100之间的随机数:

"));

boxH1.add(buttonGetNumber);

BoxboxH2=Box.createHorizontalBox();

boxH2.add(newJLabel("输入您的猜测:

"));

boxH2.add(inputNumber);

BoxboxH3=Box.createHorizontalBox();

boxH3.add(newJLabel("单击确定按钮:

"));

boxH3.add(buttonEnter);

BoxboxH4=Box.createHorizontalBox();

boxH4.add(newJLabel("反馈信息:

"));

boxH4.add(feedBack);

BoxbaseBox=Box.createVerticalBox();

baseBox.add(boxH1);

baseBox.add(boxH2);

baseBox.add(boxH3);

baseBox.add(boxH4);

Containercon=getContentPane();

con.setLayout(newFlowLayout());

con.add(baseBox);

con.validate();

setBounds(120,125,279,200);

setVisible(true);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setBounds(100,100,150,150);

setVisible(true);

validate();

}

publicvoidactionPerformed(ActionEvente){

if(e.getSource()==buttonGetNumber){

number=(int)(Math.random()*100)+1;

}elseif(e.getSource()==buttonEnter){

intguess=0;

try{

guess=Integer.parseInt(inputNumber.getText());

if(guess==number){

JOptionPane.showMessageDialog(this,"猜对了");

}elseif(guess>number){

JOptionPane.showMessageDialog(this,"猜大了");

inputNumber.setText(null);

}elseif(guess

JOptionPane.showMessageDialog(this,"猜小了");

inputNumber.setText(null);

}

}catch(NumberFormatExceptionevent){

JOptionPane.showMessageDialog(this,"请输入数字字符");

}

}

}

}

publicclassGame{

publicstaticvoidmain(Stringargs[]){

newWindowButton("猜数字小游戏");

}

}

3.2运行结果

主页面如下,点击“得到一个随机数”按钮,

输入您的猜测:

50,系统会让其与产生的随机数比较而判断猜大了还是猜小了,然后重新猜

然后一直猜直到猜对为止

4、总结

猜数字是一款非常经典的脑力游戏,游戏规则简单,但是玩起来难度较大,是消磨时间、锻炼脑力的好选择。

通过选择猜数字这个游戏,可以让我掌握Java中的包和类,并且可以灵活使用MyElipse软件。

同时更加深入的了解字符界面的编程过程。

使我们更熟练掌握Java程序框架的搭建和类的创建格式。

在分析阶段,要进行面向对象的需求分析、系统设计等,这些工作更能锻炼我们的逻辑思维,更能培养我思考的全面性。

让我学会了多角度思考问题,对我以后的编程奠定了更好的基础。

 

实验二:

基于JSPservlet的产品信息

1、实验目的

1)掌握对JDBC基本操作步骤的简单封装

2)掌握Servlet和JSP结合使用

3)掌握MVC设计模式

4)掌握监听器、过滤器的使用

2,程序代码

packagewhpu.edu.servletmvc.model;

importjava.io.Serializable;

publicclassProductimplementsSerializable{

privatestaticfinallongserialVersionUID=748392348L;

privateStringname;

privateStringdescription;

privatefloatprice;

publicStringgetName(){

returnname;

}

publicvoidsetName(Stringname){

this.name=name;

}

publicStringgetDescription(){

returndescription;

}

publicvoidsetDescription(Stringdescription){

this.description=description;

}

publicfloatgetPrice(){

returnprice;

}

publicvoidsetPrice(floatprice){

this.price=price;

}

}

packagewhpu.edu.servletmvc.form;

publicclassProductForm{

privateStringname;

privateStringdescription;

privateStringprice;

publicStringgetName(){

returnname;

}

publicvoidsetName(Stringname){

this.name=name;

}

publicStringgetDescription(){

returndescription;

}

publicvoidsetDescription(Stringdescription){

this.description=description;

}

publicStringgetPrice(){

returnprice;

}

publicvoidsetPrice(Stringprice){

this.price=price;

}

}

packagewhpu.edu.servletmvc.action;

importwhpu.edu.servletmvc.model.Product;

 

publicclassSaveProductAction{

publicvoidsave(Productproduct){

//insertProducttothedatabase

}

}

/*

*GeneratedbytheJaspercomponentofApacheTomcat

*Version:

ApacheTomcat/7.0.37

*Generatedat:

2015-05-0412:

44:

47UTC

*Note:

Thelastmodifiedtimeofthisfilewassetto

*thelastmodifiedtimeofthesourcefileafter

*generationtoassistwithmodificationtracking.

*/

packagewhpu.edu.servletmvc;

importjavax.servlet.*;

importjavax.servlet.http.*;

importjavax.servlet.jsp.*;

publicfinalclassProductDetails_jspextendsorg.apache.jasper.runtime.HttpJspBase

implementsorg.apache.jasper.runtime.JspSourceDependent{

privatestaticfinaljavax.servlet.jsp.JspFactory_jspxFactory=

javax.servlet.jsp.JspFactory.getDefaultFactory();

privatestaticjava.util.Map_jspx_dependants;

privatejavax.el.ExpressionFactory_el_expressionfactory;

privateorg.apache.tomcat.InstanceManager_jsp_instancemanager;

publicjava.util.MapgetDependants(){

return_jspx_dependants;

}

publicvoid_jspInit(){

_el_expressionfactory=_jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();

_jsp_instancemanager=org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(getServletConfig());

}

publicvoid_jspDestroy(){

}

publicvoid_jspService(finaljavax.servlet.http.HttpServletRequestrequest,finaljavax.servlet.http.HttpServletResponseresponse)

throwsjava.io.IOException,javax.servlet.ServletException{

finaljavax.servlet.jsp.PageContextpageContext;

javax.servlet.http.HttpSessionsession=null;

finaljavax.servlet.ServletContextapplication;

finaljavax.servlet.ServletConfigconfig;

javax.servlet.jsp.JspWriterout=null;

finaljava.lang.Objectpage=this;

javax.servlet.jsp.JspWriter_jspx_out=null;

javax.servlet.jsp.PageContext_jspx_page_context=null;

 

try{

response.setContentType("text/html");

pageContext=_jspxFactory.getPageContext(this,request,response,

null,true,8192,true);

_jspx_page_context=pageContext;

application=pageContext.getServletContext();

config=pageContext.getServletConfig();

session=pageContext.getSession();

out=pageContext.getOut();

_jspx_out=out;

out.write("

DOCTYPEHTML>\r\n");

out.write("\r\n");

out.write("\r\n");

out.write("SaveProduct\r\n");

out.write("@importurl(css/main.css);\r\n");

out.write("\r\n");

out.write("\r\n");

out.write("\r\n");

out.write("

Theproducthasbeensaved.

\r\n");

out.write("

\r\n");

out.write("

Details:

\r\n");

out.write("ProductName:

");

out.write((java.lang.String)org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${product.name}",java.lang.String.class,(javax.servlet.jsp.PageContext)_jspx_page_context,null));

out.write("
\r\n");

out.write("Description:

");

out.write((java.lang.String)org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${product.description}",java.lang.String.class,(javax.servlet.jsp.PageContext)_jspx_page_context,null));

out.write("
\r\n");

out.write("Price:

$");

out.write((java.lang.String)org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${product.price}",java.lang.String.class,(javax.servlet.jsp.PageContext)_jspx_page_context,null));

out.write("\r\n");

out.write("

\r\n");

out.write("

\r\n");

out.write("\r\n");

out.write("");

}catch(java.lang.Throwablet){

if(!

(tinstanceofjavax.servlet.jsp.SkipPageException)){

out=_jspx_out;

if(out!

=null&&out.getBufferSize()!

=0)

try{out.clearBuffer();}catch(java.io.IOExceptione){}

if(_jspx_page_context!

=null)_jspx_page_context.handlePageException(t);

elsethrownewServletException(t);

}

}finally{

_jspxFactory.releasePageContext(_jspx_page_context);

}

}

}

 

packagewhpu.edu.servletmvc.controller;

importjava.io.IOException;

importjavax.servlet.RequestDispatcher;

importjavax.servlet.ServletException;

importjavax.servlet.annotation.WebServlet;

importjavax.servlet.http.HttpServlet;

importjavax.servlet.http.HttpServletRequest;

i

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2