java课程设计带源代码

2023-06-20

第一篇:java课程设计带源代码

c语言课程设计-学籍管理系统(含源代码)

课 程 设 计 课程设计名称: C语言程序设计 题 目:学籍管理系统 学 生 姓 名: 学生学号 : 学 院(系): 软件学院 专 业 班 级: 112021 指 导 教 师:

设计时间: 2012 年 9 月 日  2012 年 9月_ 14 日

实验题目:学籍管理系统

一、实验目的

综合应用所学的C语言程序设计知识,自行设计并实现一个较为完整的小型管理信息系统。通过系统分析、系统设计、编程实现,写实验报告等环节,初步掌握软件系统的设计方法和步骤,提高灵活运用程序语言进行软件开发的技能,提高程序设计水平和分析问题、解决问题的能力。

二、实验内容

1):熟悉C语言的开发环境,按照给定的上机步骤练习完成;

2):熟悉C程序的编辑,编译,链接和运行的过程。 3):编译一个应用系统程序,形成一个软件系统。

三.实验要求

1.1、 分析系统功能

(1)用户进入主菜单后,就会在看到,菜单选项中添加有系统的各项功能,进入的

应的选项就可进行相应的操作.其主要功能有:

1、录入学生信息

2、删除学生信息

3、查询学生信息

4、学生信息排序

5、改学生信息

6、保存退出系统

(2) 用户选择所需操作的选项,进入相应的操作界面,在这里用户就可开始进行操作。

四、 使用说明

学生学籍管理系统是针对学生信息的管理,主要功能是添加学生信息、删除学生信息、查询学生信息、学生信息排序、修改学生信息、保存信息。

1,用户打开程序,进入主界面,输入学生信息如图

2,按回车进入主菜单,列出各项功能如图

输入1,是查询整个班级的学生的信息,如图

输入2,是查询个别学生的信息,如查询第一学生的信息,如图

输入3,是删除个别学生的信息,如删除第一个学生,如图

输入4,是插入某些学生的信息,如插入第三个,如图

输入5,是修改某个同学的信息,如删除第一个,如图

三、心得体会

两周的课程过起来其实也是很快的。这是我第一次做课程设计,起初还没做的时候觉得很快自己就将得编一个较大的程序,将会很有意思。带着最初的好奇心,新鲜感就这样开始了第一天的编程,结果是大失所望。做课程设计并不是自己想象中的那样有意思,而是很枯燥,很乏味的。也没想象中的那样简单,并不是像我们平时上C语言课时,每次编的那些小程序,没那么简单。我们现在要做的就是将我们平时学的,做的那些小程序都合理的凑到一块儿来。而把这些小程序都加到一块儿来,并不是随意的将它们放到一个程序中就完事的,而是必须得合理,且得顾及到各个方面。

正是由于编程的纷繁复杂,且结构的严谨,因此编程的过程中到处是困难和问题。它考验的不仅是我们的平时用功程度,以及我们对所学知识的熟练掌握程度、应用的灵活程度,它还考验我们的毅力。在刚开始的几天时,由于前一阵忙于各科的考试,C语言已经好久没碰了,所学的知识都有点遗忘了,在编写时处处碰壁,一直会停顿翻书,编得自己都开始心烦意乱了,实在是编不下去了,于是索性就停了三天去看书,先把书给吃透。并在后期的程序调试中也碰到不少的问题,好多问题自己反复检查了几遍都没查出,但在老师的帮助下还是一下就查出了。并不是这些问题多难,而是不够心细。因此做课程设计、编程时,它还考验并锻炼我们的心细程度。

经过这次的课程设计的实践,我受益颇多,不仅是对我掌握知识、灵活运用知识的一次考验和锻炼,也是对我生活态度的一次锻炼,让我学会心细和拥有毅力,更具信心和恒心,碰到困难不再退缩,而是坚强面对。

四,程序编码

/*做一个学生的学籍管理系统,有输入,查询,删除,增加,修改等功能*/ #include /*程序需要的头文件*/ #include

#include #include #include #define SIZE 4

/*声明数组的大小,可以任意改动*/ int board[50][50]; /*声明一个表格的数组*/ int cur_x, cur_y; /*定义坐标*/

void init();/*声明一个初始化界面的函数*/ void clear(); /*清除界面的函数*/

void draw_board();/*声明一个函数画表格*/ struct student{/*创建一个学生的结构体*/

char stuNo[8];

/*学生的学号*/

char name[10];/*学生的姓名*/

char sex[2]; /*学生的性别*/

char score[4];

/*学生的分数*/

char address[10];/*学生的地址*/ }; void init() /*初始化函数*/ {

int gdriver, gmode, i, j;

gdriver = DETECT; /*图形界面的驱动声明*/

registerbgidriver(EGAVGA_driver);

initgraph(&gdriver, &gmode, "");

for (i = 0; i < 10; i ++)

for (j = 0; j < 10; j++)/*声明坐标的间距*/

board[i][j] = 0;

cur_x = 1;

cur_y = 1; }

void destroy() /*关闭图形驱动器*/ {

closegraph(); }

void draw_board(int n) /*画表格的函数*/ {

int i, j;

for (i = 20; i <=5*160+80; i += 90)/*划横线的循环*/

{

line(i, 20, i, (n+1)*60+20);

}

for (i = 20; i <= (n+1)*60+30; i += 60)/*划纵线的循环*/

{

line(20, i, 5*110+10, i);

} }

void main() {

struct student stu[SIZE],stu_temp;/*声明结构体变量*/

FILE *fp;

/*声明文件型的指针*/

int i,j,n,m,h;

int c=1; /*c为循环次数*/

h=0;

fp=fopen("c:list.txt","wb+");/*打开写入文件*/

init(); /*调用函数*/

draw_board(SIZE);

if(fp==NULL) /*验证文件是否为空*/

{

printf("cannot open this file ");

exit(0);

}

printf("input all %d students's data. ",SIZE); /*画输入学生信息的表*/

gotoxy(17,4);

printf("stuNo");

gotoxy(29,4);

printf("name");

gotoxy(41,4);

printf("sex");

gotoxy(52,4);

printf("score");

gotoxy(63,4);

printf("address");

for(i=0;i

{

gotoxy(7,4*(i+2));

printf("%d",i);

gotoxy(17,4*(i+2));

scanf("%s",&stu[i].stuNo);

gotoxy(29,4*(i+2));

scanf("%s",&stu[i].name);

gotoxy(41,4*(i+2));

scanf("%s",&stu[i].sex);

gotoxy(52,4*(i+2));

scanf("%s",&stu[i].score);

gotoxy(63,4*(i+2));

scanf("%s",&stu[i].address);

}

for(i=0;i

if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)

{

printf("file write error!");

exit(0);

}

rewind(fp);

clrscr();

for(c=1;c<100;c++) /*创建一个图形界面*/

{

textbackground(0);

textcolor(1);

gotoxy(29,7);

printf("read->1");

gotoxy(29,9);

printf("find->2");

gotoxy(29,11);

printf("delete->3");

gotoxy(29,13);

printf("insert->4");

gotoxy(29,15);

printf("modify->5");

gotoxy(29,17);

printf("plese enter j= ");

scanf("%d",&j);

clrscr();

if(j==1) /*当输入为1时,显示整个班级

{的学生信息*/

draw_board(SIZE);

gotoxy(17,4);

printf("stuNo");

gotoxy(29,4);

printf("name");

gotoxy(41,4);

printf("sex");

gotoxy(52,4);

printf("score");

gotoxy(63,4);

printf("address");

for(i=0;i

{

fread(&stu_temp,sizeof(struct student),1,fp);出每个学生的信息*/

gotoxy(7,4*(i+2));

printf("%d",i);

gotoxy(17,4*(i+2));

printf("%s",stu[i].stuNo);

gotoxy(29,4*(i+2));

printf("%s",stu[i].name);

gotoxy(41,4*(i+2));

printf("%s",stu[i].sex);

gotoxy(52,4*(i+2));

printf("%s",stu[i].score);

gotoxy(63,4*(i+2));

printf("%s",stu[i].address);

}

fclose(fp);

/*关闭文件*/

getch(); /*留在当前界面*/

clrscr(); /*清屏*/

}

if(j==2) /*当输入为2时,查找某个学生的

{信息*/

rewind(fp);/*移动指针到最前*/

printf("look up the nth(n<4) student,plese enter n= : ");/*输入要查找的学生

scanf("%d",&i);位置*/

clrscr();

draw_board(1); /*画表格*/

gotoxy(17,4);

printf("stuNo");

gotoxy(29,4);

printf("name");

gotoxy(41,4);

printf("sex");

gotoxy(52,4);

printf("score");

gotoxy(63,4);

printf("address");

fseek(fp,(i-1)*sizeof(struct student),0); /*打开文件查找,读出信

fread(&stu_temp,sizeof(struct student),1,fp);息*/

gotoxy(7,8);

printf("%d",i);

gotoxy(17,8);

printf("%s",stu[i].stuNo);

gotoxy(29,8);

printf("%s",stu[i].name);

gotoxy(41,8);

printf("%s",stu[i].sex);

gotoxy(52,8);

printf("%s",stu[i].score);

gotoxy(63,8);

printf("%s",stu[i].address);

}

fclose(fp);

getch();

clrscr();

if(j==3) /*当输入为3,删除某个学生的信息*/

{

h=h-1; /*表格少画一格*/

printf("you want delete nth student,plese enter n= ");

scanf("%d",&n);

draw_board(SIZE+h); /*调用函数画表格*/

gotoxy(17,4);

printf("stuNo");

gotoxy(29,4);

printf("name");

gotoxy(41,4);

printf("sex");

gotoxy(52,4);

printf("score");

gotoxy(63,4);

printf("address");

for(m=n;m

{

strcpy(stu[m].stuNo,stu[m+1].stuNo);

strcpy(stu[m].name,stu[m+1].name);

strcpy(stu[m].sex,stu[m+1].sex);

strcpy(stu[m].score,stu[m+1].score);

strcpy(stu[m].address,stu[m+1].address);

}

for(i=0;i

{

fread(&stu_temp,sizeof(struct student),1,fp);个表格*/

gotoxy(7,4*(i+2));

printf("%d",i);

gotoxy(17,4*(i+2));

printf("%s",stu[i].stuNo);

gotoxy(29,4*(i+2));

printf("%s",stu[i].name);

gotoxy(41,4*(i+2));

printf("%s",stu[i].sex);

gotoxy(52,4*(i+2));

printf("%s",stu[i].score);

gotoxy(63,4*(i+2));

printf("%s",stu[i].address);

}

fclose(fp);

getch();

clrscr();

} if(j==4) /*当输入为4时,增加一个学生

{信息*/

h=h+1;

printf("you want insert nth student,plese enter n= ");

scanf("%d",&n);

for(m=n;m

{息*/

strcpy(stu[m+1].stuNo,stu[m].stuNo);

strcpy(stu[m+1].name,stu[m].name);

strcpy(stu[m+1].sex,stu[m].sex);

strcpy(stu[m+1].score,stu[m].score);

strcpy(stu[m+1].address,stu[m].address);

}

draw_board(1); /*调用函数画表格*/

gotoxy(7,4*2);

printf("%d",n);

gotoxy(17,4);

printf("stuNo");

gotoxy(29,4);

printf("name");

gotoxy(41,4);

printf("sex");

gotoxy(52,4);

printf("score");

gotoxy(63,4);

printf("address");

gotoxy(17,8); /*输入一个新学生的

scanf("%s",&stu[n].stuNo);信息*/

gotoxy(29,8);

scanf("%s",&stu[n].name);

gotoxy(41,8);

scanf("%s",&stu[n].sex);

gotoxy(52,8);

scanf("%s",&stu[n].score);

gotoxy(63,8);

scanf("%s",&stu[n].address);

gotoxy(7,8);

printf("%d",i);

gotoxy(17,8);

printf("%s",stu[n].stuNo);

gotoxy(29,8);

printf("%s",stu[n].name);

gotoxy(41,8);

printf("%s",stu[n].sex);

gotoxy(52,8);

printf("%s",stu[n].score);

gotoxy(63,8);

printf("%s",stu[n].address);

clrscr();

draw_board(SIZE+h);

gotoxy(17,4);

printf("stuNo");

gotoxy(29,4);

printf("name");

gotoxy(41,4);

printf("sex");

gotoxy(52,4);

printf("score");

gotoxy(63,4);

printf("address");

for(i=0;i

{

fread(&stu_temp,sizeof(struct student),1,fp);表格*/

gotoxy(7,4*(i+2));

printf("%d",i);

gotoxy(17,4*(i+2));

printf("%s",stu[i].stuNo);

gotoxy(29,4*(i+2));

printf("%s",stu[i].name);

gotoxy(41,4*(i+2));

printf("%s",stu[i].sex);

gotoxy(52,4*(i+2));

printf("%s",stu[i].score);

gotoxy(63,4*(i+2));

printf("%s",stu[i].address);

}

fclose(fp);

getch();

clrscr();

}

if(j==5)/*当输入为5,修改某个学生

{信息*/

printf("you want to modify nth student information,plese enter n= ");

scanf("%d",&n);

/*输入修改的学生的位置*/

draw_board(1);

draw_board(1);

gotoxy(7,4*2);

printf("%d",n);

gotoxy(17,4);

printf("stuNo");

gotoxy(29,4);

printf("name");

gotoxy(41,4);

printf("sex");

gotoxy(52,4);

printf("score");

gotoxy(63,4);

printf("address");

gotoxy(17,8);

/*输入新的学生信息*/

scanf("%s",&stu[n].stuNo);

gotoxy(29,8);

scanf("%s",&stu[n].name);

gotoxy(41,8);

scanf("%s",&stu[n].sex);

gotoxy(52,8);

scanf("%s",&stu[n].score);

gotoxy(63,8);

scanf("%s",&stu[n].address);

gotoxy(7,8);

clrscr();

draw_board(SIZE);

gotoxy(17,4);

printf("stuNo");

gotoxy(29,4);

printf("name");

gotoxy(41,4);

printf("sex");

gotoxy(52,4);

printf("score");

gotoxy(63,4);

printf("address");

for(i=0;i

{

fread(&stu_temp,sizeof(struct student),1,fp);

gotoxy(7,4*(i+2));

printf("%d",i);

gotoxy(17,4*(i+2));

printf("%s",stu[i].stuNo);

gotoxy(29,4*(i+2));

printf("%s",stu[i].name);

gotoxy(41,4*(i+2));

printf("%s",stu[i].sex);

gotoxy(52,4*(i+2));

printf("%s",stu[i].score);

gotoxy(63,4*(i+2));

printf("%s",stu[i].address);

}

fclose(fp);/*关闭文件*/

getch();/*保留在这个界面上*/

clrscr(); /*清屏*/

}

}

}

第二篇:C语言课程设计代码

#include "stdio.h" #include #include #define LEN sizeof(struct course) struct course { int cID; char name[50]; float credit; int semester; struct course *next; };

void main() { int n=0; struct course *head=NULL; void insert(struct course **head,struct course *cou); void Print(struct course **head,int *n); void Modify(struct course **head,int *n); void Require(struct course **head); void Creat(struct course **head,int *n); void Delete(struct course **head,int *n);

1 void Fun(struct course **head,int *n);

Fun(&head,&n); }

void insert(struct course **head,struct course *cou) { struct course *p0,*p1,*p2; p2=p1=*head; p0=cou; if(*head) {

while((p0->semester>p1->semester)&&(p1->next))

{

p2=p1;

p1=p1->next;

}

if(p0->semestersemester)

{

if(*head==p1)*head=p0;

else p2->next=p0;

p0->next=p1; }

else

{

if(p0->semester==p1->semester) { while((p0->cID>p1->cID)&&(p1->next)&&(p0->semester==p1->semester))

{

} if(p0->semester!=p1->semester) {

} else {

if(p0->cID<=p1->cID) {

if(*head==p1)*head=p0; else p2->next=p0;

3 p2=p1; p1=p1->next; p2->next=p0; p0->next=p1;

p0->next=p1;

}

else

{p1->next=p0;p0->next=NULL;}

}

}

else

{p1->next=p0;p0->next=NULL;}

} } else

{

*head=p0;

p0->next=NULL; } }

void Print(struct course **head,int *n) { struct course *p; p=*head; if(*head)

4 {

if(*n==1)printf(" This %d record is: ",*n);

else printf(" These %d records are: ",*n);

printf("semester cID

name

credit ");

do

{ printf("%-10d%-10d%-18s%-12.1f ",p->semester,p->cID,p->name,p->credit);

p=p->next;

}while(p!=NULL); } else printf(" List null! "); }

void Modify(struct course **head,int *n) { struct course *p,*p2; int cID; if(*head) {

Print(head,n); while(1)

5 { printf(" Please input the cID which you want to modify:");

scanf("%d",&cID); p2=p=*head; while(p->next&&(cID!=p->cID)) {

p2=p;

p=p->next; } if(cID==p->cID) {

printf("Please input the new cID(1~60):");

scanf("%d",&p->cID);

while(p->cID<0||p->cID>60)

{

printf(" Error!");

printf(" Please input the new cID(1~60):");

scanf("%d",&p->cID);

}

printf("Please input the new semester(1~8):");

scanf("%d",&p->semester); while(p->semester<0||p->semester>8)

{

printf(" Error!");

printf(" Please input the new semester(1~8):");

scanf("%d",&p->semester);

}

printf("Please input the new credit:");

scanf("%f",&p->credit);

printf("Please input the new name:");

scanf("%s",p->name);

if(p==*head)*head=p->next;

else p2->next=p->next;

insert(head,p);

break;

}

else printf("%d not been found! ",cID);

} } else {printf(" List null! ");} }

void Require(struct course **head) {

7 struct course *p; float sum=0; int sem,i=0; printf(" Please input the semester which is required:");

scanf("%d",&sem); p=*head; while(p) {

if(sem==p->semester)

{

i++; if(i==1)printf(" semester cID

name

credit "); printf("%-10d%-10d%-18s%-12.1f ",p->semester,p->cID,p->name,p->credit);

sum=sum+p->credit;

}

p=p->next; } printf("The sum of credit in this term is:%.1f ",sum); }

void Creat(struct course **head,int *n) { struct course *p1; while(1) {

p1=(struct course *)malloc(LEN);

printf("Please input the cID(1~60):");

scanf("%d",&p1->cID);

while(p1->cID<0||p1->cID>60)

{

printf(" Error!");

printf(" Please input the cID(1~60):");

scanf("%d",&p1->cID);

}

if(p1->cID==0) break;

printf("Please input the semester(1~8):");

scanf("%d",&p1->semester);

while(p1->semester<0||p1->semester>8)

{

printf(" Error!");

printf(" Please input the semester(1~8):"); scanf("%d",&p1->semester);

}

} } printf("Please input the credit:"); scanf("%f",&p1->credit); printf("Please input the name:"); scanf("%s",p1->name); insert(head,p1); *n=*n+1; printf(" You can continue until the cID is "0"! "); Print(head,n); void Delete(struct course **head,int *n) {

struct course *p1,*p2; int cID; Print(head,n); if(*head) { printf("Please input the cID of the course which you want to delete:"); scanf("%d",&cID); p1=*head;

10

while(cID!=p1->cID&&p1->next!=NULL)

{

p2=p1;

p1=p1->next;

}

if(cID==p1->cID)

{

if(p1==*head)*head=p1->next;

else p2->next=p1->next;

printf("Have delete cID:%d ",cID);

*n=*n-1;

}

else printf("%d not been found! ",cID); } }

void Fun(struct course **head,int *n) { char num;

while(1)

{

system("cls");

puts("**************** Main Menu ******************");

puts("* 1. Add Records

2. Print Records

*");

puts("* 3. Delete Records

4. Modify Records *");

puts("* 5. Require Records 6. Exit

*");

printf("Please input your choice: ");

scanf("%d",&num);

switch(num)

{

case 1:Creat(head,n);break;

case 2:Print(head,n);break;

case 3:Delete(head,n);break;

case 4:Modify(head,n);break;

case 5:Require(head);break; case 6:exit(0); break;

default: break;

}

printf(" Press "Enter" to continue!"); getchar(); getchar();

} }

13

第三篇:JAVA课程设计

JAVA程序设计课程设计报告

目 录

一、 项目背景及意义: ............................................... 2

二、 系统描述 ............................................................... 2

三、 分析与设计 ........................................................... 3 1. 分析 ....................................................................... 3 2. 功能模块划分 ....................................................... 3 3. 功能模块流程图 ................................................... 5 4. 各模块的关键代码 ............................................... 5

四、 系统测试 ............................................................... 5

五、 课程设计进度 ..................................................... 13

六、 心得体会 ............................................................. 13

七、 参考文献 ............................................................. 14

八、 附录 ..................................................................... 14

一、 项目背景及意义:

记事本千百年来都在人类的工作生活中起到重要的作用,计算机革命电子产品未出现之前,人们的记事都是基于纸质加笔两者的简单记事,也即单纯的文本记录。直到计算机的出现和更新换代,高科技电子产品大行其道,人们日益将在纸质上的记事转移到将事件记录在个人电子设备如PC上,现在基于电子移动设备如手机和平板等的记事本app开发更是迅猛,功能更加丰富多彩,能记录的不单纯是文本了,人们能将声音和图片甚至视频结合起来,将一件事“有声有色”地记录下来,保存在个人电子设备产品中。近年来产生的采用云存储技术的“云笔记”,更是能让人们随时随地将集文本、语音、图像和视频于一体的事件记录保存在所谓的“云端”,能同步到个人其他设备中,解决了个人资料和信息跨平台跨地点的管理问题。

现在我们以有限的资源以及智慧力量,用Java语言编写一个可以在装有jar模拟器的个人电子移动设备上使用的简单记事本软件,没视频记录功能和基于网络功能但却能集文本、声音和图像于一起记录的功能的记事本,我们将轻便和简洁走向极致!所以此记事本软件操作起来简单易上手,能给带来同学简单便捷的记事体验。另外,这不单纯是个人人都可以打开的记事本,使用时需要账号密码登陆,因此能较好地保障个人隐私。

二、 系统描述

Java的前身是Oak,它一开始只是被应用于消费性电子产品中。后来它的开发者们发现它还可以被用于更大范围的Internet上。1995年,Java语言的名字从Oak编程了Java。1997年J2SE1.1发布。1998年J2SE1.2发布,

2 标志Java2的诞生。十多年来,Java编程语言及平台成功地运用在网络计算及移动等各个领域。Java的体系结构由Java语言、Java class、Java API、Java虚拟机组成。它具有简单、面向对象、健壮、安全、结构中立、可移植和高效能等众多优点。Java支持多线程编程,Java运行时系统在多线程同步方面具有成熟的解决方案。Java的平台标准有Java ME,Java SE和Java EE。Java发展到今天,它的卓越成就及在业界的地位毋庸置疑。目前在众多的支持Java的开发工具中主要的7有Java Development Kit,NetBeans,Jcreator,JBuilder,JDeveloper和Eclipse等。其中Java Development Kit 简称JDK是大多开发工具的基础。以上的每种开发工具都有优缺点,对于开发者来说,重要的是要根据自己的开发规模、开发内容和软硬件环境等因素来选择一种合适的开发工具。

在本程序设计中,因为需要开发的是记事本程序,规模较小,内容较少,所以选择了适合初学者使用的eclipse开发工具。

三、 分析与设计

1. 分析

现在网络上各种文档编辑器数不胜数,有EmEditor ,UEStudio ,GridinSoft Notepad ,Notepad++,win32pad ,SkimEdit,UniRed, xint 。功能也是应有尽有,有能改变字体的,有能改变文字颜色的。但是,这些软件又存在各种各样的瑕疵或问题:有的文件体积相对于一般文字编辑来说太大;有的功能太繁杂,使初级使用者一时难以掌握。仅从日常应用方面来说,一个文本编辑器只需一些简单实用的功能就够了。本程序设计就是依照这样一种使用需要设计了一个简单的笔记本程序。 2. 功能模块划分

程序构建的记事本程序具有Windows系统记事本工具基本功能,并且能够创

3 建多个不同的用户和保存图片功能。以下是具体说明: 第一部 登陆界面

(1) 用户名和密码输入文本框,供已注册的用户输入用户名和密码。 (2) 登陆控件,在用户名和密码正确的前提下,进入软件主界面。

(3) 注册控件,点击此按钮,将进入用户创建,创建之后用户名和密码会自动保存在电脑的相应文件中。 第一部分 菜单栏

(1)菜单中有“新健”,“删除”,“显示”,“菜单”,“帮助”五个主菜单。 (2)“新建”有“新建笔记”“新建笔记本”二个子菜单:分别用于创建新的笔记和新的笔记本。

(3)“删除”中有“删除笔记”和“删除笔记本”二个子菜单,和“新建”相对应。

(4)“显示”中可以选择界面的风格,有Metal风格、Windows风格、Motif风格、Nimbus风格;还有界面排版的选择,可以选择水平显示或垂直显示。 (5)“帮助”菜单中有关于笔记本程序的说明,作者等信息。 第二部分 笔记本排列区

显示用户创建的所有笔记本。 第三部分 笔记显示排列区

此处主要显示选中笔记本中的所有笔记,并且可以在此区右击来创建、删除笔记、查看笔记,当然也可以在菜单栏中的“新建”和“删除”菜单中创建和删除笔记。

第四部分 笔记编辑区

此部分为用户设计选择操作和右键操作,可以在笔记中插入图片、更改字体颜色、和插入时间;方便用户进行一系列的编辑操作,增强本记笔记本的用户体验性能。

4 3. 功能模块流程图

4. 各模块的关键代码

1构造函数创建窗口界面 主菜单,子菜单

public MainFrame(String name) {

this.name=name;

this.setUser_path("Users/"+name);

this.setBook_Path(this.getUser_path()+"/默认笔记本");

this.setNote_Path(this.getBook_Path()+"/默认笔记"); //

一、菜单界面

menu=new Menu(this);

/**

二、 创建三个JPanel *1.l笔记正文 TextPanel

*2.笔记名目录及查找方式 DirectoryPanel *3.笔记类型目录及排序方式选择 NoteTypePane */

/*笔记正文部分*******/ TextPanel=new JPanel(); rightPanel=new RightPanel(TextPanel,this);

} /*文件名目录部分******/

DirectoryPanel=new JPanel(); midPanel =new MidPanel(DirectoryPanel,this); /*笔记类型目录部分*****/

NoteTypePanel =new JPanel(); leftPanel=new LeftPanle(NoteTypePanel,this); leftPanel.update_Left_view();

//

三、处理拆分窗格

splitM_R =new JSplitPane(1,DirectoryPanel,TextPanel); splitM_R.setOneTouchExpandable(true); splitL_M =new JSplitPane(1,NoteTypePanel,splitM_R); splitL_M.setOneTouchExpandable(true); this.add(splitL_M);

//

四、设置标题等

this.setTitle(name+" 的笔记本"); this.setLocation(200,100); this.setSize(1000,600); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); 2 添加右键菜单并为其添加监听器

public RightPanel(JPanel panel,MainFrame mainFrame)

{ this.mainFrame=mainFrame; this.panel=panel;

//创建一个 文本域存放文字 JTextArea textPane =new JTextPane(); //设置自动换行

textPane.setFont(new Font("", 1, 12)); jsp_Pane=new JScrollPane(textPane);//滚轮

//设置鼠标右击弹框效果

//cut

cutItem=new JMenuItem("Cut",new ImageIcon("image/cut.png"));

cutItem.setAccelerator(KeyStroke.getKeyStroke("ctrl x"));//设置快捷键 "ctrl x"

cutItem.addActionListener(this);

//copy

copyItem=new JMenuItem("Copy",new ImageIcon("image/copy.png"));

copyItem.setAccelerator(KeyStroke.getKeyStroke("ctrl x"));//设置

6 快捷键 "ctrl O"

copyItem.addActionListener(this);

//paste

pasteItem=new JMenuItem("Paste",new ImageIcon("image/haha.png"));

pasteItem.setAccelerator(KeyStroke.getKeyStroke("ctrl v"));//设置快捷键 "ctrl v"

pasteItem.addActionListener(this);

saveItem=new JMenuItem("Save",new ImageIcon("image/save.png"));

saveItem.setAccelerator(KeyStroke.getKeyStroke("ctrl s"));

saveItem.addActionListener(this);

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

if(e.getActionCommand()=="Cut"){//剪切

textPane.cut(); }else if(e.getActionCommand()=="Copy"){//复制

textPane.copy(); }else if(e.getActionCommand()=="Paste"){//粘贴

textPane.paste(); }else if(e.getActionCommand()=="Save"){//保存

this.book_Save(); }else if(e.getSource()==image_Button){//插入图片

String temp=Tools.open_Choose(); if(!temp.equals("not")){

textPane.insertIcon(new ImageIcon(temp)); }

}else if(e.getSource()==font_Button){//修改字体颜色

Color c=JColorChooser.showDialog(this, "Color", Color.black); textPane.setForeground(c); }else if(e.getSource()==timeButton){//插入时间

Date now = new Date(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");//可以方便地修改日期格式

String hehe = dateFormat.format( now );

textPane.replaceSelection(hehe);

}

3 设为Document类型

public static void setDocument(File file) {

try {

} JTextPane tempPane=new JTextPane(); FileOutputStream outputStream=new FileOutputStream(file); ObjectOutputStream oos=new ObjectOutputStream(outputStream); oos.writeObject(tempPane.getDocument());

oos.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block

e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block

e.printStackTrace(); } 系统测试

1、笔记本登陆

2 、用户注册

3、菜单栏 a.总菜单

b.新建菜单

8

c.删除菜单

d.显示菜单

e.“菜单”菜单

f.帮助

10 4.导入笔记、导出笔记、及插入图片选择

5.字体颜色选择

6.插入时间

7、插入图片

四、 课程设计进度

我们进行了若干阶段的部署,令课题研究可以在每个阶段有条不紊地进行。具体如下:

(一)理论学习和开题论证

1.浏览相关网站,查阅与课题研究的相关理论、研究方法; 2.运用文献研究法,深入学习java理论,对要有关课题研究的知识进行理论上的研究和探讨。 3,制订研究计划和方案 。

(二)第一阶段

1.以调查法为主开展研究。(1)对有关java的课题设计进行调查,查阅网络上java应用的设计案例,并分析和总结,寻找思路。(2)对更新频率快的java应用进行追踪,采取观察,评价、讨论的方式分析和总结。

2.制订第二阶段实验方案,为下阶段实验做准备。

(三)第二阶段

1.按计划在继续第一阶段实验的基础上,进一步加强java应用的实施和研究。采用实验法对上一阶段的总结的结论进行验证和拓展。

2.让同学体验一下我们初步完成的作品,根据他们用完之后的感受,进一步修正作品存在的问题,完善作品。

(四),总结阶段

1.收集和整理研究资料,参照相关书籍分析和研究实验情况 2.制订总结阶段计划 3.总结和提炼研究成果 4.全面总结实验工作 5.解题论证

6.成果展示(课题报告) (五) 总结阶段(2013.12) 整理材料,撰写课题报告。

五、 心得体会

此次课程设计由我们小组一起共同合作完成,花费了差不多两个月的时间。在这期间我们共同协作,互帮互助取得了很好的效率,也为我们构建友好的同学关系,学习气氛良好做出了一定的贡献。在这期间我领略到了团队协作的重要性, 13 也看到了团队合作的高效率性。还有通过这次试验我们领悟到了团队的力量是巨大的,也学习到的一些学习方法,比如追查API,如何在短时间内学习一个自己不懂的东西那就是利用好所有的搜索引擎,多去图书馆找资料。总之此次课程设计我们不仅长了学科知识,在生活上我也长了见识。

六、 参考文献

a.黄晓东 等编著 Java课程设计案例精编(第二版)[M].北京:中国水利水电出版社,2007 b.李兴华 等编著 Java开发实战经典Java开发实战经典 北京:清华大学出版社,2009 C.李尊朝 苏军 Java程序设计(第二版) 图形用户界面设计、Swing组件 中国铁道出版社,2007

七、 附录

1.程序结构

14 2.程序

(1)Tools.java package common;

import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectOutputStream;

import javax.swing.*;

public class Tools {

/**打开选择框 返回详细地址*/ public static String open_Choose() {

JFileChooser jfc1=new JFileChooser();

jfc1.setDialogTitle("请选择...");

int judge=jfc1.showOpenDialog(null);

jfc1.setVisible(true);

//得到文件的完全路径

if(judge==JFileChooser.APPROVE_OPTION)

return (jfc1.getSelectedFile().getAbsolutePath());

else

return "not"; } /**保存选择框 返回详细地址*/ public static String save_Choose() {

JFileChooser jfc1=new JFileChooser();

jfc1.setDialogTitle("请选择...");

int judge=jfc1.showSaveDialog(null);

jfc1.setVisible(true);

//得到文件的完全路径

if(judge==JFileChooser.APPROVE_OPTION)

return (jfc1.getSelectedFile().getAbsolutePath());

else

return "not";

}

/**显示对话框,需要传递 标题和显示内容*/ public static void showMessage(String text,String title)

15 {

JOptionPane.showMessageDialog(null,text,title,

JOptionPane.INFORMATION_MESSAGE | JOptionPane.OK_OPTION); } /**新建笔记时将笔记设为Document类型,方便存储图片,在本地不能打开*/ public static void setDocument(File file) {

try {

JTextPane tempPane=new JTextPane();

FileOutputStream outputStream=new FileOutputStream(file);

ObjectOutputStream oos=new ObjectOutputStream(outputStream);

oos.writeObject(tempPane.getDocument());

oos.close();

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} } /**删除文件 传一个文件地址 返回一个boolean 为了方便删除文件夹才将此方法提取出来*/ public static boolean deleteFile(String path) {

File file=new File(path);

return (file.delete()); }

/**删除文件 传一个文件地址

返回一个boolean 先删除里面的文件再删除文件夹*/ public static boolean deleteFolder(String path) {

File folder=new File(path);

File[] list=folder.listFiles();

for(int i=0;i

deleteFile(path+"/"+list[i].getName());

return (folder.delete()); } }

(2)User.java package common; /**

16 * 处理用户属性

* 为用户创建自己的专有途径

* 如果有了则不创建

*/ import java.io.*;

import javax.swing.JTextPane; import javax.swing.text.Document;

import view.MainFrame;

public class User {

public User(String name)

{

//如果第一次登录的话,为用户新建一个专属区

File file=new File("Users/"+name);

if(!file.exists())

{

try {

file.mkdir();

} catch (Exception e1) {

e1.printStackTrace();

}

//第一次登录创建默认笔记本

File book=new File("Users/"+name+"/默认笔记本");

try {

book.mkdir();

} catch (Exception e1) {

e1.printStackTrace();

}

//第一次登录创建默认笔记

File note=new File("Users/"+name+"/默认笔记本"+"/默认笔记.ser");

try {

note.createNewFile();

Tools.setDocument(note);

} catch (Exception e1) {

e1.printStackTrace();

}

}

//构造完毕

正式进入笔记本

new MainFrame(name);

}

}

(3)login_zhuce.java package login;

import java.awt.*; import java.awt.event.*; import java.io.*;

import javax.swing.*;

import common.User; import view.MainFrame;

public class login_zhuce extends JFrame implements ActionListener {

JPanel jp0; JPanel jp1,jp2,jp3,jp4,jp5; JTextField jtf; JPasswordField jpf; JLabel jl1,jl2,jl3; JButton jb1,jb2,jb3; ImageIcon bg;

public static void main(String[] args) {

// TODO Auto-generated method stub

login_zhuce lz = new login_zhuce(); }

public login_zhuce(){

try {//默认 NImbus风格

UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");

} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnsupportedLookAndFeelException e) { // TODO Auto-generated catch block e.printStackTrace(); }

jp1 = new JPanel(); jp2 = new JPanel(); jp3 = new JPanel(); jp4 = new JPanel(); jp1.setOpaque(false); jp2.setOpaque(false); jp3.setOpaque(false); jp4.setOpaque(false);

//no.1 jl1 = new JLabel("用户名"); jtf = new JTextField(10); jp1.add(jl1); jp1.add(jtf);

//no.2 jl2 = new JLabel("密

码"); jpf = new JPasswordField(10); jp2.add(jl2); jp2.add(jpf); //3 jb1 = new JButton("登陆"); jb1.addActionListener(this); jb1.setActionCommand("denglu"); jb2 = new JButton("取消"); jb2.addActionListener(this); jb2.setActionCommand("quxiao"); jb3 = new JButton("注册"); jb3.addActionListener(this); jb3.setActionCommand("zhuce");

jp3.add(jb1);

jp3.add(jb2);

jp3.add(jb3);

this.setLayout(new GridLayout(4,1));

this.add(jp4);

this.add(jp1);

this.add(jp2);

this.add(jp3);

bg = new ImageIcon("image//huashi.jpg");

jl3 = new JLabel(bg);

jl3.setBounds(0, 0, 300, 200);

this.getLayeredPane().add(jl3,new Integer(Integer.MIN_VALUE));

jp5 = (JPanel)this.getContentPane();

jp5.setOpaque(false); //设置透明

this.setTitle("笔记本登陆");

this.setSize(300,200);

// 获取屏幕分辨率,以此设置程序出现在屏幕中央

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

Dimension testSize = getSize();

this.setLocation((screenSize.widthtestSize.width) / 2, (screenSize.height - testSize.height) / 2); this.setResizable(false); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

24

public void actionPerformed(ActionEvent e){

if(e.getActionCommand().equals("queding")){

String st1 = "ff";

String st2 = ".txt";

String st3 = this.jtf1.getText();

String st4 = st1 + st3 +st2 ;

System.out.println(st4);

File f = new File(st4);

if(!f.exists()){

String password1=new String(jtf2.getPassword());

String password2=new String(jtf3.getPassword());

System.out.println(password1);

System.out.println(password2);

if (!(password1.equals(password2))){

JOptionPane.showMessageDialog(null, "两次密码输入不一样,请重新输入", "错误提示",

JOptionPane.INFORMATION_MESSAGE | JOptionPane.OK_OPTION);

this.jtf2.setText(null);

this.jtf3.setText(null);

}

else {

try {

f.createNewFile();

} catch (IOException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

FileWriter fw = null;

BufferedWriter bw = null;

try {

fw = new FileWriter(st4,true);

bw = new BufferedWriter(fw);

bw.write(st3+"");

bw.close();

} catch (Exception e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

} finally{

try {

fw.close();

} catch (IOException e1) {

25

// TODO Auto-generated catch block

e1.printStackTrace();

}

}

try {

fw = new FileWriter(st4,true);

bw = new BufferedWriter(fw);

bw.write(this.jtf2.getPassword());

bw.close();

} catch (Exception e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

} finally{

try {

fw.close();

} catch (IOException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

}

JOptionPane.showMessageDialog(null, "创建账户成功", "恭喜你",

JOptionPane.INFORMATION_MESSAGE | JOptionPane.OK_OPTION);

this.dispose();

login_zhuce lz = new login_zhuce();

}

}

else {

JOptionPane.showMessageDialog(null,"该用户名已被占用,请重新输入用户名","错误提示",

JOptionPane.INFORMATION_MESSAGE | JOptionPane.OK_OPTION);

System.out.println("该用户名已被占用,请重新输入用户名");

this.jtf1.setText(null);

} //

if (this.jpf1.getText()!=this.jpf2.getText()){ //

JOptionPane.showMessageDialog(null, "两次密码输入不一样,请重新输入", "错误提示", //

JOptionPane.INFORMATION_MESSAGE | JOptionPane.OK_OPTION); //

this.jpf1.setText(null); //

this.jpf2.setText(null); //

}

}

26

else if(e.getActionCommand().equals("quxiao")){

this.dispose();

System.exit(0);

} } }

(5)LefgPanle.java package view; /** * 将卡片布局修改 修改成仅有两片

* 第一片 所有笔记 按钮

* 第二片 所有笔记 目录

*/ import java.awt.*; import java.awt.event.*; import java.io.*;

import javax.swing.*;

public class LeftPanle extends JPanel implements ActionListener,MouseListener{

/**************笔记本类型部分声明*****************/ CardLayout cardLayout;//卡片布局的方式

JPanel firstPanel,secondPanel;//分别存储两片

//第一片声明

JPanel allBookPanel,firstTempPanel;//所有笔记

JButton allBook;//所以笔记,排序,回收站的按钮

JScrollPane allBookjsp; //第二片声明

JPanel secondTempPanel,timePaenl_o; JButton allBook_o;//所以笔记,排序,回收站的按钮

JScrollPane timePaenljsp_o;

//处理文件部分内容

File book; String [] book_name; JLabel[] member;

JPanel panel; MainFrame mainFrame; public final int TOTAL=20;

/**************笔记本类型部分声明结束*****************/

27

public LeftPanle(JPanel panel,MainFrame mainFrame) { this.mainFrame=mainFrame; this.panel=panel; //处理第一片11111111111111111111111111 //设置初始界面 显示 所以笔记,排序,回收站的按钮

//ImageIcon imageIcon=new ImageIcon("image/note.png"); allBook=new JButton("所有笔记",new ImageIcon("image/expand.png")); allBook.addActionListener(this);//点击按时间排序时显示第二片

allBookPanel=new JPanel(new GridLayout(TOTAL,1,1,4)); member=new JLabel[TOTAL]; for(int i=0;i

member[i]=new JLabel("");

member[i].addMouseListener(this); }

allBookjsp=new JScrollPane(allBookPanel);//滚动

firstPanel=new JPanel(new BorderLayout());//将第一片设置为边界布局

firstPanel.add(allBook,"North"); firstPanel.add(allBookjsp);

//处理第二片222222222222222222222 //仅有一个按钮

allBook_o=new JButton("所有笔记",new ImageIcon("image/collapse.png")); allBook_o.addActionListener(this);//点击所有笔记时 显示第一片

secondPanel=new JPanel(new BorderLayout());//将第二片设为 边界布局

secondPanel.add(allBook_o,"North");

//进行卡片布局

cardLayout=new CardLayout(); panel.setLayout(cardLayout); panel.add(firstPanel,"1"); panel.add(secondPanel,"2");

} //更新leftPanel中的笔记本,在新建或删除笔记本是需要刷新

并附带刷新右边两个

28 Panel public void update_Left_view() {

book=new File(mainFrame.getUser_path());

book_name=book.list();

if(book.exists())

{

for(int i=0;i

{

member[i].setText("");

member[i].setIcon(null);

member[i].removeMouseListener(this);

}

for(int i=0;i

{

//为每个好友设置头像和名字,每一个好友用 JLabel组件 存放

ImageIcon imageIcon=new ImageIcon("image/note.png");

member[i].setText(book_name[i]);

member[i].setIcon(imageIcon);

member[i].addMouseListener(this);//为每一种笔记的排序方式注册监听

allBookPanel.add(member[i],i);//将笔记添加到所有笔记面板

}

mainFrame.setBook_Path(mainFrame.getUser_path()+"/"+book_name[0]);

mainFrame.midPanel.update_Mid_View();

} }

@Override public void mouseClicked(MouseEvent e) {

// TODO Auto-generated method stub

//将选中部分字体设为红色

JLabel jl = null;

for(int i=0;i

{

if(e.getComponent().equals(member[i]))

{

jl=(JLabel)e.getSource();

jl.setForeground(Color.red);

}

else

{

member[i].setForeground(Color.black);

29

// //

// //

}

} //保存当前笔记本的路径 如 ... mainFrame.setBook_Path(book.getAbsolutePath()+""+jl.getText()); //点击打开一个笔记本

刷新中间的目录

mainFrame.midPanel.update_Mid_View();

} @Override public void mousePressed(MouseEvent e) { // TODO Auto-generated method stub

} @Override public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub

} @Override public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub JLabel jl=(JLabel)e.getSource(); jl.setForeground(Color.red); //jl.setFont(new Font("",1,30)); //在笔记本界面操作 允许删除笔记本 不允许删除笔记

mainFrame.menu.delete_item[0].setEnabled(false);//不允许删除笔记

mainFrame.menu.delete_item[1].setEnabled(true);//允许删除笔记本 } @Override public void mouseExited(MouseEvent e) { // TODO Auto-generated method stub JLabel jl=(JLabel)e.getSource(); jl.setForeground(Color.black); //jl.setFont(new Font("",1,12)); } @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if(e.getSource()==allBook) {

//cardLayout.show(this.getContentPane(), "2");

cardLayout.next(panel); }else if(e.getSource()==allBook_o){

30

//cardLayout.show(this.getContentPane(), "1");

cardLayout.next(panel);

} }

}

(6)MainFrame.java package view; /** * 笔记本 java版

*

1、将主界面分为四块 北边的菜单 以及左中右的笔记本目录,笔记目录和笔记内容

*

2、左边目录为卡片布局,实现点了"所有笔记"弹出所有笔记的效果

*

3、中间显示笔记目录 采用网格布局 每个网格用了JMenuItem *

4、右边是一个JTextArea可能会改成JTextPane *

5、实现了新建删除笔记(本),但界面刷新有点问题 (会重叠)

*

6、采用MVC的思想实现时事刷新界面的效果

*

7、鼠标右击删除新建 测试成功(鼠标右击是笔记本的新建与删除没有)

*

8、注册登录系统 已测试成功 在包login里面

*

9、图片的问题已成功解决

*

10、可以更改字体颜色(大小没有写),以及插入时间等

*

11、显示处添加实现多种版本的切换(如可切换成windows)

*/

import java.awt.*; import java.awt.event.*; import javax.swing.*;

import common.User;

public class MainFrame extends JFrame implements ActionListener{

Menu menu;//连接菜单栏

JPanel NoteTypePanel,DirectoryPanel,TextPanel;//三个大Panel JSplitPane splitM_R,splitL_M;

LeftPanle leftPanel;//左边第一个Panel MidPanel midPanel;//连接中间Panel RightPanel rightPanel;//连接右边Panel

//存放路径

31 public String name=null; public String user_path=null; public String book_Path=null; public String note_Path=null;

public MainFrame(String name) {

this.name=name;

this.setUser_path("Users/"+name);

this.setBook_Path(this.getUser_path()+"/默认笔记本");

this.setNote_Path(this.getBook_Path()+"/默认笔记");

//

一、菜单界面

menu=new Menu(this);

/**

二、 创建三个JPanel

*1.l笔记正文 TextPanel

*2.笔记名目录及查找方式

DirectoryPanel

*3.笔记类型目录及排序方式选择

NoteTypePane

*/

/*笔记正文部分*******/

TextPanel=new JPanel();

rightPanel=new RightPanel(TextPanel,this);

/*文件名目录部分******/

DirectoryPanel=new JPanel();

midPanel =new MidPanel(DirectoryPanel,this);

/*笔记类型目录部分*****/

NoteTypePanel =new JPanel();

leftPanel=new LeftPanle(NoteTypePanel,this);

leftPanel.update_Left_view();

//

三、处理拆分窗格

splitM_R =new JSplitPane(1,DirectoryPanel,TextPanel);

splitM_R.setOneTouchExpandable(true);

splitL_M =new JSplitPane(1,NoteTypePanel,splitM_R);

splitL_M.setOneTouchExpandable(true);

this.add(splitL_M);

//

四、设置标题等

this.setTitle(name+" 的笔记本");

this.setLocation(200,100);

this.setSize(1000,600);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

32

} this.setVisible(true); } //为了方便后面的垂直和水平显示 public void showStyle(int show) { this.remove(splitL_M);//先把以前的去掉重新添加

splitM_R =new JSplitPane(show,DirectoryPanel,TextPanel); splitM_R.setOneTouchExpandable(true);

splitL_M =new JSplitPane(1,NoteTypePanel,splitM_R); splitL_M.setOneTouchExpandable(true); this.add(splitL_M); this.setVisible(true); }

@Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub }

public String getUser_path() { return user_path; } public void setUser_path(String user_path) { this.user_path = user_path; } public String getBook_Path() { return book_Path; } public void setBook_Path(String book_Path) { this.book_Path = book_Path; } public String getNote_Path() { return note_Path; } public void setNote_Path(String note_Path) { this.note_Path = note_Path; }

33

(7) package view;

import java.awt.*; import java.awt.event.*; import java.io.*;

import javax.swing.*; import javax.swing.text.Document; import javax.swing.text.StyledDocument;

import common.Tools; import common.User; import login.login_zhuce;

public class Menu extends JFrame implements ActionListener{

//菜单部分声明

JMenuBar menuBar=null;//菜单主干

JMenu newNote_menu,deliteNote_menu,show_menu,menu_menu,help_menu;//菜单组件

树干

//处理新建笔记菜单 newNote_menu JMenuItem[] newNote_item={

new JMenuItem("新建笔记"),

new JMenuItem("新建笔记本")

}; //处理删除deliteNote_menu JMenuItem[] delete_item={

new JMenuItem("删除笔记"),

new JMenuItem("删除笔记本")

};

//处理显示

JMenuItem[] show_item={

new JMenuItem("Metal风格"),

new JMenuItem("Windows风格"),

new JMenuItem("Motif风格"),

new JMenuItem("Nimbus风格"),

new JMenuItem("水平显示"),

new JMenuItem("垂直显示")

};

//处理menu_menu JMenuItem[] menu_item={

new JMenuItem("丨账户"),

new JMenuItem("丨导入"),

34

new JMenuItem("丨导出"),

new JMenuItem("丨注销"),

new JMenuItem("丨退出")

};

//处理help_menu JMenuItem[] help_item={

new JMenuItem("关于作者"),

new JMenuItem("关于笔记本") };

MainFrame mainFrame;

public Menu(MainFrame mainFrame) { this.mainFrame=mainFrame; //

一、先处理菜单

menuBar=new JMenuBar(); //各菜单menu[0]menu[1]menu[2]menu[3]menu[4] newNote_menu=new JMenu("新建"); deliteNote_menu=new JMenu("删除"); deliteNote_menu.setToolTipText("选中笔记(本)时才可删除"); show_menu=new JMenu("显示"); help_menu=new JMenu("帮助"); menu_menu=new JMenu("菜单");

//将菜单项添加到各菜单

for(int i=0;i

菜单

newNote_menu.add(newNote_item[i]); for(int i=0;i

deliteNote_menu.add(delete_item[i]); for(int i=0;i

show_menu.add(show_item[i]); for(int i=0;i

help_menu.add(help_item[i]); for(int i=0;i

{

menu_menu.add(menu_item[i]);

if(i==0||i==2)//添加分隔线 将导入和导出框起来

menu_menu.addSeparator(); }

35

//添加事件监听

for(int i=0;i

newNote_item[i].addActionListener(this);

for(int i=0;i

delete_item[i].addActionListener(this);

for(int i=0;i

show_item[i].addActionListener(this);

for(int i=0;i

help_item[i].addActionListener(this);

for(int i=0;i

menu_item[i].addActionListener(this);

//将菜单 添加到主干中

menuBar.add(newNote_menu);

menuBar.add(deliteNote_menu);

menuBar.add(show_menu);

menuBar.add(menu_menu);

menuBar.add(help_menu);

mainFrame.add(menuBar,"North");

} //构造完毕

//实现风格转换

private void changeFlavor(int flavor)throws Exception

{

switch(flavor)

{

case 1:

UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");

break;

case 2:

UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

break;

case 3:

UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");

break;

case 4:

UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");

break;

36

}

SwingUtilities.updateComponentTreeUI(this.getContentPane());

SwingUtilities.updateComponentTreeUI(mainFrame);

} //实现监听后的动作

@Override public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

String str=e.getActionCommand();

if(str.equals("新建笔记")){

String note_name=null;

note_name=JOptionPane.showInputDialog(null,"请输入笔记的名字","新笔记",

JOptionPane.INFORMATION_MESSAGE |JOptionPane.OK_OPTION);

//如果用户点取消 或没有输入文件名

则不用新建

if(note_name!=null){

File file=new File(mainFrame.book_Path+"/"+note_name+".ser");

if(!file.exists())

{

try {

file.createNewFile();

//将新建的笔记格式设为Document对象

Tools.setDocument(file);

} catch (Exception e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

//刷新中间和左边的Panel

mainFrame.midPanel.update_Mid_View();

}

}

}else if(str.equals("新建笔记本")){

String book_name=null;

book_name=JOptionPane.showInputDialog(null,"请输入笔记的名字","新笔记",

JOptionPane.INFORMATION_MESSAGE | JOptionPane.OK_OPTION);

if(book_name!=null){

File file=new File(mainFrame.getUser_path()+"/"+book_name);

//System.out.println("User_path:"+mainFrame.getUser_path());

if(!file.exists())

{

try {

file.mkdir();

//将笔记本路径设为新建笔记本的路径

37 mainFrame.setBook_Path(mainFrame.getUser_path()+"/"+book_name);

mainFrame.leftPanel.update_Left_view();

} catch (Exception e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

//改变的笔记本总数

刷新左边Panel

mainFrame.leftPanel.update_Left_view();

}

}

}else if(str.equals("删除笔记")){

Tools.deleteFile(mainFrame.getNote_Path());

//删除笔记之后需要刷新右边的两个Panel

mainFrame.midPanel.update_Mid_View();

}else if(str.equals("删除笔记本")){

Tools.deleteFolder(mainFrame.book_Path);

//笔记本目录发生改变

mainFrame.leftPanel.update_Left_view();

}else if(str.equals("关于作者")){

Tools.showMessage("邓伟杰、苏俊钦、陈通、陈盛锋、林健祺、尹国瑜、温天宇、赵潮顺", "帮助");

}else if(str.equals("关于笔记本")){

Tools.showMessage("还存在许多BUG,望老师指正", "呵呵");

}else if(str.equals("丨账户")){

Tools.showMessage("姓名:"+mainFrame.name, "用户信息");

}else if(str.equals("丨导入")){//即打开一个笔记

String temp=Tools.open_Choose();

if(!temp.equals("not"))

{

FileInputStream inputStream=null;

ObjectInputStream ois=null;

try {

inputStream=new FileInputStream(Tools.open_Choose());

ois=new ObjectInputStream(inputStream);

mainFrame.rightPanel.textPane.setDocument((Document) ois.readObject());

mainFrame.rightPanel.book_Save();

} catch (Exception e1) {

// TODO Auto-generated catch block

38

e1.printStackTrace();

}finally{

try {

ois.close();

} catch (IOException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

} } }else if(str.equals("丨导出")){//即另存为一个笔记

String temp=Tools.open_Choose(); if(!temp.equals("not")) {

FileOutputStream outputStream=null;

ObjectOutputStream oos=null;

try {

outputStream=new FileOutputStream(Tools.save_Choose());

oos=new ObjectOutputStream(outputStream);

oos.writeObject(mainFrame.rightPanel.textPane.getDocument());

} catch (Exception e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}finally{

try {

oos.close();

} catch (IOException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

} } }else if(str.equals("丨注销")){ mainFrame.dispose(); new login_zhuce();//注销之后重新登录 }else if(str.equals("丨退出")){ System.exit(0); }else if(str.equals("垂直显示")){ mainFrame.showStyle(0);//重新调用一下拆分窗格 }else if(str.equals("水平显示")){ mainFrame.showStyle(1); }else {

39

try{

if(str.equals("Metal风格")){

this.changeFlavor(1);

}else if(str.equals("Windows风格")){

this.changeFlavor(2);

}else if(str.equals("Motif风格")){

this.changeFlavor(3);

}else if(str.equals("Nimbus风格")){

this.changeFlavor(4);

}

}catch(Exception e1){

e1.printStackTrace();

}

}

}

}

(8)Midpanel.java package view;

import java.awt.*;

import javax.swing.*; import javax.swing.text.Document;

import common.Tools;

import java.awt.event.*; import java.io.*;

public class MidPanel extends JPanel

implements ActionListener,MouseListener{

JPanel panel; MainFrame mainFrame; /// JScrollPane jscroll2;

JMenuItem[] items; File lists[];

JPanel jp1;

40

//鼠标右击部分

JPopupMenu right_Click;

JMenuItem delete_book,properties_book,new_book;

public final int TOTAL=20; public String filename; public String temp_path=null;//右击时记录选中笔记的途径

public MidPanel(JPanel panel, MainFrame main) {

this.panel=panel;

this.mainFrame=main;

jp1=new JPanel();

jp1.setLayout(new GridLayout(TOTAL,1,1,4));

//初始化20个MenuItem

items =new JMenuItem[TOTAL];

for(int j=0;j

items[j]=new JMenuItem("");

items[j].addMouseListener(this);

}

//处理鼠标右击问题

right_Click=new JPopupMenu();

new_book=new JMenuItem("New");//新建笔记

delete_book=new JMenuItem("Delete"); //删除笔记

properties_book=new JMenuItem("Properties");

delete_book.addActionListener(this);

properties_book.addActionListener(this);

new_book.addActionListener(this);

//right_Click.

right_Click.add(new_book);

right_Click.addSeparator();

right_Click.add(delete_book);

right_Click.add(properties_book);

JLabel label=new JLabel("All Note & Note All ");

label.setEnabled(false);

label.setBackground(Color.gray);

41

jscroll2 = new JScrollPane(jp1);//为Panel添加滚动条

panel.setLayout(new BorderLayout());

panel.add(label,"North");

panel.add(jscroll2);

} //在新建或删除是需要刷新,并附带刷新

RightPanel中的内容

public void update_Mid_View()

{

File file = new File(mainFrame.getBook_Path());

if(file.isDirectory())

{

lists = file.listFiles();

for(int j=0;j

items[j].setText("");

items[j].setArmed(false);

items[j].removeMouseListener(this);//避免某个笔记被删除之后还可以被点的情况

}

for(int i=0;i

items[i].setText(lists[i].getName());//创建20个JLanel

items[i].addActionListener(this);

items[i].addMouseListener(this);

jp1.add(items[i],i );

//在该项上右击弹出一个选择框

items[i].setComponentPopupMenu(right_Click);

}

//更新右边的Panel 里面应该没有内容

mainFrame.rightPanel.update_Right_view();

}

}

public void showfile(int y) {

String filename1 = lists[y].getAbsolutePath();

FileInputStream inputStream=null;

ObjectInputStream ois = null;

try {

inputStream=new FileInputStream(filename1);

ois=new ObjectInputStream(inputStream);

42

mainFrame.rightPanel.textPane.setDocument((Document)ois.readObject());

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}finally{

try {

ois.close();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

@Override public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

if(e.getActionCommand().equals("New")){

String note_name=JOptionPane.showInputDialog(null,"请输入笔记的名字","新笔记",

JOptionPane.INFORMATION_MESSAGE | JOptionPane.OK_OPTION);

//如果用户点了取消 则不用新建笔记

if(!note_name.equals("null")){

File file=new File(mainFrame.book_Path+"/"+note_name+".ser");

if(!file.exists())

{

try {

file.createNewFile();

//为新建的笔记写入一个空白的对象 避免打开时报指针的错误

Tools.setDocument(file);

} catch (IOException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

}

//刷新中间和左边的Panel

mainFrame.midPanel.update_Mid_View();

}

}else if(e.getActionCommand().equals("Delete")){

File file=new File(this.getTemp_path());

file.delete();

//删除笔记之后需要刷新右边的两个Panel

43

mainFrame.midPanel.update_Mid_View(); }else if(e.getActionCommand().equals("Properties")){

Tools.showMessage(this.getTemp_path(),"笔记"); }else

{

mainFrame.rightPanel.textPane.setEditable(true);

mainFrame.setNote_Path(mainFrame.getBook_Path()+"/"+e.getActionCommand());

for (int x=0;x

if (e.getActionCommand().endsWith(lists[x].getName()))

this.showfile(x);

} } }

@Override public void mouseClicked(MouseEvent arg0) { // TODO Auto-generated method stub //设置选中部分的情况

JMenuItem jmtemp=null; for(int i=0;i

if(arg0.getComponent().equals(items[i]))

{

jmtemp=(JMenuItem)arg0.getSource();

jmtemp.setArmed(true);

}else{

items[i].setArmed(false);

} }

//记录被要在右边显示出内容的笔记途径

可以在菜单中删除该笔记

mainFrame.setNote_Path(mainFrame.getBook_Path()+"/"+jmtemp.getText());

mainFrame.menu.delete_item[0].setEnabled(true);//允许删除笔记

mainFrame.menu.delete_item[1].setEnabled(false);//不允许删除笔记本 } @Override public void mouseEntered(MouseEvent arg0) { // TODO Auto-generated method stub

JMenuItem jm=(JMenuItem)arg0.getSource(); //将当前笔记的途径

存到辅助路径中

44

this.setTemp_path(mainFrame.getBook_Path()+"/"+jm.getText()); } @Override public void mouseExited(MouseEvent arg0) {

// TODO Auto-generated method stub

JMenuItem jm=(JMenuItem)arg0.getSource();

//jm.setBackground(new Color(238,238,238)); } @Override public void mousePressed(MouseEvent arg0) {

// TODO Auto-generated method stub

} @Override public void mouseReleased(MouseEvent arg0) {

// TODO Auto-generated method stub }

public String getTemp_path() {

return temp_path; } public void setTemp_path(String temp_path) {

this.temp_path = temp_path; } }

(9) RightPanel.java package view; /** * 改用JTextPane实现图片即单个文字更改字体或颜色的功能

*/ import java.awt.*; import java.awt.event.*; import java.io.*; import java.text.SimpleDateFormat; import java.util.Date;

import javax.swing.*; import javax.swing.text.Document;

import common.Tools;

45 public class RightPanel extends JPanel implements ActionListener{

JPanel panel;

MainFrame mainFrame;

//文本域

JTextPane textPane; JScrollPane jsp_Pane; //鼠标右击部分

JPopupMenu right_Click; JMenuItem cutItem,copyItem,pasteItem,saveItem; //插入图片与更改字体

JToolBar toolBar; JButton image_Button,font_Button,timeButton;

public RightPanel(JPanel panel,MainFrame mainFrame) {

this.mainFrame=mainFrame;

this.panel=panel;

//创建一个 文本域存放文字

JTextArea

textPane =new JTextPane();

//设置自动换行

textPane.setFont(new Font("", 1, 12));

jsp_Pane=new JScrollPane(textPane);//滚轮

//设置鼠标右击弹框效果

//cut

cutItem=new JMenuItem("Cut",new ImageIcon("image/cut.png"));

cutItem.setAccelerator(KeyStroke.getKeyStroke("ctrl x"));//设置快捷键 "ctrl x"

cutItem.addActionListener(this);

//copy

copyItem=new JMenuItem("Copy",new ImageIcon("image/copy.png"));

copyItem.setAccelerator(KeyStroke.getKeyStroke("ctrl x"));//设置快捷键 "ctrl O"

copyItem.addActionListener(this);

//paste

pasteItem=new JMenuItem("Paste",new ImageIcon("image/haha.png"));

pasteItem.setAccelerator(KeyStroke.getKeyStroke("ctrl v"));//设置快捷键 "ctrl v"

pasteItem.addActionListener(this);

saveItem=new JMenuItem("Save",new ImageIcon("image/save.png"));

saveItem.setAccelerator(KeyStroke.getKeyStroke("ctrl s"));

saveItem.addActionListener(this);

//将各菜单项添加到 右击菜单组中

right_Click=new JPopupMenu();

//right_Click.

right_Click.add(cutItem);

46

right_Click.add(copyItem);

right_Click.add(pasteItem);

right_Click.addSeparator();

right_Click.add(saveItem);

//为右击注册监听

textPane.setComponentPopupMenu(right_Click);

//可以懂工具条部分

toolBar=new JToolBar("工具");

image_Button=new JButton("插入图片");

image_Button.addActionListener(this);

font_Button=new JButton("更改字体颜色");

font_Button.addActionListener(this);

timeButton = new JButton("插入时间");

timeButton.setToolTipText("点击可以插入当前时间");

timeButton.addActionListener(this);

toolBar.add(image_Button);

toolBar.add(font_Button);

toolBar.add(timeButton);

//将工具条和textPane添加到panel

panel.setLayout(new BorderLayout());

panel.add(toolBar,"North"); panel.add(jsp_Pane); } //更新文本框

在新建或删除

笔记或笔记本

的时候需要刷新 public void update_Right_view() { textPane.setText(""); textPane.setEditable(false); } //保存当前笔记

public void book_Save() { FileOutputStream outputStream=null; ObjectOutputStream oos=null; try {

outputStream=new FileOutputStream(mainFrame.getNote_Path());

oos=new ObjectOutputStream(outputStream);

oos.writeObject(textPane.getDocument()); } catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

47

}finally{

try {

oos.close();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

} }

@Override public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

if(e.getActionCommand()=="Cut"){//剪切

textPane.cut();

}else if(e.getActionCommand()=="Copy"){//复制

textPane.copy();

}else if(e.getActionCommand()=="Paste"){//粘贴

textPane.paste();

}else if(e.getActionCommand()=="Save"){//保存

this.book_Save();

}else if(e.getSource()==image_Button){//插入图片

String temp=Tools.open_Choose();

if(!temp.equals("not")){

textPane.insertIcon(new ImageIcon(temp));

}

}else if(e.getSource()==font_Button){//修改字体颜色

Color c=JColorChooser.showDialog(this, "Color", Color.black);

textPane.setForeground(c);

}else if(e.getSource()==timeButton){//插入时间

Date now = new Date();

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");//可以方便地修改日期格式

String hehe = dateFormat.format( now );

textPane.replaceSelection(hehe);

} } }

48

第四篇:java书店管理系统源代码

Java 源代码

public class loaduser { public String user; public String password; boolean b1; loaduser(String s1,String s2){

user=s1;

password=s2; } void load(){

System.out.println(" 书店管理销售系统");

System.out.println("**************************************"); System.out.println("

1、登录系统"); System.out.println("

2、退出系统");

System.out.println("**************************************"); System.out.println("请选择:");

int m; Scanner s=new Scanner(System.in); m=s.nextInt();

if(m==1){

for(int i=0;i<3;i++) {

System.out.println("请输入账户名和密码");

String s3,s4;

Scanner ss=new Scanner(System.in);

s3=s.next();

s4=s.next();

if(user.equals(s3)&&password.equals(s4)) b1=true ;

else b1=false;

if(i==0&&b1==false)System.out.println("用户名或密码输入错误一次,还有两次机会!");

if(i==1&&b1==false)System.out.println("用户名或密码输入错误两次,还有一次机会!");

if(i==2&&b1==false){System.out.println("三次输入错误,退出系统!");System.exit(0);}

if(b1==true) {

System.out.println("登录成功!");

break; } } }

if(m==2)System.exit(0); }

package manger; import java.util.ArrayList; import java.util.Scanner; import manger.vip; import System.menu; public class vipmanger { static ArrayList vipgroup=new ArrayList(); public vipmanger(){

vipgroup.add(new vip("001","王芳",100));

vipgroup.add(new vip("002","李娜",60));

vipgroup.add(new vip("003","杨丽",50));

vipgroup.add(new vip("004","孙洁",150));

vipgroup.add(new vip("005","肖青",300)); } static void addd(){ System.out.println("请一次输入编号,姓名,积分");

String S1,S2;

int A;

Scanner s=new Scanner(System.in);

S1=s.next();

S2=s.next();

A=s.nextInt();

vip v1=new vip (S1,S2,A); vipgroup.add(v1); }

static void delete(){ System.out.println("请输入要求删除的会员编号:"); String s; Scanner me=new Scanner (System.in); s=me.next();

boolean b1=true;

for(int i=0;i

if(s.equals(vipgroup.get(i).ID)) {vipgroup.remove(i); b1=false; }

if(b1)System.out.println("查无此会员!"); } static void correct(){ System.out.println("请输入要修改信息的会员编号:"); String sss; Scanner s=new Scanner(System.in); sss=s.next();

boolean b1=true;

for(int i=0;i

if(sss.equals(vipgroup.get(i).ID)){

b1=false;

System.out.println("请输入新的姓名和积分:");

String ss1; Scanner s7=new Scanner(System.in); ss1=s7.next(); vipgroup.get(i).name=ss1; int b;

Scanner s8=new Scanner(System.in);

b=s8.nextInt();

vipgroup.get(i).score=b; }

if(b1==true)System.out.println("查无此会员!"); } static void select(){ System.out.println("请输入要查询的会员编号:"); String s; Scanner me=new Scanner(System.in); s=me.next();

boolean b1=true ;

for(int i=0;i

if

(s.equals(vipgroup.get(i).ID)){System.out.println(vipgroup.get(i).ID+" "+vipgroup.get(i).name+" "+vipgroup.get(i).score); b1=false ; }

if(b1==true)System.out.println("查无此会员!"); } static void show(){

for(int i=0;i

System.out.println(vipgroup.get(i).ID+" "+vipgroup.get(i).name+" "+vipgroup.get(i).score); } public static void exchange(String s1,int a,int b){

boolean b1=true;

for(int i=0;i

if(s1.equals(vipgroup.get(i).ID))

{if(vipgroup.get(i).score<(a*b))System.out.println("积分不足,不能兑换!");

else vipgroup.get(i).score-=a*b;

b1=false;

} if(b1==true)System.out.println("查无此会员,不能兑换!"); } public static void shop(String s1,int a,int b){

boolean b1=true;

for( int

i=0;i

if(b1==true)System.out.println("查无此会员,不能购买!"); } public static boolean start(){ menu m=new menu(); m.vip();

int x; Scanner me= new Scanner(System.in); x=me.nextInt();

switch(x){

case 1:show();break;

case 2:delete(); break;

case 3:addd();break;

case 4:correct();break;

case 5:select();break;

case 6:return false; }

return true; } }

public class book {

public String number;

public String name;

public int price;

public int jf; book(String s1,String s2,int a,int b){

number=s1;

name=s2;

price=a;

jf=b; }

}

package manger; import java.util.ArrayList; import java.util.Scanner; import System.menu; public class bookmanger {

static ArrayList bookgroup=new ArrayList(); public bookmanger(){ bookgroup.add(new book("001","c语言",20,20)); bookgroup.add(new book("002","大学英语",22,22)); bookgroup.add(new book("003","高等数学",28,28)); } static void show(){ for(int i=0;i

for( i=0;i

return a; } public static String name(String s1){ String a = "无此书"; for(int i=0;i

return a; } public static boolean start(){ menu m=new menu(); m.bookmanger(); int x; Scanner me= new Scanner(System.in); x=me.nextInt(); switch(x){ case 1:show();break; case 2:delete();break; case 3:addd();break; case 4:return false; } return true; } }

public class gift { public String number; public String caption ; public int costjf; gift(String s1,String s2,int a){ number=s1; caption=s2; costjf=a; } }

package manger; import java.util.ArrayList; import java.util.Scanner; import manger.vipmanger; import manger.vip; import System.menu; import manger.gift; public class giftmanger { static ArrayList giftgroup=new ArrayList(); public giftmanger(){

giftgroup.add(new gift("001","鼠标垫",100));

giftgroup.add(new gift("002","书夹子",50));

giftgroup.add(new gift("003","中性笔",30)); } static void show(){ for(int i=0;i

System.out.println("请输入要删除的礼品编号:");

String s;

Scanner ss=new Scanner(System.in);

s=ss.next();

boolean b1=true;

for(int i=0;i

if(s.equals(giftgroup.get(i).number))

{giftgroup.remove(i);

b1=false;

}

if(b1)System.out.println("查无此礼品!"); } static void addd(){

System.out.println("请输入要添加的礼品编号,名称,所需积分:");

String s1,s2;

int a;

Scanner me=new Scanner(System.in);

s1=me.next();

s2=me.next();

a=me.nextInt();

gift g1=new gift(s1,s2,a);

giftgroup.add(g1); } static void exchange(){

String s1,s2,c="无此礼品";

int a,b=0;

giftmanger.show();

Scanner me=new Scanner(System.in);

System.out.println("请输入您的会员编号:");

s1=me.next();

System.out.println("请输入您要兑换的礼品编号:");

s2=me.next();

System.out.println("请输入您要兑换的礼品数量:");

a=me.nextInt();

boolean b1=true;

for(int i=0;i

{b=giftgroup.get(i).costjf;

c=giftgroup.get(i).caption;

b1=false;

}

if(b1==true)System.out.println("查无此礼品!");

else vipmanger.exchange(s1, a, b);

System.out.println("兑换结果:");

System.out.println("礼品名称"+" "+"礼品积分"+" "+"礼品数量"+" "+"消耗积分");

System.out.println(c+" "+b+" "+a+" "+(a*b)); } public static boolean start(){

menu m=new menu();

m.gift();

int x;

Scanner me= new Scanner(System.in);

x=me.nextInt();

switch(x){

case 1:show();break;

case 2:delete();break;

case 3:addd();break;

case 4:exchange();break;

case 5:return false;

}

return true; } }

public class shoping { static void shop(){ bookmanger.show(); String s1,s2,s3;

int a,b=0; Scanner me=new Scanner(System.in); System.out.println("请输入您的会员编号:"); s1=me.next(); System.out.println("请输入书籍编号:"); s2=me.next(); System.out.println("请输入购买数量:"); a=me.nextInt(); b=bookmanger.price(s2); s3=bookmanger.name(s2); System.out.println("书名"+" "+"单价"+" "+"数量"+" "+"总价"); System.out.println(s3+" "+b+" "+a+" "+(a*b)); vipmanger.shop(s1, a, b); } public static boolean start(){ menu m=new menu();

m.shopping();

int x;

Scanner me= new Scanner(System.in);

x=me.nextInt();

switch(x){

case 1:shop();break;

case 2:return false;

}

return true; } }

public class menu {

void mainmenu(){

System.out.println("

书店管理系统");

System.out.println("****************************");

System.out.println("书店管理系统");

System.out.println("

1、会员管理");

System.out.println("

2、书籍管理");

System.out.println("

3、购物结算");

System.out.println("

4、积分兑换礼品");

System.out.println("

5、注销");

System.out.println("****************************");

}

public void vip(){

System.out.println("书店管理系统>会员管理:");

System.out.println("****************************");

System.out.println("

1、显示会员信息");

System.out.println("

2、删除会员");

System.out.println("

3、添加会员");

System.out.println("

4、修改会员信息");

System.out.println("

5、查询会员");

System.out.println("

6、返回上层菜单");

System.out.println("****************************");

}

public void bookmanger(){

System.out.println("书店管理系统>书籍管理:");

System.out.println("****************************");

System.out.println("

1、书籍信息查询");

System.out.println("

2、删除书籍");

System.out.println("

3、添加书籍");

System.out.println("

4、返回上层菜单");

System.out.println("****************************");

}

public void shopping(){

System.out.println("书店管理系统>购物结算:");

System.out.println("****************************");

System.out.println("

1、购物");

System.out.println("

2、返回上层菜单");

System.out.println("****************************");

}

public void gift(){

System.out.println("书店管理系统>礼品兑换:");

System.out.println("****************************");

System.out.println("

1、礼品信息");

System.out.println("

2、删除礼品");

System.out.println("

3、添加礼品");

System.out.println("

4、兑换礼品");

System.out.println("

5、返回上层菜单");

System.out.println("****************************");

}

public static void main(String[] args) {

loaduser u1=new loaduser("manger","416426");

u1.load(); menu m1=new menu();

vipmanger vip=new vipmanger(); bookmanger book=new bookmanger(); giftmanger gi=new giftmanger();

while (true){

m1.mainmenu();

int x;

Scanner me=new Scanner(System.in);

x=me.nextInt();

switch(x){

case 1:while( vipmanger.start());break ;

case 2:while(bookmanger.start());break;

case 3:while(shoping.start());break;

case 4:while(giftmanger.start());break;

case 5:u1.load();

}

}

} }

第五篇:学生成绩管理系统 java源代码

package com.student.enty;

//姓名学号语文数学英语public class Student {

private String name;

private int num;

private double chi;

private double mat;

private double eng;//声明成员变量 public String getName() {

return name;

}

public void setName(String name) {this.name = name;

}

public int getNum() {

return num;

}

public void setNum(int num) {this.num = num;

}

public double getChi() {

return chi;

}

public void setChi(double chi) {this.chi = chi;

}

public double getMat() {

return mat;

}

public void setMat(double mat) {this.mat = mat;

}

public double getEng() {

return eng;

}

public void setEng(double eng) {this.eng = eng;

}

}

上一篇:java项目物业管理系统下一篇:建党伟业观后感2000字