JAVA课程设计写字留痕.docx

上传人:b****8 文档编号:29633725 上传时间:2023-07-25 格式:DOCX 页数:13 大小:189.71KB
下载 相关 举报
JAVA课程设计写字留痕.docx_第1页
第1页 / 共13页
JAVA课程设计写字留痕.docx_第2页
第2页 / 共13页
JAVA课程设计写字留痕.docx_第3页
第3页 / 共13页
JAVA课程设计写字留痕.docx_第4页
第4页 / 共13页
JAVA课程设计写字留痕.docx_第5页
第5页 / 共13页
点击查看更多>>
下载资源
资源描述

JAVA课程设计写字留痕.docx

《JAVA课程设计写字留痕.docx》由会员分享,可在线阅读,更多相关《JAVA课程设计写字留痕.docx(13页珍藏版)》请在冰豆网上搜索。

JAVA课程设计写字留痕.docx

JAVA课程设计写字留痕

 

山东工商学院

《JAVA程序设计》课程设计报告

 

报告题目:

JAVA写字留痕

所在院系:

计算机科学与技术学院

所在班级:

网络工程

姓名:

***

 

一.设计思路

1.作为日记本,为了保密性,设计了登陆界面,只有知道密码才能登陆到主界面,在主界面文本区,右键单击菜单可以进行密码的修改。

如上图。

 

2.主界面用了两个Jpanel。

左边的图片,日历等为一个JPanel;右边的文本框,JButton等为另一个JPanel。

两个JPanel都是用的GridLayout,主界面的JFram用的是FlowLayout。

如上图。

3.当更换日期,关闭窗口,点击保存,都能把当前日期的日记保存到磁盘上。

4.当更换年月后,要先选择日期才能在文本区进行输入,否则会提示选择日期。

JLable的显示内容会变为“请选择日期”。

如下图。

 

二.实现代码

1.登陆界面的代码,只有输入正确的密码才能登陆日记程序。

publicclassPassValidateextendsJFrameimplementsActionListener{

JPasswordFieldpassfield;

JLabellabel,title1,title2,title3,title4;

JButtonyes,cancle;

PassValidate(){

super("登录");

setDefaultCloseOperation(3);

Toolkittool=();

Imageim=("");

(im);文本区JPanel的实现代码。

publicclassFileEditorextendsJPanelimplementsActionListener{

JPanelbuttonPanel;

staticJLabeltitle;

JTextAreaWithMenut;

JButtonsave,delete,inport,outport;

booleandateexistence=true;

intyear;

intmouth;

intday;

Hashtabledata

=newHashtable();

Filefile=newFile("data\\");

ObjectOutputStreamhashOut;

ObjectInputStreamhashIn;

Stringjournalpass;

rim().equals("")){

(year)+(mouth)+(day));

}

if(!

().trim().equals("")){

try{

(year)+(mouth)+(day),());

(data);

();

"indatasave");主界面,把两个JPanel组成一个日记程序的主界面。

publicclassJournalTestextendsJFrameimplementsWindowListener{

FileEditorfe;

JournalTest(){

super("写字留痕");

setDefaultCloseOperation(3);

(this);

Toolkittool=();

Imageim=("");

(im);日历,图片,Spinner的JPanel。

publicclassYearMouthextendsJPanelimplementsChangeListener,MouseListener{

privateintyear;

privateintmouth;

privateintday;

privateJLabely1;

privateJLabelm1;

privateJLabelpic;

JSpinnershowyear;

JSpinnershowmouth;

SpinnerNumberModelyearmodel,mouthmodel;

JPanelspinner;

JPanelarrnum;

JTextField[]showDay;

FileEditorfe;

YearMouth(FileEditorfe){

=fe;

(newBorderLayout(5,5));

ymInit();etFont(newFont("TimesRomn",,16));

(title[i]);

}

arrangeNum(year,mouth,day);

}

voidarrangeNum(intyear,intmouth,intday){

intdays=(year,mouth);

Calendarc=();

"days:

"+days);etText(""+n);

showDay[i].setBackground(newColor(238,238,238));

if(year,mouth,n)&&day!

=n){

showDay[i].setForeground;

showDay[i].setFont(newFont("TimesRomn",,20));

}etFont(newFont("TimesRomn",,20));

showDay[i].setBackground;

showDay[i].setForeground;

}etForeground;

}ddMouseListener(this);

}

for(inti=0;i<42;i++){

if(i=first+days){

showDay[i].setBackground(newColor(238,238,238));

showDay[i].setText("");

}

}etEditable(false);

showDay[i].setColumns

(2);etFont(newFont("TimesRomn",,16));etHorizontalAlignment;etForeground;

showDay[first+day-1].setBackground(newColor(238,238,238));

showDay[first+day-1].setFont(newFont("TimesRomn",,20));

}etBackground(newColor(238,238,238));

showDay[first+day-1].setForeground;

showDay[first+day-1].setFont(newFont("TimesRomn",,16));

}弹出式菜单,右键单击可以更改文本的字体,登陆密码。

publicclassFontPopupextendsJPopupMenuimplementsActionListener{

String[]item;

Font[]font;

JMenuItemmt;

JTextAreat;

FontPopup(JTextAreat){

=t;

(newBevelBorder);

item=newString[]{"标准仿宋","粗放行楷","规矩新魏","精致宋体","灵感隶书"};

font=newFont[]{

newFont("仿宋",0,18),

newFont("华文行楷",0,30),

newFont("华文新魏",0,22),

newFont("宋体",0,14),

newFont("隶书",0,20),

};

for(inti=0;i<;i++){

mt=newJMenuItem(item[i]);

(newFont("仿宋",0,14));

(mt);

(this);

}

mt=newJMenuItem("修改密码");

(newFont("仿宋",0,14));

(mt);

(this);

}

@Override

publicvoidactionPerformed(ActionEvente){

DateTime类的实现,为程序提供系统日期处理方法。

ublicclassDateTime{

staticCalendarcc=();

staticintgetYear(){

return;

}

staticintgetMouth(){

return+1;

}

staticintgetDay(){

return;

}

staticintgetMonDay(intyear,intmouth){

intdays;

switch(mouth){

case1:

case3:

case5:

case7:

case8:

case10:

case12:

{days=31;break;}

case2:

{

if((year%4==0&&year%100!

=0)||year%400==0){

days=29;

break;

}

else{

days=28;

break;

}

}

default:

days=30;

}

returndays;

}

staticbooleanisWenkend(intyear,intmouth,intday){

booleanvalue=false;

Calendarc=();

(year,mouth-1,day);

intfirst=;

if(first==6||first==7)

value=true;

returnvalue;

}

}

8.打开文件时的过滤,只显示txt文件。

ublicclassTxtFilterextendsFileFilter{

@Override

publicbooleanaccept(Filef){

oLowerCase().trim();

if(".txt"))returntrue;

returnfalse;

}

@Override

publicStringgetDescription(){

导出日记文件的时候,输入密码为明文。

如下图。

2.spinner中的文本框,当输入非法内容的时候没有进行提示。

如下图。

 

3.因为改变主界面窗口的大小不会是的各个组件的大小等比例的变大变小,所以把主界面设置为不可改变大小。

如下图。

4.未能实现自动创建磁盘日记保存文件。

当文件缺失时,程序无法运行,并给出提示,如下图。

5.没有对密码文件进行加密,有记事本打开文件就可以看到明文的密码。

四.心得与收获

通过这次的课程设计,不仅让自己使自己学的到课本知识得到了充分的运用,还极大的丰富了课本外的知识。

通过上网,以及API的查询来实现自己对程序的想法。

如上述,程序实现的过程中还是有很多的不足需要改进。

程序设计时并没有领悟java的面相对象的编程思想,所以在编写过程中程序显得很混乱,需要很多的改进。

 

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

当前位置:首页 > 经管营销 > 经济市场

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

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