《网络编程技术》课程实验指导书Word文档格式.docx

上传人:b****8 文档编号:22128868 上传时间:2023-02-02 格式:DOCX 页数:11 大小:17.57KB
下载 相关 举报
《网络编程技术》课程实验指导书Word文档格式.docx_第1页
第1页 / 共11页
《网络编程技术》课程实验指导书Word文档格式.docx_第2页
第2页 / 共11页
《网络编程技术》课程实验指导书Word文档格式.docx_第3页
第3页 / 共11页
《网络编程技术》课程实验指导书Word文档格式.docx_第4页
第4页 / 共11页
《网络编程技术》课程实验指导书Word文档格式.docx_第5页
第5页 / 共11页
点击查看更多>>
下载资源
资源描述

《网络编程技术》课程实验指导书Word文档格式.docx

《《网络编程技术》课程实验指导书Word文档格式.docx》由会员分享,可在线阅读,更多相关《《网络编程技术》课程实验指导书Word文档格式.docx(11页珍藏版)》请在冰豆网上搜索。

《网络编程技术》课程实验指导书Word文档格式.docx

publicvoidpaint(Graphicsg){

g.drawString("

Hello"

50,100);

}

2基本用户界面设计

调试下面“计算器”程序,理解事件响应机制。

importjava.awt.*;

importjava.awt.event.*;

importjavax.swing.*;

publicclassCalculatorTestextendsJFrameimplementsActionListener{

JLabellabel1=newJLabel("

PleaseInputTheFirstNum"

);

JLabellabel2=newJLabel("

PleaseInputTheSecondNum"

JLabellabel3=newJLabel("

TheResultis"

JTextFieldtext1=newJTextField(15);

JTextFieldtext2=newJTextField(15);

JTextFieldtext3=newJTextField(15);

JButtonbutton1=newJButton("

加"

JButtonbutton2=newJButton("

减"

JButtonbutton3=newJButton("

乘"

JButtonbutton4=newJButton("

除"

publicCalculatorTest(){

super("

calculatorTest"

Containerc=getContentPane();

c.setLayout(newFlowLayout());

c.add(label1);

c.add(text1);

c.add(label2);

c.add(text2);

c.add(button1);

c.add(button2);

c.add(button3);

c.add(button4);

c.add(label3);

c.add(text3);

button1.addActionListener(this);

button2.addActionListener(this);

button3.addActionListener(this);

button4.addActionListener(this);

addWindowListener(

newWindowAdapter(){

publicvoidwindowClosing(WindowEvente){

System.exit(0);

}

}

);

setSize(220,250);

}

publicvoidactionPerformed(ActionEvente){

floata1,a2,a3;

Stringstr1,str2;

str1=text1.getText();

a1=Float.valueOf(str1).floatValue();

str2=text2.getText();

a2=Float.valueOf(str2).floatValue();

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

a3=a1+a2;

text3.setText(str1+"

+"

+str2+"

="

+String.valueOf(a3));

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

a3=a1-a2;

-"

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

a3=a1*a2;

*"

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

a3=a1/a2;

/"

}

publicstaticvoidmain(Stringargs[]){

JFrameframe=newCalculatorTest();

frame.show();

3多线程程序设计

参考下面程序结构,利用多线程技术实现动态时钟。

importjava.applet.*;

importjava.util.*;

publicclassRunnableDemoextendsAppletimplementsRunnable{

ThreadclockThread;

publicvoidstart(){

//启动多线程

publicvoidrun(){

//多线程运行主体

publicvoidpaint(Graphicsg){

//重画功能实现

publicvoidstop(){

//线程停止

实验三服务器端小程序设计

1虚拟服务器环境配置

2掌握基本的Servlet程序设计

3完成基本的表单提交和处理程序设计

网络计算机,Jcreatorpro2.0,JDK1.4,Windows2000,JSWDK1.0.1

1虚拟服务器环境配置

根据JSWDK1.0.1的安装说明,配置虚拟服务器环境

2基本Servlet程序设计

调试下面服务器端小应用程序,并根据配置的虚拟服务器环境发布这一Servlet程序,理解Servlet的运行与Applet运行过程的不同之处。

importjava.io.*;

importjavax.servlet.*;

importjavax.servlet.http.*;

publicclassWelcomeServletextendsHttpServlet{

publicvoiddoGet(HttpServletRequestrequset,

HttpServletResponseresponse)

throwsIOException,ServletException{

response.setContentType("

text/html"

PrintWriterout=response.getWriter();

out.println("

<

HTML>

"

HEAD>

TITLE>

Hello"

/TITLE>

BODY>

H1>

Hello,,welcometoStar'

sJSPsite.<

/H1>

+

"

欢迎访问Star的主页<

h2>

AHREF=\"

HTTP:

//localhost:

8080/star\"

>

进入Star的主页<

/A>

/h2>

/BODY>

3表单提交和处理程序设计

下面为一表单处理程序框架,根据这一框架完成程序设计,并完成相应的表单提交Html程序设计。

publicclassSurveyextendsHttpServlet{

publicvoiddoPost(HttpServletRequestreq,HttpServletResponseres)

throwsServletException,IOException

{

//设置响应头部

//得到响应的PrintWriter以返回文本给客户端.

try{

//打开一个文件写入Survey的结果.

//从客户端得到表单数据,存贮在文件中

//关闭文件.

//返回感谢信息给客户端

}catch(IOExceptione){

e.printStackTrace();

toClient.println("

Aproblemoccuredwhilerecordingyouranswers. "

+"

Pleasetryagain."

//关闭writer;

响应完成.

实验四综合实例

1掌握JSP的基本程序设计

2掌握基于JDBC的数据库访问

3完成简单网上书店程序设计

1JSP的基本程序设计

完成下面程序调试,体会JavaBean在程序设计中的运用

%@pagelanguage="

java"

%>

jsp:

useBeanid="

taxbean"

scope="

application"

class="

tax.TaxRate"

/>

修改前:

br>

 产品:

<

%=taxbean.getProduct()%>

 税率:

%=taxbean.getRate()%>

%taxbean.setProduct("

A002"

taxbean.setRate(20.5);

修改后:

产品:

/HTML>

//TaxRate.java

%@pageimport="

java.util.*"

%>

%=(newjava.util.Date()).toLocaleString()%>

TaxRate.java:

packagetax;

publicclassTaxRate{

StringProduct;

doubleRate;

publicTaxRate(){

this.Product="

A001"

;

this.Rate=5;

publicvoidsetProduct(StringProductName){

this.Product=ProductName;

publicStringgetProduct(){

return(this.Product);

publicvoidsetRate(doublerateValue){

this.Rate=rateValue;

publicdoublegetRate(){

return(this.Rate);

2基于JDBC的数据库访问程序设计

下面为基于JDBC的数据库访问程序,根据这一程序,利用Access建立相应的数据库文件,调试程序,观察运行结果。

importjava.sql.*;

classtestJDBC{

StringsDBDriver="

sun.jdbc.odbc.JdbcOdbcDriver"

StringsConnStr="

jdbc:

odbc:

faq"

//数据源名称faq

Connectionconn=null;

ResultSetrs=null;

publictestJDBC(){

try{Class.forName(sDBDriver);

}

catch(java.lang.ClassNotFoundExceptione){

System.err.println("

testJDBC():

+e.getMessage());

}

}

publicResultSetexecuteQuery(StringtestJDBC){

rs=null;

try{conn=DriverManager.getConnection(sConnStr);

Statementstmt=conn.createStatement();

rs=stmt.executeQuery(testJDBC);

}catch(SQLExceptionex){

aq.executeQuery:

+ex.getMessage());

returnrs;

publicclassrunJDBC{

publicstaticvoidmain(Stringarg[]){

testJDBCRJDBC=newtestJDBC();

ResultSetr=RJDBC.executeQuery("

SELECT*FROM地址"

//查询数据表名称faqs

try{r.next();

System.out.println(r.getString("

名字"

));

//获得表中项subject

}catch(Exceptione){System.out.println("

no"

3简单网上书店程序设计

参考1、2项实验内容中的程序范例,利用JavaBean,JDBC,JSP技术完成简单的网上书店程序设计。

要求程序具有图书展示(三本书),加入购物车,购物篮展示,移出商品,继续购物,交银台,结账单功能。

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

当前位置:首页 > PPT模板 > 可爱清新

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1