JAVA项目实验报告Word文档格式.docx

上传人:b****4 文档编号:16579862 上传时间:2022-11-24 格式:DOCX 页数:12 大小:75.11KB
下载 相关 举报
JAVA项目实验报告Word文档格式.docx_第1页
第1页 / 共12页
JAVA项目实验报告Word文档格式.docx_第2页
第2页 / 共12页
JAVA项目实验报告Word文档格式.docx_第3页
第3页 / 共12页
JAVA项目实验报告Word文档格式.docx_第4页
第4页 / 共12页
JAVA项目实验报告Word文档格式.docx_第5页
第5页 / 共12页
点击查看更多>>
下载资源
资源描述

JAVA项目实验报告Word文档格式.docx

《JAVA项目实验报告Word文档格式.docx》由会员分享,可在线阅读,更多相关《JAVA项目实验报告Word文档格式.docx(12页珍藏版)》请在冰豆网上搜索。

JAVA项目实验报告Word文档格式.docx

Server.java、Objecting.java、LogIn.java、ClientUser.java、Client.java。

小时钟除了需要编写的上述5个Java源文件所给出的类外,还需要Java系统提供的一些重要的类,如JTextField、JTextArea和File类。

2.3运行环境

CPU:

Pentium2.8GHz以上

内存:

256MB以上

硬盘空间:

80G以上

操作系统:

WindowsXP

运行环境:

JDK,JCreator

2.4程序功能图及程序相关说明

2.4.1主功能框

图1程序基本框图

表1小时钟基本功能表

序号

文件名

主要功能

1

ServerHost

被服务器调用

2

Client

显示小时钟

3

ClientUser

被客户端调用

4

LogIn

注册登陆

5

Objecting

连接小时钟

6

Server

启动小时钟

2.4.2程序分析

程序中引入的包:

packageClock

importjava.awt.Clock

importjava.awt.Graphics

importjava.awt.event.WindowAdapter

importjava.awt.event.WindowEvent

importjava.util.Calendar

importjava.util.GregorianCalendar

用户自定义类:

类名:

Clock

作用:

定义小时钟

继承的父类:

JFrame

publicclassclockextendsJFrame{

定义的对象:

ClockPaint

size

Resizable

Location

Title

Visible

WindowListener,WindowClosing

主要成员方法:

publicvoidcenter//定义小程序查看器的位置

publicvoidactionPerformed//定义处理异常机制

定义子类:

ClockPaint

继承的父类名:

JPanel

继承的接口名:

Runnable

classClockPaintextendsJPanelimplementsRunnable

inth,m,s//小时,分钟,秒

publicClockPaint

this.x=x

this.y=y

this.r=r

s=now.get(Calendar.SECOND)*6//获得秒转换成度数

m=now.get(Calendar.MINUTE)*6//获得分钟

h=(now.get(Calendar.HOUR_OF_DAY)-12)*30+now.get(Calendar.MINUTE)/12*6//获得小时

publicvoidpaint(Graphicsg)//清屏

super.paint(g)

g.setColor(Color.BLACK)

g.fillRect(0,0,r*3,r*3)//画圆

g.setColor(Color.WHITE)

g.drawOval(x,y,r*2,r*2)//秒针

g.setColor(Color.RED)

intx1=(int)((r-10)*Math.sin(rad*s))

inty1=(int)((r-10)*Math.cos(rad*s))

g.drawLine(x+r,y+r,x+r+x1,y+r-y1)//分针

g.setColor(Color.BLUE)

x1=(int)((r-r/2.5)*Math.sin(rad*m))

y1=(int)((r-r/2.5)*Math.cos(rad*m))

g.drawLine(x+r,y+r,x+r+x1,y+r-y1)//时针

g.setColor(Color.CYAN)

x1=(int)((r-r/1.5)*Math.sin(rad*h))

y1=(int)((r-r/1.5)*Math.cos(rad*h))

g.drawLine(x+r,y+r,x+r+x1,y+r-y1)//数字

g.setColor(Color.YELLOW)

intd=29

for(inti=1;

i<

=12;

i++)

x1=(int)((r-10)*Math.sin(rad*d))

y1=(int)((r-10)*Math.cos(rad*d))

g.drawString(i+"

"

x+r+x1-4,x+r-y1+5)

d+=30//小点

d=0;

for(inti=0;

60;

x1=(int)((r-2)*Math.sin(rad*d))

y1=(int)((r-2)*Math.cos(rad*d))

g.drawString("

."

x+r+x1-1,x+r-y1+1)

d+=6//显示时间

//Calendarnow1=newGregorianCalendar();

//g.drawString(now1.get(Calendar.HOUR_OF_DAY)+"

//+now1.get(Calendar.MINUTE)+"

+now1.get(Calendar.SECOND),

//0,10);

publicvoidrun

捕获异常

catch(Exceptionex)

完成显示实时数据

s+=6

if(s>

=360)

s=0

m+=6

if(m==72||m==144||m==216||m==288)

h+=6

if(m>

m=0

h+=6;

if(h>

h=0;

this.repaint();

3.设计结果与分析

将5个Java源文件:

分别编译这5个Java源文件,或运行“javac*.java”命令,编译全部的源文件,然后运行连接服务器的主类,即运行Clock类。

连接完毕后在运行注册的主函数类,即运行LogIn类。

运行Clock.java,运行结果如下:

图2查看实时时间

4.设计总结

4.1遇到的问题和解决方法

在用JAVA编写程序时,我遇到了很多困难,对很多的接口,类,方法都不是很熟悉,只好采用查看API文档,一个一个进行对照学习,同时也上网查看了有关小时钟的相关描述,还向同学请教了,翻阅了相关的书籍。

尤其是因为有些方法需要使用JDK1.6才行,所以在学校网络机房一开始不能运行,在安装了1.6版本后运行正常了。

4.2设计心得

花费了近一个多星期的时间,查阅了许多相关的资料,终于把这个Java小时钟,程序基本实现了该课程设计的基本要求。

在设计的过程中了解到自己的知识还是比较有限,更肯定了自己在以后学习编程的道路上坚定不移的但由于只学习了一个学期的JAVA语言,自己水平有限,使得程序还有不是很完善回顾起此次java,至今我仍感慨颇多,的确,从选题到定稿,从理论到实践,在整整一星期的日子里,可以说得是苦多于甜,但是可以学到很多很多的的东西,同时不仅可以巩固了以前所学过的知识,而且学到了很多在书本上所没有学到过的知识。

通过这次课程设计使我懂得了理论与实际相结合是很重要的,只有理论知识是远远不够的,只有把所学的理论知识与实践相结合起来,从理论中得出结论,才能真正掌握这门技术,也提高了自己的独立思考的能力。

在设计的过程中遇到问题,可以说得上是困难重重,这毕竟第一次做的,难免会遇到过各种各样的问题,同时在设计的过程中发现了自己的不足之处,对以前所学过的知识理解得不够深刻,掌握得不够牢固,通过这次课程设计之后,一定把以前所学过的知识重新温故。

通过此次课程设计,将我本学期所学的JAVA知识得到巩固和应用,在设计的过程中我遇到了很到问题,不过在老师和同学们的帮助和自己的思考下还是很好的完成了。

这此课程设计还让我懂得了写程序不能闭门造车,要努力拓宽知识面,开阔视野,拓展思维。

它还让我学会了在网上查阅那些无限的资料。

让我不仅学会了书本上的知识,还让自己能够面对困难并且克服它。

5.主要代码:

importjava.awt.Color;

importjava.awt.Graphics;

importjava.awt.event.WindowAdapter;

importjava.awt.event.WindowEvent;

importjava.util.Calendar;

importjava.util.GregorianCalendar;

importjavax.swing.JFrame;

importjavax.swing.JPanel;

/**

*时间类

**

*/

publicclassClockextendsJFrame{

/**

*

*/

privatestaticfinallongserialVersionUID=1L;

publicClock(){

ClockPaintcp=newClockPaint(20,20,70);

this.add(cp);

this.setSize(200,200);

this.setResizable(false);

this.setLocation(260,120);

this.setTitle("

小时钟"

);

this.setVisible(true);

addWindowListener(newWindowAdapter(){

publicvoidwindowClosing(WindowEvente){

System.exit(0);

}

});

publicstaticvoidmain(String[]s){

newClock();

}

classClockPaintextendsJPanelimplementsRunnable{

intx,y,r;

inth,m,s;

//小时,分钟,秒

doublerad=Math.PI/180;

publicClockPaint(intx,inty,intr){

this.x=x;

this.y=y;

this.r=r;

Calendarnow=newGregorianCalendar();

s=now.get(Calendar.SECOND)*6;

//获得秒转换成度数

m=now.get(Calendar.MINUTE)*6;

//获得分钟

h=(now.get(Calendar.HOUR_OF_DAY)-12)*30

+now.get(Calendar.MINUTE)/12*6;

//获得小时

Threadt=newThread(this);

t.start();

publicvoidpaint(Graphicsg){

//清屏

super.paint(g);

g.setColor(Color.BLACK);

g.fillRect(0,0,r*3,r*3);

//画圆

g.setColor(Color.WHITE);

g.drawOval(x,y,r*2,r*2);

//秒针

g.setColor(Color.RED);

intx1=(int)((r-10)*Math.sin(rad*s));

inty1=(int)((r-10)*Math.cos(rad*s));

g.drawLine(x+r,y+r,x+r+x1,y+r-y1);

//分针

g.setColor(Color.BLUE);

x1=(int)((r-r/2.5)*Math.sin(rad*m));

y1=(int)((r-r/2.5)*Math.cos(rad*m));

//时针

g.setColor(Color.CYAN);

x1=(int)((r-r/1.5)*Math.sin(rad*h));

y1=(int)((r-r/1.5)*Math.cos(rad*h));

//数字

g.setColor(Color.YELLOW);

intd=29;

for(inti=1;

i++){

x1=(int)((r-10)*Math.sin(rad*d));

y1=(int)((r-10)*Math.cos(rad*d));

g.drawString(i+"

x+r+x1-4,x+r-y1+5);

d+=30;

//小点

d=0;

for(inti=0;

x1=(int)((r-2)*Math.sin(rad*d));

y1=(int)((r-2)*Math.cos(rad*d));

g.drawString("

x+r+x1-1,x+r-y1+1);

d+=6;

//显示时间

//Calendarnow1=newGregorianCalendar();

publicvoidrun(){

while(true){

try{

Thread.sleep(1000);

}catch(Exceptionex){

s+=6;

if(s>

=360){

s=0;

m+=6;

if(m==72||m==144||m==216||m==288){

h+=6;

if(m>

m=0;

if(h>

h=0;

this.repaint();

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

当前位置:首页 > 成人教育 > 自考

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

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