就向记事本一样的 保存、打开功能,那位大虾能指教一下,无从下手呀,或者给我提供一下 原代码正好 嘿嘿!
------解决方案--------------------
这是我刚才在网上搜索到的一个例子,我稍微改造了一下,把下面两段程序依次追加到这段程序的后面,保存为一个java文件,然后运行。
网上例子很多的。
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.text.*;
import javax.swing.event.*;
import javax.swing.undo.*;
import java.util.*;
/**
* <p> Title: 程序编辑器 </p>
* <p> Description: 增强的文本编辑程序 </p>
* <p> Copyright: Copyright (c) 2005 </p>
* <p> Company: </p>
*@author 红色彼岸
*@version 0.1
*/
class ProEFrame extends JFrame{
private JFileChooser fileChooser = new JFileChooser();
private JMenuBar menuBar;
private JMenu file, edit, format, help;
private JMenuItem newItem, openItem, saveItem, saveAsItem, pageSetItem, printItem, exitItem;
private JMenuItem undoItem, redoItem, cutItem, copyItem, pasteItem, deleteItem, findItem, findNextItem, replaceItem, goToLineItem, selectAllItem, timeItem;
private JMenuItem autoNextLineItem, fontItem;
private JMenuItem helpItem, aboutItem;
private JTextArea textArea;
private JScrollPane scrollPane;
private final int TAB_SIZE = 4;
private File fileName;
private boolean isChange = false;
private final UndoManager undo = new UndoManager();
public static void main(String[] args)
{
ProEFrame frame=new ProEFrame( "记事本 ");
frame.setSize(600,400);
frame.setVisible(true);
frame.setDefaultCloseOperation(ProEFrame.EXIT_ON_CLOSE);
}
public ProEFrame(String title) {
//设置窗体的标题栏和默认关闭操作
super(title);
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
//设置菜单栏和菜单的内容
menuBar = new JMenuBar();
file = new JMenu( "文件(F) ");
edit = new JMenu( "编辑(E) ");
format = new JMenu( "格式(O) ");
help = new JMenu( "帮助(H) ");
setQuickKey(file, 'F ');
setQuickKey(edit, 'E ');
setQuickKey(format, 'O ');
setQuickKey(help, 'H ');
newItem = new JMenuItem( "新建(N) ");
openItem = new JMenuItem( "打开(O)... ");
saveItem = new JMenuItem( "保存(S) ");
saveAsItem = new JMenuItem( "另存为... ");
pageSetItem = new JMenuItem( "页面设置(U)... ");
printItem = new JMenuItem( "打印(P)... ");
exitItem = new JMenuItem( "退出 ");
setQuickKey(newItem, 'N ');
setQuickKey(openItem, 'O ');
setQuickKey(saveItem, 'S ');
setQuickKey(pageSetItem, 'U ');
setQuickKey(printItem, 'P ');
file.add(newItem);
file.add(openItem);
file.add(saveItem);
file.add(saveAsItem);
file.addSeparator();
file.add(pageSetItem);
file.add(printItem);
file.addSeparator();
file.add(exitItem);
undoItem = new JMenuItem( "撤销(Z) ");
redoItem = new JMenuItem( "恢复(R) ");
cutItem = new JMenuItem( "剪切(X) ");
copyItem = new JMenuItem( "复制(C) ");
pasteItem = new JMenuItem( "粘贴(V) ");
deleteItem = new JMenuItem( "删除 ");
findItem = new JMenuItem( "查找(F)... ");
findNextItem = new JMenuItem( "查找下一个 ");
replaceItem = new JMenuItem( "替换... ");
goToLineItem = new JMenuItem( "转到(G)... ");
selectAllItem = new JMenuItem( "全选(A) ");
timeItem = new JMenuItem( "时间/日期 ");