项目实训报告

项目实训说明:

1、软件工程和网络工程专业项目实训时间为20##年11月——20##年1月。

2、实训内容:主要写在公司实训的主要完成的专业技术工作,可以是一个项目的相关内容,如需求、分析、实现;也可以是参加培训所学习的主要内容;或者是自己在实训期间所学的专业知识。

3、实训收获与体会:可以写实训过程中对专业知识、社会认知方面的收获与体会。

4、对实训教学的意见和建议:可以写实习与在校课内教学对比,以及如何开展实习教学的建议。

5、字数要求:正文要求5000字。

6、具体格式如下:


项 目 实 训 报 告

实训专业班级                          

学 生 姓 名                           

实 习 单 位                           

实习起讫日期 2015  年  11 月 20## 年 1 月

指 导 教 师                           

辽宁科技大学软件学院制表


一、实训单位及岗位

正文(宋体小4号)

二、实训内容

正文(宋体小4号)或者是自己在实训期间所学的专业知识

三、实训收获与体会

正文(宋体小4号)

可以写实训过程中对专业知识、社会认知方面的收获与体会。

四、对实训教学的意见和建议

正文(宋体小4号)

可以写实习与在校课内教学对比,以及如何开展实习教学的建议。


五、教师评语

 

第二篇:魔板项目实训报告

目 录

§一、绪论 ................................................. 2

§二、设计要求及其环境 ...................................... 2

§三、设计方案和功能实现原理 ................................ 2

1、设计方案 ............................................. 2

2、系统功能流程图 ........................................ 3

3、系统结构框图.......................................... 3

4、模块流程图 ........................................... 4

§四、程序的界面和代码实现 .................................. 4

1、代码实现 ............................................. 4

2、程序的界面 .......................................... 14

§五、设计小结 ............................................ 15

§六、谢辞 ................................................ 15

§七、参考文献 ............................................ 15

§一、绪论

拼图游戏很多人都玩过,对于他的游戏规则每个人都知道,也就是数字或者图片任意把顺序给打乱,然后把数字重新以从左至右的顺序按数字顺序排列,而图片则是把打乱顺序的小图片拼成一个完整的图,前提是,每次只可以移动一个小图。在这次课程设计里我就选者了拼图游戏。这个程序实现了拼图游戏中的基本功能,首先你可以选者拼数字还是拼图。拼数字的规则是数字可以按行排列好,同时可以实现游戏的难易选者;而对于拼图,首先你可以载入自己喜欢的图片,然后可以选者难易程度,在打乱顺序的图片右侧有排列正确的,可以对比进行排列。在你点击开始的时候,同时开始计时,如果在规定的时间里你没有完成游戏,就会提示失败信息,如果你在规定的时间里成功拼图,此时时间停止,同时给以成功提示信息。如果发现自己完成不了,只要重新点下开始又可以重新游戏。

§二、设计要求及其环境

1)

2)

3)

4)

5)

6) 实现程序GUI图形界面; 实现游戏开始、重来、退出功能; 设计实现游戏主要算法; 实现鼠标或键盘事件响应模块; 实现用户可选难度等级功能; 实现输赢自动判别功能。

环境为JDK1.5,同时运用了JCreator工具。

§三、设计方案和功能实现原理

1、设计方案

本程序主要分为数字拼图和图片拼图,对于数字拼图分为数字打乱、移动、成功提示;拼图片,首先要载入图片,然后选者难度,对于图片的分割、打乱顺序、实现成功提示为本程序的设计的关键。对于分割图片是用到像素点来实现的,同时对图片进行了自动缩放,这样一来就可以使得图片分割后看起来更连贯。首先把分好的图片存储到一个image数组中。对于可移动的块其实是按钮,每个按钮上都有一个icon,通过随机把image数组中的图片通过imageIcon的转化后附给一个按钮。有顺序的按钮数组首先附给一个向量,然后用随机数来确定对应向量的值,然后再附给对应数组按钮,同时向两中去除该值。也就是说在附值的时候图片顺序不变,变的而是数组按钮的顺序。

对于图片的成功提示,主要在每个按钮中加个String的属性值,而且对于正确的排序的值与正在排的各个值比较,一旦所有的按钮对应的值与正确的排序一致,则为成功。成功的顺序不是用随机而是顺序排列。

2、系统功能流程图

魔板项目实训报告

魔板项目实训报告

3、系统结构框图

循环调用

4、模块流程图

魔板项目实训报告

魔板项目实训报告

魔板项目实训报告

§四、程序的界面和代码实现

1、代码实现

(1)主程序的的actionPerformed代码,这部分程序主要是对事件进行响应,控制主要的菜单和按钮。

public void actionPerformed(ActionEvent e)

{

int w=0;

if(e.getSource()==begin)

{

if(Pnu.isSelected())

{

th.start();

puzzlePad.RandomNumber();//随机数字 }

else

if(Pimge.isSelected())

{

//PuzzlePad.str1="1.jpg";

th.start();

puzzlePad.RandomImage();//随机图片 //puzzlePad.Ytu();

th.setTime(time);

th.start();

System.out.print(puzzlePad.Td); }

}

else if(e.getSource()==low)

{

time=300;

con.remove(puzzlePad);

puzzlePad=new PuzzlePad(3,3,50,50);

con.add(puzzlePad,BorderLayout.CENTER); con.validate();

this.validate();

}

else if(e.getSource()==high)

{

time=600;

con.remove(puzzlePad);

puzzlePad=new PuzzlePad(5,5,50,50);

con.add(puzzlePad,BorderLayout.CENTER); con.validate();

this.validate();

}

else if(e.getSource()==exit)

{ System.exit(0);}

else if (e.getSource() ==Limge)

{

FileDialog my = new FileDialog(Pintu.this); my.setVisible(true);

String aa ="";

aa= my.getDirectory()+my.getFile(); System.out.println(aa);

puzzlePad.str1=aa;

}

}

(2)这部分代码是本程序的关键代码,主要是用来实现基本上全部的功能。 public class PuzzlePad extends JPanel implements ActionListener

{

int rows, colums; //行数、列数(默认为3行3列)

int width, height; //按钮的宽度和高度

SquarePoint point[][];

JButton block[][];

Vector vector;

int leftX = 50, leftY = 50;

Image image = null;

Toolkit tool = null; //工具集

int photowidth, photohigh;

Image blockImage[];

static String str1=new String();

boolean Pimage = true;

int k = 0;

static boolean Td=false;

public PuzzlePad(int r, int c, int w, int h)

{

setLayout(null);

vector = new Vector();

rows = r;

colums = c;

width = w;

height = h;

tool = Toolkit.getDefaultToolkit();

try

{

Image sourceImage = tool.getImage(str1); //加载图像

image = sourceImage.getScaledInstance(colums * width, rows Image.SCALE_DEFAULT);//缩放图像

}

catch (Exception e)

{}

block = new JButton[rows][colums];

point = new SquarePoint[rows][colums];

for (int i = 0; i < rows; i++)

{

for (int j = 0; j < colums; j++)

{

if ((i == rows - 1) && (j == colums - 1)) //最后一个空缺 {} * height,

else { block[i][j] = new JButton(); block[i][j].setSize(width, height); block[i][j].addActionListener(this); //注册监听者 //vector.add(block[i][j]); } } } for (int i = 0; i < rows; i++) { for (int j = 0; j < colums; j++) { point[i][j] = new SquarePoint(50 + j * width, 50 + i * height); if ((i == rows - 1) && (j == colums - 1)) {} else {point[i][j].setBlock(block[i][j], this);} } } } public void actionPerformed(ActionEvent e) { JButton button = (JButton)e.getSource(); int x = button.getBounds().x; int y = button.getBounds().y; int m = 0, n = 0; boolean bl = false; String temp = ""; for (int i = 0; i < rows; i++) { for (int j = 0; j < colums; j++) { if (point[i][j].getX() == x && point[i][j].getY() == y) { m = i; n = j; temp = point[i][j].getstr(); } } } int up = Math.max(0, m - 1); int down = Math.min(rows - 1, m + 1); int left = Math.max(0, n - 1);

int right = Math.min(colums - 1, n + 1); if (point[up][n].getLblock() == false) { point[up][n].setBlock(button, this); point[up][n].setstr(temp); point[m][n].setstr("$"); point[m][n].setLblock(false); } else if (point[down][n].getLblock() == false) { point[down][n].setBlock(button, this); point[down][n].setstr(temp); point[m][n].setstr("$"); point[m][n].setLblock(false); } else if (point[m][left].getLblock() == false) { point[m][left].setBlock(button, this); point[m][left].setstr(temp); point[m][n].setstr("$"); point[m][n].setLblock(false); } else if (point[m][right].getLblock() == false) { point[m][right].setBlock(button, this); point[m][right].setstr(temp); point[m][n].setstr("$"); point[m][n].setLblock(false); } int num = 0; for (int i = 0; i < rows; i++) { for (int j = 0; j < colums; j++) { if ((i == rows - 1) && (j == colums - 1)) {} else { if (point[i][j].getstr().equals("num")) {bl = true;} else { bl = false; break; }

}

num++;

}

if (bl == false)

break;

}

if (bl == true)

{

JOptionPane.showMessageDialog(null, "成功拼图!");

Td=bl;

}

}

public void RandomImage()

{

try

{

photowidth = image.getWidth(this);

photohigh = image.getHeight(this);

int w = photowidth / colums;

int h = photohigh / rows;

blockImage = new Image[rows*colums];

int k = 0;

PixelGrabber pg = null;

ImageProducer ip = null;

for (int i = 0; i < rows; i++)

{

for (int j = 0; j < colums; j++)

{

int pixels[] = new int[w*h

//创建一个 PixelGrabber 对象,以从指定图像中将像素矩形部分抓取到给定的数组中 pg = new PixelGrabber(image, j * w, i * h, w, h, pixels, 0, w); pg.grabPixels();

ip = new MemoryImageSource(w, h, pixels, 0, w);//使用一个数组为 Image 生成像素值

blockImage[k] = tool.createImage(ip);

k++;

}

}

//vector.removeAllElements();

for (int i = 0; i < k - 1; i++)

{vector.add(i);}

int num = 0;

for (int i = 0; i < rows; i++)

{

for (int j = 0; j < colums; j++) { if ((i == rows - 1) && (j == colums - 1)) { } else { int n = (int)(Math.random() * vector.size()); int m = (Integer)vector.elementAt(n); point[i][j].getBlock().setIcon(new ImageIcon(blockImage[m])); point[i][j].getBlock().setBorder(null); point[i][j].setstr("m"); num++; point[i][j].getBlock().setText(""); vector.remove(n); } } } point[rows - 1][colums - 1].setstr("$"); Pimage = true; repaint(); } catch (Exception ex) {} } public void Ytu() { try { photowidth = image.getWidth(this); photohigh = image.getHeight(this); int w = photowidth / colums; int h = photohigh / rows; blockImage = new Image[rows*colums]; PixelGrabber pg = null; ImageProducer ip = null; for (int i = 0; i < rows; i++) { for (int j = 0; j < colums; j++) { int pixels[] = new int[w*h]; pg = new PixelGrabber(image, j * w, i * h, w, h, pixels, 0, w); pg.grabPixels(); ip = new MemoryImageSource(w, h, pixels, 0, w);

blockImage[k] = tool.createImage(ip);

k++;

}

}

int num = 0;

for (int i = 0; i < rows; i++)

{

for (int j = 0; j < colums; j++)

{

block[i][j].setIcon(new ImageIcon(blockImage[num]));

block[i][j].setBorder(null);

point[i][j].setstr("num");

num++;

block[i][j].setText("");

}

}

point[rows - 1][colums - 1].setstr("$");

Pimage = true;

this.repaint();

}

catch (Exception ee)

{}

}

public void paintComponent(Graphics g)

{

super.paintComponent(g);

g.setColor(Color.black);

g.fillRect(leftX, leftY, colums * width, rows * height);

if (Pimage == true)

{

g.drawImage(image, colums * width + 80, height, colums * width, rows * height, this);

for (int i = 0; i < rows; i++)

{

g.setColor(Color.white);

g.drawLine(colums * width + 80, height + i * height,

colums * width + 80 + colums * width, height + i * height); }

for (int j = 0; j < colums; j++)

{

g.drawLine(colums * width + 80 + j * width, height,

colums * width + 80 + j * width, height + rows * height); }

g.setColor(Color.black);

g.fillRect(colums * width + 80 + (colums - 1) * width,

height + (rows - 1) * height, width, height);

}

}

}

(3)这个部分的代码主要是用来控制移动的按钮的,同时这部分代码在识别是否完成拼图的时候起到一定作用,主要是setstr的

public class SquarePoint

{ int x,y;

boolean Lblock;

JButton block=null;

Container con=null;

String str = "$";

public SquarePoint(int x,int y)

{ this.x=x;

this.y=y;

}

public boolean getLblock()

{ return Lblock; }

public void setLblock(boolean boo)

{ Lblock=boo; }

public int getX()

{ return x; }

public int getY()

{ return y; }

public void setblock(JButton block)

{ this.block = block; }

public void setBlock(JButton block,Container con)

{

this.con=con;

this.block=block;

con.add(block);

block.setLocation(x,y);

Lblock=true;

con.validate();

}

public String getstr()

{ return str;}

public void setstr(String str)

{ this.str = str;}

public JButton getBlock()

{ return block;}

}

(4)本部分主要是个线程,用sleep来控制延时,同时控制时间的限制,到达后给以时间

提示。这个本分代码会在主程序和PuzzlePad中调用。

class Th extends JLabel implements Runnable

{

private volatile Thread t;

int usedtime = 0;

int Time = 60;

Th()

{

super();

setText("0");

}

public void start()

{

t = new Thread(this, "showtime");

t.start();

}

public void run()

{

int usedtime = 0;

Thread thisThread = Thread.currentThread();

while (t == thisThread)

{

try

{

usedtime++;

setText(Integer.toString(usedtime));

t.sleep(1000);

if (usedtime > Time)

{

JOptionPane.showMessageDialog(null, "时间到了!"); this.stopShow();

}

}

catch (InterruptedException e)

{setText("无法准确显示时间");}

}

}

public int gettime()

{return usedtime;}

public void setTime(int x)

{Time = x;}

public void stopShow()

{t = null;}

public void stop()

{t.stop();} }

2、程序的界面

魔板项目实训报告

魔板项目实训报告

时间到后,就会有提示:

魔板项目实训报告

§五、设计小结

这个程序在设计的时候,由于很多人都做了这个程序,我想到做同样的题目要有自己独特之处,但真正改动的地方并不多。但我却增加了程序的关键部分:成功提示。因为这个程序的关键也在于如何分图、如何打乱顺序、如何实现成功提示。前两个都实现了,第三个就比较难实现。此外还增加了部分菜单选项、图片导入功能。在设计如何实现成功提示的时候,其实算法都基本相同,但关键是所取的数据类型不同,我在设计的时候开始选定的是按钮icon的对比,完全一致就可以返回成功信息,同时计时器停止,但是在具体实现的时候却遇到了问题,事实上没有自己想的那么简单,因为我对swing中的image和icon不了解,最终以实现以失败告终。接着我想到了其他俩中方法:数字和字符串。我自己用的是字符串,在每个按钮上添加一个字符串的属性,完全一致后就可以提示成功。

其次就是我对编程能力上又了一定的提高特别是对可视化编程有了一定的提高但是这次设计对我来说不能算是个成功。因为程序的一部分并不是我自己编的,但是学习别人的不是直接拿来用,而是对每一个函数、每一行的代码都要分析透彻,然后学习别人的编程思想和算法设计,同时还要加上自己的一些设计。

总的来说,这次课程设计真的让我学到了很多东西,同时也让我有了一定的成就感觉,尽管我这次的设计并不怎么样,不过我会在以后的时间多多加尝试做的东西,毕竟这样会对我以后有很大的帮助的。只有多学着点做点东西,才可以熟练掌握所学的知识,才能做到把自己学到的东西用到实践中去。当自己毕业的时候,也不会因为自己没有什么作品而感到茫然,别管好与坏,至少使自己的知识得到巩固,自己各方面的能力得到了锻炼与提高。 §六、谢辞

首先在这里要忠心地感谢老师对我们的教导和帮助,没有你的教育我们就不会很好地掌握这方面的知识,更不能很好达到这次设计的目的。在设计的时候老师能够认真分析我们的出错和不足的地方,然后给我们提出一些修改建议,并对自己的意见详细讲给我们听,这些对于程序的完善提供了很好的帮助,这也给我们以后的设计提供了很好的设计分析的注意之处。此外还要谢谢其他同学,在我设计的时候他们也提供了很多宝贵的意见。没有大家的帮助,我的设计也不能做的令自己满意的。

§七、参考文献

[1]丁振凡 . Java语言实用教程[M]. 北京邮电大学出版社. 2006.9

[2]丁振凡 . Java语言实用教程实验指导[M]. 北京邮电大学出版社. 2006.9

[3] John Lewis等《Java程序设计教程(第四版)中文 》电子工业出版社

[4]Bruce Eckel著.《Java编程思想(第四版)中文》

[5]宛延闿 . 实用Java语言程序设计教程习题解答与上机实践[M]. 机械工业出版社.

相关推荐