JA V A程序设计综合实训专业:________ 计算机软件______班级:_______ 06软件(一)班___ ________姓名:_______ _ 蒋俊涛______________项目名称:《计事本》开始时间:___ 2008年1月7日__完成时间:___ 2008年1月11日___指导教师:叶老师实训地点:14#2机房评分成绩:_______________________一、实训目的java程序设计是计算机软件的专业核心课程,而且java也是当前软件市场上较流行和功能很好的一种软件开发语言。
经过这个学期的学习后,能不能把学习的知识综合串联起来,java的实训项目的制作可以有效的检验这一点。
进行综合项目实训可以练习java软件开发的环境和配置,能够把java的面向对象技术、数据结构、图形界面、线程、网络知识、小应用程序等知识运用到实践中去,从而更好地理解java的各项知识,达到能够应用自如的地步。
进行实训的同时还需要查阅大量的文档,可以锻炼同学的自学能力。
二、实训内容每个同学完成一个小项目,小项目的选题可以从规定题目中,也可以自己定题目。
建议选做的题目如下:1、画图软件。
要求:能够使用菜单功能完成基本图形的绘制(画圆、直线等),能够画较复杂的图形(如房子),能够有橡皮擦、改变画笔粗细等功能。
2、记事本。
仿照windows下的记事本,要求:能够读写文件,文件内容的复制、剪切和粘贴,能够设置字体的大小和颜色。
3、计算器。
仿照windows下的计算器能够完成基本的计算任务,能够完成平方、开方、求余等一些特殊的运算。
4、万年历。
要求:能够查阅农历、阳历和星期。
5、拼图游戏。
能够完成拼图游戏,能够设置游戏的级别和时间,记录游戏用户的成绩。
6、扫雷游戏。
模仿windows下的扫雷游戏。
7、英汉词典。
要求:能够进行英汉单词的互译,进行英语单词的记忆训练以及一些简单句子的翻译。
8、设计一个俄罗斯方块的游戏。
9、设计一个简单的聊天软件。
要求:注册和登陆功能,客户端能够进行通信。
10、动态时钟的制作。
要求:仿照手表制作一个时钟。
每个同学也可以自己选择一个题目,要求不能抄袭他人作品,独立完成任务。
三、课程设计项目内容和简介(在此填入项目名称和进行项目设计的背景及简单介绍)四、系统环境(开发、运行的硬件环境和软件环境)操作系统:windows 2000;内存:256M;Cpu:Inter Celeron 1G;JDK版本:1.5;五、进度计划及执行情况六、程序清单import java.awt.*;import java.awt.event.*;import java.io.*;import java.awt.GraphicsEnvironment;import javax.swing.*;import java.util.*;import java.awt.Graphics;class MyTextPad extends Frame implements ActionListener {JTextArea text;JScrollPane jsp;PopupMenu popm;Date date=new Date();String str="";Dialog d,About;Choice c1,c2,c3;Button btn1,btn2;String Str1="宋体",Str2="普通",Str3="15";int temp=0;int Red=0,Green=0,Blue=0;Label lFind = new Label("查找字符串:");Label lReplace = new Label("替换字符串:");TextField tFind = new TextField(10);TextField tReplace = new TextField(10);Button bFind = new Button("查找");Button bReplace = new Button("替换");Button bReplaceAll=new Button("替换所有");Dialog dialog;Dialog findD;public MyTextPad(String str){super(str);text=new JTextArea();text.setFont(new Font("宋体",0,15));jsp=new JScrollPane(text);add("Center",jsp);findD=new Dialog(this);addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){dispose();}});d=new Dialog(this,"字体选择");d.setBounds(150,150,320,200);findD.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){findD.setVisible(false);}});d.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){d.setVisible(false);}});c1=new Choice();c2=new Choice();c3=new Choice();GraphicsEnvironmentge=GraphicsEnvironment.getLocalGraphicsEnvironment();String fontName[]=ge.getAvailableFontFamilyNames(); for(int i=0;i<fontName.length;i++){c1.add(fontName[i]);}c2.add("粗体");c2.add("斜体");c2.add("粗体与斜体");c2.add("普通");for(int i=8;i<100;i++){c3.add(""+i);}Panel p1=new Panel();Panel p2=new Panel();p1.add(c1);p1.add(c2);p1.add(c3);btn1=new Button("确定");btn2=new Button("取消");d.setLayout(new GridLayout(5,3));d.add(p1);p2.add(btn1);btn1.addActionListener(this);btn2.addActionListener(this);p2.add(btn2);d.add(p2);About=new Dialog(this,"关于");About.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){About.setVisible(false);}});About.setBounds(300,300,150,150);About.add(new Label("蒋俊涛的计事体1.0版本"));Menu mn=new Menu("文件");MenuItem miNewFile=new MenuItem("新建",new MenuShortcut(KeyEvent.VK_N));MenuItem miOpenFile=new MenuItem("打开",new MenuShortcut(KeyEvent.VK_O));MenuItem miSaveFile=new MenuItem("保存",new MenuShortcut(KeyEvent.VK_S));MenuItem miExit=new MenuItem("退出",new MenuShortcut(KeyEvent.VK_E));mn.add(miNewFile);mn.add(miOpenFile);mn.add(miSaveFile);mn.addSeparator();mn.add(miExit);miNewFile.addActionListener(this);miOpenFile.addActionListener(this);miSaveFile.addActionListener(this);miExit.addActionListener(this);Menu mn1=new Menu("编辑");MenuItem miSelectAll=new MenuItem("全选",new MenuShortcut(KeyEvent.VK_P));MenuItem miClear=new MenuItem("清空",new MenuShortcut(KeyEvent.VK_S));MenuItem miCopy=new MenuItem("复制",new MenuShortcut(KeyEvent.VK_C));MenuItem miPaste=new MenuItem("粘贴",new MenuShortcut(KeyEvent.VK_V));MenuItem miCut=new MenuItem("剪切",new MenuShortcut(KeyEvent.VK_T));MenuItem miFind=new MenuItem("查找",new MenuShortcut(KeyEvent.VK_D));MenuItem miReplace=new MenuItem("替换",new MenuShortcut(KeyEvent.VK_R));MenuItem miAuto=new MenuItem("自动换行");miAuto.addActionListener(this);mn1.add(miSelectAll);mn1.add(miClear);mn1.add(miCopy);mn1.add(miPaste);mn1.add(miCut);mn1.addSeparator();mn1.add(miFind);mn1.add(miReplace);mn1.add(miAuto);miSelectAll.addActionListener(this);miClear.addActionListener(this);miCopy.addActionListener(this);miPaste.addActionListener(this);miCut.addActionListener(this);miFind.addActionListener(this);miReplace.addActionListener(this);Menu mn2=new Menu("格式");MenuItem miFont=new MenuItem("字体",new MenuShortcut(KeyEvent.VK_F));MenuItem miColor=new MenuItem("颜色选择",new MenuShortcut(KeyEvent.VK_K));MenuItem miTime=new MenuItem("插入时间",new MenuShortcut(KeyEvent.VK_T));miFont.addActionListener(this);miColor.addActionListener(this);miTime.addActionListener(this);mn2.add(miFont);mn2.add(miColor);mn2.add(miTime);Menu mn3=new Menu("帮助");MenuItem miAbout=new MenuItem("关于",new MenuShortcut(KeyEvent.VK_A));miAbout.addActionListener(this);mn3.add(miAbout);FileDialog findDlg = new FileDialog(this);Panel p5=new Panel();Panel p6=new Panel();Panel p7=new Panel(); p7.setLayout(new GridLayout(1,2,30,30));p5.add(lFind); p5.add(tFind); p5.add(bFind); tFind.addActionListener(this); bFind.addActionListener(this);p6.add(lReplace); p6.add(tReplace); p7.add(bReplace);p7.add(bReplaceAll); p6.add(p7);tReplace.addActionListener(this);bReplace.addActionListener(this);bReplaceAll.addActionListener(this);findD.setLayout(new GridLayout(2,1,10,10));findD.setResizable(false);findD.add(p5);findD.add(p6);findD.setBounds(100,100,260,190);//弹出PopupMenupopm=new PopupMenu();MenuItem OpenFile=new MenuItem("打开");MenuItem SaveFile=new MenuItem("保存");MenuItem SelectAll=new MenuItem("全选");MenuItem Copy=new MenuItem("复制");MenuItem Paste=new MenuItem("粘贴");MenuItem Cut=new MenuItem("剪切");OpenFile.addActionListener(this);SaveFile.addActionListener(this);SelectAll.addActionListener(this);Copy.addActionListener(this);Paste.addActionListener(this);Cut.addActionListener(this);popm.add(OpenFile);popm.add(SaveFile);popm.add(SelectAll);popm.add(Copy);popm.add(Paste);popm.add(Cut);text.add(popm);text.addMouseListener(new MyMouseEvent(this));MenuBar Bar=new MenuBar();Bar.add(mn);Bar.add(mn1);Bar.add(mn2);Bar.add(mn3);setMenuBar(Bar);setSize(800,600);setVisible(true);}class MyMouseEvent extends MouseAdapter{MyTextPad myParentFrame;MyMouseEvent(MyTextPad myf){myParentFrame=myf;}public void mouseReleased(MouseEvent e){if(e.isPopupTrigger())myParentFrame.popm.show((Component)e.getSource(),e.getX(),e.getY()); }}public void actionPerformed(ActionEvent e){String strCmd=e.getActionCommand();if(strCmd.equals("新建")){text.setFont(new Font(Str1,Font.PLAIN,15));text.setForeground(Color.black);text.setText("");}try{if(strCmd.equals("打开")){openFile();}if(strCmd.equals("保存")){saveFile();}}catch(IOException e1){}if(strCmd.equals("退出")){System.exit(0);}if(strCmd.equals("全选")){text.selectAll();}if(strCmd.equals("清空")){text.setText("");}if(strCmd.equals("复制")){str=text.getSelectedText();}if(strCmd.equals("粘贴")){text.insert(str,text.getCaretPosition());}if(strCmd.equals("剪切")){str=text.getSelectedText();text.replaceRange("",text.getSelectionStart(),text.getSelectionEnd()) ;}if(strCmd.equals("字体")){d.setVisible(true);}if(strCmd.equals("颜色选择")){Color c=JColorChooser.showDialog(this,"颜色选择",Color.black);text.setForeground(c);Red=c.getRed();Green=c.getGreen();Blue=c.getBlue();}if(e.getSource()==tFind||e.getSource()==bFind){find();return;}if(e.getSource()==tReplace||e.getSource()==bReplace) {text.requestFocus();String s1=tReplace.getText();if(text.getSelectedText().equals(tFind.getText())){int start=text.getSelectionStart(); text.replaceRange(s1,text.getSelectionStart(), text.getSelectionEnd());text.select(start,start+s1.length()); }elsefind();return;}if(e.getSource()==bReplaceAll){text.requestFocus();String s1=tReplace.getText();str = text.getText();String strFind = tFind.getText();int start = 0;int end = str.length();int len = strFind.length();int count=0;if (start<=end-len){for (;start <= end - len; start++) { if (str.substring(start, start + len).equals(strFind)) {count++;text.replaceRange(s1,start,start + len);text.select(start,start+s1.length());}}}if(count==0)JOptionPane.showConfirmDialog(findD,"没有找到!","替换提示",JOptionPane.YES_NO_OPTION);elseJOptionPane.showConfirmDialog(findD,"共替换字符"+count+"个.","替换提示",JOptionPane.YES_NO_OPTION,RMATION_MESSAGE);return;}if(strCmd.equals("查找")){ findD.setVisible(true);}if(strCmd.equals("替换")){findD.setVisible(true);}if(strCmd.equals("插入时间")){text.setText(text.getText()+date);}if(strCmd.equals("确定")){String s1="",s2="",s3="";int s;s1=c1.getSelectedItem();Str1=s1;System.out.print(s1);s2=c2.getSelectedItem();if(s2.equals("粗体"))s=1;else if(s2.equals("斜体"))s=2;else if(s2.equals("粗体与斜体"))s=3;elses=0;Str2=s2;s3=c3.getSelectedItem();text.setFont(new Font(s1,s,Integer.parseInt(s3)));Str3=s3;d.setVisible(false);}if(strCmd.equals("取消")){d.setVisible(false);}if(strCmd.equals("关于")){About.setVisible(true);}if(strCmd.equals("自动换行")){text.setLineWrap(true);}}public void openFile() throws IOException{String str1="",str2="",string="";int n=0;Color c;FileDialog fd=new FileDialog(this,"打开对话框",FileDialog.LOAD);fd.setVisible(true);File file=new File(fd.getDirectory()+fd.getFile());str1=(fd.getFile()).substring(0,(fd.getFile()).length()-4); File fStyle=new File(fd.getDirectory()+str1+".css");FileReader fileReader=new FileReader(fStyle);BufferedReader br=new BufferedReader(fileReader,4096);while((str2=br.readLine())!=null){string+=str2;}br.close();System.out.println(string);StringTokenizer str3=new StringTokenizer(string,"/");String []str4=new String[6];while(str3.hasMoreTokens()){str4[n]=str3.nextToken();n++;}System.out.print(str4[0]);Str1=str4[0];Str2=str4[1];Str3=str4[2];Red=Integer.parseInt(str4[3]);Green=Integer.parseInt(str4[4]);Blue=Integer.parseInt(str4[5]);c=new Color(Red,Green,Blue);text.setForeground(c);if(Str2.equals("粗体")){temp=1;}if(Str2.equals("斜体")){temp=2;}if(Str2.equals("粗体与斜体")){temp=3;}if(Str2.equals("普通")){temp=0;}FileReader fr=new FileReader(file);BufferedReader bufr=new BufferedReader(fr,4096);text.setText("");String texts="",s;while((s=bufr.readLine())!=null){text.setFont(new Font(Str1,temp,Integer.parseInt(Str3))); texts+=s+"\n";}text.setText(texts);bufr.close();}public void saveFile() throws IOException{FileDialog fd=new FileDialog(this,"保存对话框",FileDialog.SAVE);fd.setVisible(true);File file=new File(fd.getDirectory()+fd.getFile()+".txt");File fileStyle=new File(fd.getDirectory()+fd.getFile()+".css");fileStyle.createNewFile();FileWriter fw =new FileWriter(file);BufferedWriter bufw=new BufferedWriter(fw);FileWriter fstyle=new FileWriter(fileStyle);BufferedWriter bufw2=new BufferedWriter(fstyle);Stringtemp="/"+Str1+"/"+Str2+"/"+Str3+"/"+Red+"/"+Green+"/"+Blue+"/";bufw2.write(temp,0,temp.length());bufw2.flush();bufw2.close();String s=text.getText();bufw.write(s,0,s.length());bufw.flush();bufw.close();}public void find(){text.requestFocus();str = text.getText();String strFind = tFind.getText();int end = str.length();int len = strFind.length();int start = text.getSelectionEnd();if (start == end)start = 0;for (;start <= end - len; start++) {if (str.substring(start, start + len).equals(strFind)) {text.select(start,start+len);return;}}JOptionPane.showConfirmDialog(findD,"没有找到!!","提示",JOptionPane.YES_NO_OPTION);text.select(start,start+len);}}public class NotePad{public static void main(String [] args){MyTextPad np=new MyTextPad("计事本");}}七、综合实训总结文章(不少于1000字)Java实训感想通过一周的实训,虽然实训的时间不长,但是总体上收获是很大的,我们的java课程学到的只是java和皮毛,一开始我还没有信心完成。