114234226徐洪飚.docx

上传人:b****6 文档编号:3241916 上传时间:2022-11-21 格式:DOCX 页数:23 大小:23.42KB
下载 相关 举报
114234226徐洪飚.docx_第1页
第1页 / 共23页
114234226徐洪飚.docx_第2页
第2页 / 共23页
114234226徐洪飚.docx_第3页
第3页 / 共23页
114234226徐洪飚.docx_第4页
第4页 / 共23页
114234226徐洪飚.docx_第5页
第5页 / 共23页
点击查看更多>>
下载资源
资源描述

114234226徐洪飚.docx

《114234226徐洪飚.docx》由会员分享,可在线阅读,更多相关《114234226徐洪飚.docx(23页珍藏版)》请在冰豆网上搜索。

114234226徐洪飚.docx

114234226徐洪飚

《JAVA程序设计语言》

课程实验报告

 

课程题目:

相册薄

专业班级:

地理信息系统112班

姓名:

徐洪飚

学号:

114234226

指导老师:

阿尔达克

 

2013/11/14

 

一、实验前言:

几十年来,计算机一直作为一个交流平台被广泛使用。

尽管email可能仍然是基于计算机进行交互的最常用媒介,但是,近年来社交网络应用(诸如Facebook、Qrkut、MySpace、人人网等)却受到巨大的热捧。

基于这样一种背景,你在本次作业中的任务是创建一个应用程序,用于了解一个简单的社交网络。

什么是社交网络?

可能你还不是很熟悉社交网络,社交网络最简单的定义就是:

了解一群人及他们彼此之间关系的一种方式。

二、实验内容:

本次作业,你将创建一个应用程序,用于了解一个简单社交网络中的信息。

说的更专业一些,在这个社交网络,你的应用程序将允许添加用户简介,删除用户简介,查询用户简介。

另外,对于每一个简介,你可以把一个人的名字和他的简介联系在一起,一个可选的图片用于显示这个人的外貌信息,一个可选的“当前状态”(通常是一个字符串,描述简介的主人当前正在从事的活动),和一组朋友列表。

三、实验目的:

利用所学习的java知识,创建应用程序并完成功能相应完整的程序设计。

四、程序源代码:

/*

*File:

FacePamphlet.java

*-----------------------

*当它被完成,这一计划将实施基本的社会网络

*管理系统。

*/

 

一:

FacePamphlet

importacm.program.*;

importacm.graphics.*;

importacm.util.*;

importjava.awt.event.*;

importjavax.swing.*;

publicclassFacePamphletextendsProgram

implementsFacePamphletConstants{

//publicclassFacePamphletextendsConsoleProgramimplementsFacePamphletConstants{

/**

*该方法具有用于初始化的责任

*团团员中的应用,并照顾其他任何

*初始化,需要执行。

*/

publicvoidinit(){

//初始化窗口

initComponent();

//监听器

addActionListeners();

}

/**

*这个类是负责检测按钮时

*点击或交互使用,所以你必须添加代码

*以应对这些行动。

*/

publicvoidactionPerformed(ActionEvente){

//姓名文本框中的内容

name=nameField.getText().trim();

booleanisInclude=userData.containsProfile(name);

//添加对象

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

if(name.equals("")){

canvas.showMessage("用户姓名不能为空!

");

}

else{

if(isInclude){

canvas.showMessage(name+"已存在!

");

}

else{

userProfile=newFacePamphletProfile(name);//创建新用户的数据文件

userData.addProfile(userProfile);//加入HashMap

canvas.displayProfile(userData.getProfile(name));//在界面上显示

canvas.showMessage("新用户["+name+"]已创建!

");

}

}

}

//删除对象

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

if(isInclude){

userProfile=userData.getProfile(name);

FacePamphletProfilefriendProfile;

if(userProfile.getFriends()!

=null){

while(userProfile.getFriends().hasNext()){

StringfriendName=userProfile.getFriends().next();//遍历当前用户的好友列表

friendProfile=userData.getProfile(friendName);

friendProfile.removeFriend(name);

userData.addProfile(friendProfile);//覆盖同名键

userProfile.removeFriend(friendName);

userData.addProfile(userProfile);

if(userProfile.getFriends()==null)break;//如果当前用户好友列表被清空,跳出循环

}

}

userData.deleteProfile(name);

canvas.displayProfile(null);

canvas.showMessage("["+name+"]已删除!

");

}

else{

canvas.showMessage("["+name+"]不存在!

");

}

}

//查找目标对象

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

//判断是否存在该用户

if(isInclude){

userProfile=userData.getProfile(name);

canvas.displayProfile(userProfile);

canvas.showMessage("显示["+name+"]用户信息");

}

else{

canvas.displayProfile(null);

canvas.showMessage("["+name+"]数据不存在!

");

}

}

//更改状态

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

changeStatus(name,isInclude);

}

//更改图片

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

changePhoto(name,isInclude);

}

//添加好友

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

addFriend(name,isInclude);

}

}

//键盘监听处理程序

publicvoidkeyTyped(KeyEvente){

booleanisInclude=userData.containsProfile(name);

if(isInclude){

if((e.getSource()==statusField)&&(e.getKeyChar()=='\n')){

changeStatus(name,true);

}

if((e.getSource()==pictureField)&&(e.getKeyChar()=='\n')){

changePhoto(name,true);

}

if((e.getSource()==friendField)&&(e.getKeyChar()=='\n')){

addFriend(name,true);

}

}

}

//窗口布局初始化

privatevoidinitComponent(){

//Youfillthisin

add(newJLabel("姓名"),NORTH);

nameField=newJTextField(TEXT_FIELD_SIZE);

add(nameField,NORTH);

addButton=newJButton("添加");

add(addButton,NORTH);

deleteButton=newJButton("删除");

add(deleteButton,NORTH);

findButton=newJButton("查询");

add(findButton,NORTH);

statusField=newJTextField(TEXT_FIELD_SIZE);

statusField.addKeyListener(this);//监听状态框

add(statusField,WEST);

statusButton=newJButton("改变状态");

add(statusButton,WEST);

add(newJLabel(EMPTY_LABEL_TEXT),WEST);

pictureField=newJTextField(TEXT_FIELD_SIZE);

pictureField.addKeyListener(this);//监听图片框

add(pictureField,WEST);

pictureButton=newJButton("改变照片");

add(pictureButton,WEST);

add(newJLabel(EMPTY_LABEL_TEXT),WEST);

friendField=newJTextField(TEXT_FIELD_SIZE);

friendField.addKeyListener(this);//监听好友框

add(friendField,WEST);

friendButton=newJButton("添加好友");

add(friendButton,WEST);

//新建画布

canvas=newFacePamphletCanvas();

add(canvas);

}

/**

*更新用户的状态

*@paramname——用户名

*@paramisContain——用户是否存在

*/

privatevoidchangeStatus(Stringname,booleanisContain){

if(isContain){

userProfile=userData.getProfile(name);

userProfile.setStatus(statusField.getText());

userData.addProfil

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

当前位置:首页 > 小学教育 > 语文

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

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