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%的人还看了以下文章

  • 全!最详细的mysql新手安装教程

    数据库排名:Oracle,mysql和 Microsoft SQL Server 仍占据前三名。 Mysql是什么? mysql是一个关系型数据库软件,由瑞典MySQL AB公司开发,目前属于Oracle公司。 为什么使用mysql? 1)mysql是开源的,所以你不需要支付额外的费用就能使用。 2)mysql支持大型的数据库。可以处理拥有上千万条记录的大型…

    2023年1月28日 编程开发
    5.8K0
  • python 初学者练手上机实操三

    一、题目:键盘输入三角形的三边,求三角形的周长。 1、新建一个triangle.py文件 2、编写程序。 3、调试程序。 4、排除错误。 二、题目:导入turtle包(import turtle),绘制边长为100的正方形。 要求: 1、新建一个“turtle2.py”文件 2、编写程序。 3、调试程序。 4、排除错误。 三、题目:打印诗“悯农” 要求: 1…

    2023年5月5日
    14.9K0
  • AdaGrad算法—随机梯度下降算法

    AdaGrad算法,它可以根据自变量在每个维度的梯度值的大小来调整各个维度上的学习率,从而避免统一的学习率难以适应所有维度的问题。

    2023年10月9日
    3.1K0
  • 精!如何在IDEA中导入myeclipse项目、配置并运行(实例演示)

    125建站网站长原来开发的myeclipse项目直接在IDEA打开发现会有很多问题,根据解决过程,写出此文章供大家参考! 1.首先打开IDEA工具,选择导入项目,然后在弹出的窗口中选择要打开的myeclipse文件,然后点击确定。如图所示 2.选择Eclipse,然后一直下一步 3.正常我们SDK这里都配置好了,直接选择就好,然后完成项目的导入 4.导入的完…

    2023年2月3日 编程开发
    6.5K0
  • 上机实战七:EL和JSTL的使用

    建议学时:2 一、使用EL表达式简化javaBean的开发 编写一个用户登录的JavaBean,用户信息包括用户名和密码。 编写user.jsp,使用setProperty设置用户名为125jz,密码为123。 使用EL获取用户名和密码并显示。 二、使用EL实现问卷调查 用户输入昵称、所在城市,并且以多选的方式让用户选择所使用的开发语言,然后使用EL表达式显…

    2018年12月4日
    7.6K0
  • 赞!1条语句快速将python程序打包成可执行文件

    python程序编写好后,如何将python程序打包成成可执行文件呢? 今天125建站网教大家使用pyinstaller打包命令将python程序打包,希望大家有所收获。 一、安装pyinstaller pip3 installer pyinstaller # 清华镜像安装 # pip3 install -i https://pypi.tuna.tsingh…

    2023年2月3日
    1.6K0

发表回复

登录后才能评论