Java课程设计报告-记事本源代码有流程图

Java课程设计报告

题 目:简单记事本程序的设计
年级专业:计算机科学与技术  软件工程
学 号:
学生姓名:
指导老师:


目    录

摘要… 1

前言… 2

1需求分析… 2

1.1需求分析… 2

1.2功能设计… 3

2.概要设计… 3

2.1程序设计思路… 3

2.2程序运行界面… 3

2.3模块说明图… 4

2.4程序流程图… 5

2.5程序相关说明… 6

3.程序详细设计与分析… 6

3.1.初始化组件… 6

3.2.构建菜单栏及其下拉菜单… 6

3.3.“文件”菜单的事件监听… 7

3.4.“编辑”菜单的事件监听… 8

3.5.异常处理… 9

4.测试分析… 10

5.源程序清单… 12

6.课程设计总结… 17

参考文献… 17

程序代码:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
class mynotepad extends JFrame{
    File file=null;
   	Color color=Color.red;
   	mynotepad(){
        initTextContent();
   	initMenu();
   	initAboutDialog();
   	        }
   	void initTextContent(){
   		getContentPane().add(new JScrollPane(content));
   		}
       JTextPane content=new JTextPane(); 
      JFileChooser openfile=new JFileChooser();
      JColorChooser opencolor=new JColorChooser();
      JDialog about=new JDialog(this);
      JMenuBar menu=new JMenuBar();
   	
 JMenu[] menus=new JMenu[]{
  new JMenu("文件"),
  new JMenu("编辑"),
  new JMenu("关于")
 };
 
 JMenuItem optionofmenu[][]=new JMenuItem[][]{{
  new JMenuItem("新建"),
  new JMenuItem("打开"),
  new JMenuItem("保存"),
  new JMenuItem("退出")
           },		         
   {
          
  new JMenuItem("复制"),         
  new JMenuItem("剪切"),
  new JMenuItem("粘贴"),
  new JMenuItem("颜色")
               },
               {
               new JMenuItem("关于")
               }
        };
      void initMenu(){
      	
      	  for(int i=0;i<menus.length;i++){
      	  	menu.add(menus[i]);
      	  	for(int j=0;j<optionofmenu[i].length;j++){
      	  		menus[i].add(optionofmenu[i][j]);
      	  		optionofmenu[i][j].addActionListener( action );
      	  	}
      	  }
      	  this.setJMenuBar(menu);
      } 
     ActionListener action=new ActionListener(){                   
     public void actionPerformed(ActionEvent e){
     	String name = e.getActionCommand();
  JMenuItem MI=(JMenuItem)e.getSource();
  if("新建".equals(name)){
   content.setText("");
   file=null;
  }else if("打开".equals(name)){
                    if(file !=null)openfile.setSelectedFile(file);
                    int returnVal=openfile.showOpenDialog(mynotepad.this);
                    if(returnVal==JFileChooser.APPROVE_OPTION){

                    file=openfile.getSelectedFile();
                    unfold();
                              }

      }else if("保存".equals(name)){
       if(file!=null) openfile.setSelectedFile(file);
          int returnVal=openfile.showSaveDialog(mynotepad.this);
                if(returnVal==JFileChooser.APPROVE_OPTION){
                file=openfile.getSelectedFile();
                  saving();
                                  }
           
             }else if("退出".equals(name)){
               mynotepad f=new mynotepad();
               int s=JOptionPane.showConfirmDialog(f,"退出?","退出",JOptionPane.YES_NO_OPTION);
               if(s==JOptionPane.YES_OPTION)
                System.exit(0);
             }else if("剪切".equals(name)){
               content.cut();
             }else if("复制".equals(name)){
               content.copy();
             }else if("粘贴".equals(name)){
               content.paste();
             }else if("颜色".equals(name)){
               color=JColorChooser.showDialog(mynotepad.this,"",color);
                 content.setForeground(color); 
                 
    }else if("关于".equals(name)){
              about.setSize(300,150);
              about.show();
     }    
   }  
  }; 

  void saving(){
       try{
        FileWriter Writef=new FileWriter(file);
        Writef.write(content.getText());
        Writef.close();
         }
    catch(Exception e){e.printStackTrace();}
                  }                
    void unfold(){
         try{
              FileReader Readf=new FileReader(file);
              int len=(int)file.length();
              char []buffer=new char[len];
              Readf.read(buffer,0,len);
              Readf.close();
              content.setText(new String(buffer));
              }catch(Exception e){e.printStackTrace();}
       }
    void initAboutDialog(){
      about.setLayout(new GridLayout(3,1));
      about.getContentPane().setBackground(Color.white);
      about.getContentPane().add(new JLabel("我的记事本程序"));
      about.getContentPane().add(new JLabel("制作者:liuhui"));
      about.getContentPane().add(new JLabel("2010年6月"));
      about.setModal(true);
      about.setSize(100,100);
      about.setLocation(250,170);
       }
  ;
   }   
     public class Notepad{
 public static void main(String args[]){		 
                mynotepad noted=new mynotepad();                
              noted.addWindowListener(new WindowAdapter(){
                  });
                       noted.setTitle("我的记事本程序");
                 noted.setSize(640,320);
                 noted.show();
                 noted.setLocation(150,100);
 }
  }

Java课程设计报告-记事本源代码有流程图下载

125jz网原创文章。发布者:江山如画,转载请注明出处:http://www.125jz.com/3782.html

(0)
江山如画的头像江山如画管理团队
上一篇 2019年10月4日 上午10:46
下一篇 2019年10月4日 下午8:58

99%的人还看了以下文章

  • ubuntu打开命令行终端的三种方法

    1、方法一(推荐使用) 快捷键 Alt + Ctrl + T 2、方法二  3、方法三

    2022年8月16日
    9470
  • 图的全部知识点、考点梳理-数据结构

    讲解了图的15条相关定义,图的表示方法、最小生成树、普里姆(Prim)算法、克鲁斯卡尔(Kruskal)算法、最短路径、迪杰斯特拉算法、弗洛伊德算法、拓扑排序、AOE 网(关键路径),邻接矩阵和邻接表的比较。

    2020年10月14日
    2.4K0
  • 使用Eclipse和Android Studio进行移动开发有什么不同?

    在Google I/O 2013发布会上谷歌推出了AndroidStudio开发者工具,该工具的开发环境和模式更加的丰富和便捷。 AndroidStudio的正式版发布时间是14年12月,谷歌宣布Android Studio将取代Eclipse,正式成为官方集成开发软件,并中止对后者支持。目前进行移动开发,仍有不少互联网公司是使用eclipse,eclips…

    2018年2月9日
    3.3K0
  • NumPy快速入门(一)

    NumPy(Numerical Python) 是 Python 语言的一个扩展程序库,支持大量的维度数组与矩阵运算,此外也针对数组运算提供大量的数学函数库。 NumPy作为高性能科学计算和数据分析的基础包,是其他重要数据分析工具的基础。 一、认识NumPy数组对象 import numpy as np #导入numpy数据包 data=np.arange(…

    2022年1月24日
    8040
  • java中类、接口、方法、变量命名时的大小写问题

    类或者接口 一个单词:首字母大写 举例:Student,Demo 多个单词:每个单词首字母大写 举例:HelloWorld,StudentName 方法或者变量 一个单词:首字母小写 举例:name,main 多个单词:从第二个单词开始,每个单词首字母大写 举例:studentAge,showAllNames() 常量 全部大写 一个单词:大写 举例:PI …

    2020年11月15日
    3.2K0
  • MySql数据库Timestamp、time、datetime 区别及使用详解

    对于数据库来说,有多种日期时间字段可供选择,如 timestamp 和 datetime 。 不仅新手,包括一些有经验的程序员还是比较迷茫,究竟我该用哪种类型来存储日期时间呢? 一个完整的日期格式如下:YYYY-MM-DD HH:MM:SS[.fraction],它可分为两部分:date部分和time部分,其中,date部分对应格式中的“YYYY-MM-DD…

    编程开发 2018年5月2日
    6.3K1

发表回复

登录后才能评论