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)
江山如画的头像江山如画管理团队
6个爆笑笑话段子-内涵YY
上一篇 2019年10月4日 上午10:46
WordPress网站error establishing a database connection错误原因及解决方法
下一篇 2019年10月4日 下午8:58

99%的人还看了以下文章

  • 程序设计基础(C语言)—教学设计、教案

    教学设计——程序设计基础 教学基本信息 课程名称 程序设计基础 性质 专业基础课 学分 3 学时 48 题目 数据类型 专业年级 软件工程专业一年级 教材 书名:C程序设计(第五版) 出版社:清华大学出版社    出版日期: 2017年8月 教学背景分析 一、学习内容分析: 本节课要介绍的知识点——数据类型比较简单,但都是概念。对于这些陌生的、枯燥的纯概念性…

    2020年4月10日
    15.8K0
  • java WEB编程技术上机练习一:

    jsp运行环境的搭建(jdk+TOMCAT)、编写JSP页面,配置虚拟目录并访问、熟悉MYECLIPSE的使用,包括项目的部署及运行。

    2018年8月29日
    13.8K1
  • Java向mysql数据库插入datetime类型数据实例(精)

    在Mysql数据库中日期跟时间有两种: 1、date类型,date类型也就是我们常见的储存yyyy-MM-dd类型的日期,它不能储存时间,也就是只能储存日期, 2、dateitme就是可以储存日期同时也可以储存时间。 datetime可以保存1000-01-01到 9999-12-31的日期。 上面mysql数据库中birthday字段类型设置的是datet…

    2018年5月2日
    22.2K0
  • java两个窗体Form1和Form2之间怎么传递参数?

    开发java图形界面程序时,会遇到一个窗体向另外一个窗体传递参数的问题,好多初学者很是迷茫。中国网页设计特别编写了一个简单程序用于演示两个窗体之间如何传递参数,代码如下:Form1.java代码: import java.awt.Container; import java.awt.FlowLayout; import java.awt.event.Acti…

    2021年11月25日
    3.9K0
  • 10秒倒计时、考试结束倒计时功能实现代码-JS

    注册成功或登录后网页会有倒计时,如5秒后跳转到哪个页面的功能。 在做一些在线测试,网上考试系统时,会用到倒计时功能。 如网上考试系统里,会有时间提示离考试结束还有多长时间,临近考试结束剩10分钟,还可以弹窗提示考生。 JavaScript实现倒计时功能代码 <!DOCTYPE html> <html> <head> &lt…

    2020年11月1日
    5.1K0
  • ubuntu打开命令行终端的三种方法

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

    2022年8月16日
    7.0K0

发表回复

登录后才能评论