WEB开发网
开发学院WEB开发Jsp 用Java编写的记事本程序(1) 阅读

用Java编写的记事本程序(1)

 2008-01-05 20:34:46 来源:WEB开发网   
核心提示:这个学期,我们学习了java编程,用Java编写的记事本程序(1),期末之时老师要我们编个记事本作为这门课程的课程设计,我写了一个,请大家指点,看还有没有更简洁高效的算法,大体上的功能都实现了,只有"撤销"的功能没有实现
这个学期,我们学习了java编程,期末之时老师要我们编个记事本作为这门课程的课程设计,我写了一个,大体上的功能都实现了,只有"撤销"的功能没有实现,请各位大虾指点一下,“撤销”的算法,不甚感激!
特将记事本的源码附下,请大家指点,看还有没有更简洁高效的算法,请不要吝啬,我的E-mail:yangyong@ccsu.cn,欢迎大家来信指点!

/*
*
*题目:记事本程序
*Author: Jeason
*
* 2004-12-20
*
**/
package jeason;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import java.util.*;
import java.text.*;

public class Jsb{

///
boolean dirty=true;
String filename="";
String strtext="";


///////////////////////////////////
////////// Menu ////////////////
///////////////////////

JFrame frame=new JFrame("我的记事本");
JPopupMenu pop=new JPopupMenu("弹出");
JTextArea text=new JTextArea();
JLabel statubar=new JLabel("状态栏");
JMenuBar Mbar=new JMenuBar();
JFileChooser jFileChooser1=new JFileChooser();

JColorChooser jColor=new JColorChooser();

JMenu jFile=new JMenu("文件");
JMenu jEdit=new JMenu("编辑");
JMenu jFormat=new JMenu("格式");
JMenu jHelp=new JMenu("帮助");

JMenuItem jnew=new JMenuItem("新建(N)");

public Jsb(){ ///无参数的构造函数

///
this.dirty=false;
/////

final BorderLayout borderLayout1=new BorderLayout();

frame.setSize(600,500);//
frame.addWindowListener(new Jsb_frame_closingAdapter(this));

JPanel panel=new JPanel();
panel.setLayout(borderLayout1);//布局
panel.add(new JScrollPane(text));//滚动条
panel.add(statubar,borderLayout1.SOUTH);


frame.getContentPane().add(panel);
//
frame.setJMenuBar(Mbar); //将主菜单添加到窗体中

/*
* jnew
**/
//jnew
jnew.addActionListener(new File_new_actionAdapter(this));
jnew.setMnemonic(´N´);//N上下划线
jnew.setAccelerator(KeyStroke.getKeyStroke(´N´,java.awt.Event.CTRL_MASK,true));
//快捷方式

/*
* jopen
**/
JMenuItem jopen=new JMenuItem("打开(O)");//jopen
jopen.addActionListener(new File_open_actionAdapter(this));
jopen.setMnemonic(´O´);
jopen.setAccelerator(KeyStroke.getKeyStroke(´O´,java.awt.Event.CTRL_MASK,true));

/*
* jsave
**/
JMenuItem jsave=new JMenuItem("保存(S)");
jsave.addActionListener(new File_save_actionAdapter(this));
jsave.setMnemonic(´S´);
jsave.setAccelerator(KeyStroke.getKeyStroke(´S´,java.awt.Event.CTRL_MASK,true));

/*
* jsave as
**/
JMenuItem jsaveas=new JMenuItem("另存为...");
jsaveas.addActionListener(new File_saveas_actionAdapter(this));
/*
* jquite
**/

JMenuItem jquite=new JMenuItem("关闭(Q)");
jquite.addActionListener(new File_quite_actionAdapter(this));
jquite.setMnemonic(´Q´);

jquite.setAccelerator(KeyStroke.getKeyStroke(´Q´,java.awt.Event.CTRL_MASK,true));

//------------------------------------
// jFile code of end
//--------------------------------------

/**
* jEdit code
*/
//jundo
JMenuItem jundo=new JMenuItem("撤销(U)");
jundo.addActionListener(new Edit_undo_actionAdapter(this));
jundo.setMnemonic(´U´);
jundo.setAccelerator(KeyStroke.getKeyStroke(´U´,java.awt.Event.CTRL_MASK,true));

/*
* jcut
**/
JMenuItem jcut=new JMenuItem("剪切(X)");
jcut.addActionListener(new Edit_cut_actionAdapter(this));
jcut.setMnemonic(´X´);
jcut.setAccelerator(KeyStroke.getKeyStroke(´X´,java.awt.Event.CTRL_MASK,true));

/*
* jcopy
**/
JMenuItem jcopy=new JMenuItem("复制(C)");
jcopy.addActionListener(new Edit_copy_actionAdapter(this));
jcopy.setMnemonic(´C´);
jcopy.setAccelerator(KeyStroke.getKeyStroke(´C´,java.awt.Event.CTRL_MASK,true));

/*
* jpaste
**/
JMenuItem jpaste=new JMenuItem("粘贴(V)");
jpaste.addActionListener(new Edit_paste_actionAdapter(this));
jpaste.setMnemonic(´V´);
jpaste.setAccelerator(KeyStroke.getKeyStroke(´V´,java.awt.Event.CTRL_MASK,true));

/*
* jdelete
**/
JMenuItem jdelete=new JMenuItem("删除(D)");
jdelete.addActionListener(new Edit_delete_actionAdapter(this));
jdelete.setMnemonic(´D´);
jdelete.setAccelerator(KeyStroke.getKeyStroke(´D´,java.awt.Event.CTRL_MASK,true));

/*
* jfind
**/
JMenuItem jfind=new JMenuItem("查找(F)");
jfind.addActionListener(new Edit_find_actionAdapter(this));
jfind.setMnemonic(´F´);
jfind.setAccelerator(KeyStroke.getKeyStroke(´F´,java.awt.Event.CTRL_MASK,true));

/*
* jreplace
**/
JMenuItem jreplace=new JMenuItem("替换(R)");
jreplace.addActionListener(new Edit_replace_actionAdapter(this));
jreplace.setMnemonic(´R´);
jreplace.setAccelerator(KeyStroke.getKeyStroke(´R´,java.awt.Event.CTRL_MASK,true));

/*
*jselectall
**/
JMenuItem jselectall=new JMenuItem("全选(A)");
jselectall.addActionListener(new Edit_selectall_actionAdapter(this));
jselectall.setMnemonic(´A´);
jselectall.setAccelerator(KeyStroke.getKeyStroke(´A´,java.awt.Event.CTRL_MASK,true));

/*
* jdate
**/
JMenuItem jdate=new JMenuItem("日期/时间(T)");
jdate.addActionListener(new Edit_timedate_actionAdapter(this));
jdate.setMnemonic(´T´);
jdate.setAccelerator(KeyStroke.getKeyStroke(´T´,java.awt.Event.CTRL_MASK,true));




//------------------------------
// jEdit code of end
//
//-----------------------------

/*
* jWord

**/
JMenuItem jword=new JMenuItem("自动换行");
jword.addActionListener(new Format_word_actionAdapter(this));

/*
* jfont
**/
JMenuItem jfont=new JMenuItem("字体..");
jfont.addActionListener(new Format_font_actionAdapter(this));

/*
* jcolor
**/
JMenuItem jcolor=new JMenuItem("颜色...");
jcolor.addActionListener(new Format_color_actionAdapter(this));



//--------------------------------------------------
// jFormat code of end
//--------------------------------------------------

/*
* jabout
**/
JMenuItem jabout=new JMenuItem("关于作者(A)");
jabout.addActionListener(new Help_about_actionAdapter(this));
jabout.setMnemonic(´A´);
jabout.setAccelerator(KeyStroke.getKeyStroke(´A´,java.awt.Event.CTRL_MASK,true));

//-------------------------------------------------
// jHelp code of end
//------------------------------------------------------

/*************************************************
*------------

Tags:Java 编写 记事本

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接