软件工程综合案例讲述

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

软件工程综合案例讲述:一、要求完成一个图片预览程序:如图
图一、主界面
图二、单击“观赏”键后弹出的图片框
二、以上软件的源代码:
程序一:
unit PicDecorator;
interface
uses
SysUtils, Windows, Messages, Classes, Graphics, Controls,
Forms, Dialogs,ComCtrls,ExtCtrls,Jpeg;
type
TPicShow = class (TObject)
public
procedure Display(Owner:TForm;ImgFile:string); virtual; abstract; end;
TPic = class (TPicShow)
public
procedure Display(Owner:TForm;ImgFile:string); override;
end;
TDecoratedPic = class (TPicShow)
private
FComponent: TPicShow;
public
constructor Creat(PicShow:TPicShow);
procedure Display(Owner:TForm;ImgFile:string); overload; override; end;
TPicWithFrame = class (TDecoratedPic)
public
procedure Display(Owner:TForm;ImgFile:string); override;
destructor destroy; override;
end;
TPicWithMusic = class (TDecoratedPic)
public
destructor destroy; override;
procedure AddMusic;
procedure Display(Owner:TForm;ImgFile:string); override;
end;
implementation
uses
mmsystem;
{
************************************* TPic ************************************* }
procedure TPic.Display(Owner:TForm;ImgFile:string);
var
Img: TImage;
begin
Img:=TImage.Create(Owner);
Img.Picture.LoadFromFile(ImgFile);
Img.AutoSize:=True;
Img.Stretch:=True;
Owner.Width:=Img.Width+32;
Owner.Height:=Img.Height+64;
Owner.Caption:=ImgFile;
Img.Left:=11;
Img.Top:=13;
Img.Parent:=Owner;
end;
{
******************************** TDecoratedPic ********************************* }
constructor TDecoratedPic.Creat(PicShow:TPicShow);
begin
self.FComponent:=PicShow;
end;
procedure TDecoratedPic.Display(Owner:TForm;ImgFile:string);
begin
if FComponent<>nil then
FComponent.Display(Owner,ImgFile);
end;
{
******************************** TPicWithFrame ********************************* }
procedure TPicWithFrame.Display(Owner:TForm;ImgFile:string);
var
FrmOut: TBevel;
FrmIn: TBevel;
inherited Display(Owner,ImgFile);
FrmIn:=TBevel.Create(Owner);
FrmIn.Parent:=Owner;
FrmIn.Width:=Owner.Width-30;
FrmIn.Height:=Owner.Height-62;
FrmIn.Left:=10;
FrmIn.Top:=12;
FrmIn.Shape:=bsBox;
FrmIn.Style:=bsLowered;
FrmOut:=TBevel.Create(Owner);
FrmOut.Parent:=Owner;
FrmOut.Width:=Owner.Width-18;
FrmOut.Height:=Owner.Height-48;
FrmOut.Left:=4;
FrmOut.Top:=6;
FrmOut.Shape:=bsBox;
FrmOut.Style:=bsRaised;
end;
destructor TPicWithFrame.destroy;
begin
if FComponent<>nil then FComponent.Free;
end;
{*************************** TPicWithMusic ******************************} destructor TPicWithMusic.destroy;
begin
sndPlaySound(nil,SND_NODEFAULT);
if FComponent<>nil then FComponent.Free;
end;
procedure TPicWithMusic.AddMusic;
begin
sndPlaySound('SONG8.wav',SND_ASYNC or SND_NODEFAULT);
end;
procedure TPicWithMusic.Display(Owner:TForm;ImgFile:string);
begin
inherited Display(Owner,ImgFile);
AddMusic;
end.
程序二:
unit frmImage;
interface
uses Windows, Classes, Graphics, Forms, Controls,
FileCtrl, StdCtrls, ExtCtrls, Buttons, Spin, ComCtrls, Dialogs , PicDecorator,Jpeg;
type
TImageForm = class(TForm)
DirectoryListBox1: TDirectoryListBox;
DriveComboBox1: TDriveComboBox;
FileEdit: TEdit;
Panel1: TPanel;
Image1: TImage;
FileListBox1: TFileListBox;
Bevel1: TBevel;
FilterComboBox1: TFilterComboBox;
btnWatch: TButton;
btnExit: TButton;
Label1:Tlabel;
rgDecoType: TRadioGroup;
Label3: TLabel;
Label4: TLabel;
procedure FileListBox1Click(Sender: TObject);
procedure FileEditKeyPress(Sender: TObject; var Key: Char);
procedure btnExitClick(Sender: TObject);
procedure btnWatchClick(Sender: TObject);
private
ImgFileName:string;
end;
var
ImageForm:TImageForm;
implementation
uses SysUtils,
mmsystem;
{$R *.DFM}
procedure TImageForm.FileListBox1Click(Sender: TObject);
var
FileExt: string[4];
begin
FileExt := AnsiUpperCase(ExtractFileExt(FileListBox1.Filename));
btnWatch.Enabled:=False;
if (FileExt = '.BMP') or
(FileExt = '.ICO') or
(FileExt = '.WMF') or
(FileExt = '.EMF') or
(FileExt = '.JPG') or
(FileExt = '.JPEG') then
begin
Image1.Picture.LoadFromFile(FileListBox1.Filename);
if (Image1.Picture.Width>800) or (Image1.Picture.Height>600) then
application.MessageBox('图片尺寸超过800*600!','操作提示',MB_OK)
else
begin
ImgFileName:=FileListBox1.Filename;
btnWatch.Enabled:=True;
end;
end;
end;
procedure TImageForm.FileEditKeyPress(Sender: TObject; var Key: Char); begin
if Key = #13 then
begin
FileListBox1.ApplyFilePath(FileEdit.Text);
Key := #0;
end;
end;
procedure TImageForm.btnExitClick(Sender: TObject);
begin
close;
end;
procedure TImageForm.btnWatchClick(Sender: TObject);
var
DecoPic:TPicShow;
CurForm:TForm;
begin
CurForm:=TForm.Create(nil);
case rgDecoType.ItemIndex of
0:DecoPic:=TPicWithFrame.Creat(TPic.Create);//装饰框
1:DecoPic:=TPicWithMusic.Creat(TPic.Create);//背景音乐
2:DecoPic:=TPicWithMusic.Creat(TPicWithFrame.Creat(TPic.Create));//音乐框end;
try
DecoPic.Display(CurForm,ImgFileName);
CurForm.ShowModal;
finally
DecoPic.Free;
CurForm.Free;
end;
end;
end.
三、程序中相关算法的流程图
示范一:procedure TImageForm.btnWatchClick(Sender: TObject);
示范二:procedure TImageForm.FileEditKeyPress(Sender: TObject; var Key: Char);
四、程序中总体类模块结构图
五、需求的描述:
为满足图片管理系统中业务的需要,要在工具菜单中加入图片预览功能,该模块具有以下功能:
选择预览的图片:
对于选中的图片,首先要有一个小的图片预览框,以便确认是否是所选图片;
如果是,单击“观赏”键,确认选中该图片进行观赏。

●操作流程:
●外观要求:
六、几个简单问题:
●如何根据描述确定类对象?类属性?类方法?类结构?
●如何利用数据流图、状态迁移图、实体关系图进行分析工作?
●拟采用动态、静态描述中的哪些技术进行分析与描述?
●项目的结束标志是什么?
●采用我们已经学过的哪一种模型来与顾客进行沟通,顾客确认
我们的方案后,应该履行何种手续,操作过程如何?。

相关文档
最新文档