本文目录一览:
如何用JAVA编写简单的记事本程序?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import java.awt.datatransfer.*;public class NewEdit
{
public static void main(String args[])
{
MyFrame EditFrame=new MyFrame();
EditFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
EditFrame.setVisible(true);
}
}class MyFrame extends JFrame
{
public MyFrame()
{ Dimension screenSize=toolKit.getScreenSize();
int screenHeight=screenSize.height;
int screenWidth=screenSize.width;
setSize(screenWidth/2,screenHeight/2);
setLocation(screenWidth/4,screenHeight/4);
Image img=toolKit.getImage("icon.gif");
setIconImage(img);
setTitle("MyEdit");
JMenuBar menuBar=new JMenuBar();
setJMenuBar(menuBar);
JMenu fileMenu=new JMenu("文件");
JMenu editMenu=new JMenu("编辑");
JMenu helpMenu=new JMenu("帮助");
menuBar.add(fileMenu);
menuBar.add(editMenu);
menuBar.add(helpMenu);
JMenuItem newItem=new JMenuItem("新建");
newItem.addActionListener(new NewListener());
JMenuItem openItem=new JMenuItem("打开");
openItem.addActionListener(new OpenListener());
JMenuItem saveItem=new JMenuItem("保存");
saveItem.addActionListener(new SaveListener());
JMenuItem escItem=new JMenuItem("退出");
escItem.addActionListener(new
ActionListener()
{
public void actionPerformed(ActionEvent myE)
{
System.exit(0);
}
});
fileMenu.add(newItem);
fileMenu.add(openItem);
fileMenu.add(saveItem);
fileMenu.add(escItem);
JMenuItem allItem=new JMenuItem("全选");
//JMenuItem copyItem=new JMenuItem("复制");
//CopyAction copyAction=new CopyAction();
//copyItem.addActionListener(copyAction);
JMenuItem cutItem=new JMenuItem("剪切");
//JMenuItem pasteItem=new JMenuItem("粘贴");
//Action pasteAction=new PasteAction();
//pasteItem.addActionListener(pasteAction);
editMenu.add(allItem);
allItem.addActionListener(new
ActionListener()
{
public void actionPerformed(ActionEvent myE)
{
textArea.selectAll();
}
});
CopyAction copyAction=new CopyAction("剪切");
editMenu.add(copyAction);
CutAction cutAction=new CutAction("复制");
editMenu.add(cutAction);
Action pasteAction=new PasteAction("粘贴");
editMenu.add(pasteAction);
popup=new JPopupMenu();
popup.add(copyAction);
popup.add(pasteAction);
popup.add(cutAction);
textArea = new JTextArea();
textArea.add(popup);
textArea.addMouseListener(new
MouseListener(){
public void mouseClicked(MouseEvent e) {} public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public void mousePressed(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON3)
{
popup.show(textArea, e.getX(), e.getY());
}
} public void mouseReleased(MouseEvent e) {} });//可尝试用MouseAdapter,代码可能更简单
JScrollPane scroller = new JScrollPane(textArea);
add(scroller);
//OR--this.getContentPane().add(scroller)
//scroller.setComponentPopupMenu(popup);
//textArea.setInheritsPopupMenu(true);
//scroller.addMouseListener(new MouseAdapter(){});
}
public void writeFile(String fileName)
{
try
{
File file = new File(fileName);
FileWriter write = new FileWriter(file);
write.write(textArea.getText());
write.close();
}
catch(Exception e){
System.out.println("Error closing file!");
}
}
public void openFile(String fileName)
{
try
{
File file = new File(fileName);
FileReader readIn = new FileReader(file);
int size = (int)file.length();
int charsRead = 0;
char[] content = new char[size];
while(readIn.ready())
charsRead += readIn.read(content,charsRead,size-charsRead);
readIn.close();
textArea.setText(new String(content,0,charsRead));
}
catch(IOException e)
{
System.out.println("Error opening file!");
}
}
private class NewListener implements ActionListener
{
public void actionPerformed(ActionEvent myE)
{
textArea.setText("");
}
}
private class OpenListener implements ActionListener
{
public void actionPerformed(ActionEvent myE)
{
openFileDialog.setVisible(true);
fileName = openFileDialog.getDirectory()+openFileDialog.getFile();
if(fileName != null)
{
openFile(fileName);
}
}
}
private class SaveListener implements ActionListener
{
public void actionPerformed(ActionEvent myE)
{
saveFileDialog.setVisible(true);
fileName = saveFileDialog.getDirectory()+saveFileDialog.getFile();
if(fileName !=null)
{
writeFile(fileName);
}
}
}
private class CutAction extends AbstractAction
{
public CutAction(String name)
{
super(name);
}
public void actionPerformed(ActionEvent event)
{
String text = textArea.getSelectedText();
StringSelection selection = new StringSelection(text);
clipboard.setContents(selection,null);
textArea.replaceRange("",textArea.getSelectionStart(),
textArea.getSelectionEnd());
}
}
private class CopyAction extends AbstractAction
{
public CopyAction(String name)
{
super(name);
}
public void actionPerformed(ActionEvent event)
{
String text = textArea.getSelectedText();
StringSelection selection= new StringSelection(text);
clipboard.setContents(selection,null);
}
}
private class PasteAction extends AbstractAction
{
public PasteAction(String name)
{
super(name);
}
public void actionPerformed(ActionEvent event)
{
Transferable contents = clipboard.getContents(this);
if(contents==null)
return;
String text;
text="";
try
{
text = (String)contents.getTransferData(DataFlavor.stringFlavor);
}
catch(Exception ex){}
textArea.replaceRange(text,
textArea.getSelectionStart(),textArea.getSelectionEnd());
}
}
private JTextArea textArea;
private JPopupMenu popup;
private String fileName="";
private FileDialog openFileDialog=new FileDialog(this,"OpenFile",FileDialog.LOAD); private FileDialog saveFileDialog=new FileDialog(this,"SaveFile",FileDialog.SAVE);
Toolkit toolKit = Toolkit.getDefaultToolkit();
private Clipboard clipboard = toolKit.getSystemClipboard();}
用JAVA编写一个记事本?
public class MyText2 extends JFrame {
private JMenuBar mb;
private JMenu 文件, 编辑, 格式, 查看, 帮助;
private JTextArea editorArea;
public MyText2() {
super();
mb = new JMenuBar();
文件 = new JMenu("文件");
编辑 = new JMenu("编辑");
格式 = new JMenu("格式");
帮助 = new JMenu("帮助");
查看 = new JMenu("查看");
mb.add(文件);
mb.add(编辑);
mb.add(格式);
mb.add(查看);
mb.add(帮助);
setJMenuBar(mb);
Container container = getContentPane();
editorArea = new JTextArea();
editorArea.setLineWrap(true);
JScrollPane scrollPane = new JScrollPane(editorArea);
container.add(scrollPane);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e){
dispose();
}
});
setTitle("MyText");
setSize(600, 400);
setVisible(true);
}
public static void main(String args[]) {
MyText2 app = new MyText2();
}
}
java编写简单记事本
方法/步骤
下载JDK,并安装成功,CMD测试Java环境安装成功。出现如下提示则Java环境安装成功
打开mycelipse进入主界面,点击左上角file--new---java project,新建一个Java项目,项目名字任意取,这里我取名为note--然后点击完成,创建Java项目
然后右键项目下的src--new---package,新建一个包,包名我定为notetest,然后点击完成
然后右键我们建立好的包notetest--new--class,包名为Note,点击完成
首先我们想导入工程所需要的包,以便编写程序时进行调用
package notepad;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.BufferedWriter;
首先定义好编写程序时变量,我们设为成员变量方便以后调用
public class Notepad{
//屏幕分辨率
int width = Toolkit.getDefaultToolkit().getScreenSize().width;
int height = Toolkit.getDefaultToolkit().getScreenSize().height;
//窗体
private Frame frm ;
//显示内容多行文本
private TextArea notetext;
//记事本菜单
private MenuBar mb;
//菜单
private Menu m ;
//菜单项
private MenuItem open,save;
为程序创建组件--Frame--菜单栏目--文本框TextArea
public Notepad(){init();}
private void init(){
frm = new Frame("模拟记事本");
//设置菜单
mb = new MenuBar();
m = new Menu("文件");
//显示文件的地方
notetext = new TextArea();
notetext.setBounds(30, 50, 750, 500);
frm.add(notetext);
myEvent();
为控件和按钮添加监听事件
private void myEvent() {
//打开菜单的事件处理
open.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//判断路径和文件名是否为空 如果为空结束程序
if(dir == null || name == null)
//如果不为空讲路径名和文件名封装到File对象里
file = new File(dir,name);
//使用字符缓冲读取文件
BufferedReader bfr = null;
try {
bfr = new BufferedReader(new FileReader(file));
});
save.addActionListener(new ActionListener(){
//获取路径和文件名
String dir =fd.getDirectory();
String name = fd.getFile();
//如果不为空讲路径名和文件名封装到File对象里
file = new File(dir,name);
}
BufferedWriter bfr= null;
}
});
}
}
然后创建主方法,开始测试程序,新建一个NoteDemo类
package notepad;
public class NoteDemo {
public static void main(String[] args) {
new Notepad();
}
}
如何用JAVA程序编写一个记事本
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.undo.CannotRedoException;
import javax.swing.undo.UndoManager;
import java.util.Date;
import java.text.SimpleDateFormat;
public class Notepad extends JFrame {
// 菜单
JMenuBar menub = new JMenuBar();
// 显示纯文本的多行区域
JTextArea text = new JTextArea();
JMenu files = new JMenu("文件(F)");
JMenu edit = new JMenu("编辑(E)");
JMenu formats = new JMenu("格式(O)");
JMenu help = new JMenu("帮助(H)");
JMenuItem newFile = new JMenuItem("新建(N)");
JMenuItem open = new JMenuItem("打开(O)");
JMenuItem save = new JMenuItem("保存(S)");
JMenuItem saveAs = new JMenuItem("另存为(A)");
JMenuItem exit = new JMenuItem("退出(X)");
JMenuItem undo = new JMenuItem("撤销(U)");
JMenuItem cut = new JMenuItem("剪切(T)");
JMenuItem copy = new JMenuItem("复制(C)");
JMenuItem paste = new JMenuItem("粘贴(P)");
JMenuItem selectAll = new JMenuItem("全选(A)");
JMenuItem timeDate = new JMenuItem("时间/日期(D)");
JCheckBoxMenuItem lineWrap = new JCheckBoxMenuItem("自动换行(M)");
JMenuItem fonts = new JMenuItem("字体");
JMenuItem about = new JMenuItem("关于记事本(A)");
JFrame th = this;
String name;
String openedPath = null;
boolean opened = false;
boolean reworked = false;
UndoManager undoManager = new UndoManager();
// 初始化窗体
public Notepad(String name) {
super(name);
this.name = name;
int x, y;
// 得到用户屏幕大小
Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
x = (size.width - 600) / 2;
y = (size.height - 400) / 2;
setSize(600, 400);
// 让程序界面显示在屏幕中央
setLocation(x, y);
// 将此窗口的最小大小设置为一个常量值。
setMinimumSize(new Dimension(250, 150));
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
// 初始化布局
void init() {
files.setMnemonic('F');
edit.setMnemonic('E');
formats.setMnemonic('O');
help.setMnemonic('H');
newFile.setMnemonic('N');
open.setMnemonic('O');
save.setMnemonic('S');
saveAs.setMnemonic('A');
exit.setMnemonic('X');
undo.setMnemonic('U');
cut.setMnemonic('T');
copy.setMnemonic('C');
paste.setMnemonic('P');
selectAll.setMnemonic('A');
timeDate.setMnemonic('D');
lineWrap.setMnemonic('M');
about.setMnemonic('A');
// 为控件添加助记符
newFile.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,
InputEvent.CTRL_MASK));
open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,
InputEvent.CTRL_MASK));
save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
InputEvent.CTRL_MASK));
exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q,
InputEvent.CTRL_MASK));
cut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,
InputEvent.CTRL_MASK));
copy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,
InputEvent.CTRL_MASK));
paste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,
InputEvent.CTRL_MASK));
selectAll.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A,
InputEvent.CTRL_MASK));
// 为控件添加快捷键
timeDate.setAccelerator(KeyStroke.getKeyStroke("F5"));
files.add(newFile);
files.add(open);
files.add(save);
files.add(saveAs);
files.addSeparator();
files.add(exit);
edit.add(undo);
edit.addSeparator();
edit.add(cut);
edit.add(copy);
edit.add(paste);
edit.addSeparator();
edit.add(selectAll);
edit.add(timeDate);
formats.add(lineWrap);
formats.add(fonts);
help.add(about);
menub.add(files);
menub.add(edit);
menub.add(formats);
menub.add(help);
setJMenuBar(menub);
getContentPane().add(new JScrollPane(text));
Listen listen = new Listen();
Listen1 listen1 = new Listen1();
// 为控件添加事件侦听器
newFile.addActionListener(listen);
undo.addActionListener(listen);
open.addActionListener(listen);
save.addActionListener(listen);
saveAs.addActionListener(listen);
exit.addActionListener(listen);
cut.addActionListener(listen);
copy.addActionListener(listen);
paste.addActionListener(listen);
selectAll.addActionListener(listen);
timeDate.addActionListener(listen);
lineWrap.addActionListener(listen);
about.addActionListener(listen);
open.addActionListener(listen1);
save.addActionListener(listen1);
saveAs.addActionListener(listen1);
// 暂时没有实现的功能 :设置字体
//undo功能没有实现
fonts.setEnabled(false);
}
class Listen implements ActionListener {
// 实现用于一般操作的事件侦听器
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source == newFile) {
text.setText("");
// 设置标题
th.setTitle(name);
openedPath = null;
opened = false;
} else if (source == exit)
setVisible(false);
else if (source == undo)
try {
//此功能没有实现 撤销要用栈?
// undo.setEnabled(undoManager.canUndo());
undoManager.undo();
} catch (CannotRedoException cre) {
cre.printStackTrace();
}
else if (source == selectAll)
text.selectAll();
else if (source == cut)
text.cut();
else if (source == copy)
text.copy();
else if (source == paste)
text.paste();
else if (source == lineWrap)
// 设置文本区的换行策略(获取文本区的换行策略)
text.setLineWrap(!text.getLineWrap());
else if (source == about) {
String message = "--------\n版本:1.0\n作者:时超" +
"\n撤销功能要用堆栈存贮操作" +
"\n还有字体格式"+
"\n暂时没有实现" +
"\n\n感谢您的使用";
JOptionPane.showMessageDialog(th, message, "关于",
JOptionPane.PLAIN_MESSAGE);
} else if (source == timeDate) {
Date nowTime = new Date();
SimpleDateFormat times = new SimpleDateFormat(
"HH:mm yyyy-MM-dd");
text.insert(times.format(nowTime), text.getCaretPosition());
}
}
}
class Listen1 implements ActionListener {
// 实现用于对文件进行操作的事件侦听器
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
// 打开文件事件
if (source == open) {
// 显示对话窗口 以便选择文件
FileDialog openFile = new FileDialog(th, "打开文件",
FileDialog.LOAD);
openFile.setVisible(true);
// 获取文件路径
String filePath = openFile.getDirectory() + openFile.getFile();
try {
FileInputStream fis = new FileInputStream(filePath);
byte[] content = new byte[fis.available()];
fis.read(content);
text.setText(new String(content));
// 设置 TextComponent 的文本插入符的位置
text.setCaretPosition(0);
if (openFile.getFile() != null) {
th.setTitle(openFile.getFile() + name);
openedPath = filePath;
opened = true;
}
fis.close();
} catch (Exception ex) {
ex.printStackTrace();
}
opened = true;
}
// 保存及另存为事件
else if (source == save || source == saveAs) {
String savePath = openedPath;
if (savePath == null || source == saveAs) {
// 如果 mode 的值为 LOAD,那么文件对话框将查找要读取的文件,所显示的文件是当前目录中的文件
// 如果 mode 的值为 SAVE,则文件对话框将查找要写入文件的位置。
FileDialog saveFile = new FileDialog(th, "保存文件",
FileDialog.SAVE);
saveFile.setVisible(true);
savePath = saveFile.getDirectory() + saveFile.getFile();
}
try {
FileOutputStream fos = new FileOutputStream(savePath);
fos.write(text.getText().getBytes());
fos.close();
} catch (Exception ex) {
ex.printStackTrace();
}
if (source == save)
openedPath = savePath;
}
}
}
public static void main(String[] args) {
try {
// 使用当前线程的上下文类加载器加载给定类名称所指定的 LookAndFeel
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
System.err.println("Couldn't use the system look and feel:" + e);
}
String name = ("--记事本 版本1.0--");
Notepad note = new Notepad(name);
note.init();
note.setVisible(true);
}
}
如何用java一步步编出一个记事本程序
一、要创建一个Frame或者JFrame现在基本上都用后者
二、要建立你的控件,就是面板Jpanel菜单JMenu\JMenuItem等,写字板textArea等,
三、动作监听器,addActionListener
四、就是你的布局了
一下是一个可以运行的,你看看
package mySwing;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.awt.color.*;
import java.awt.font.*;
import javax.swing.plaf.metal.MetalLookAndFeel;
import javax.swing.undo.*;
public class Note extends JFrame {
boolean isChange = false;
boolean wasChange = false;
JMenuBar menuBar = new JMenuBar();
JMenu menuFile = new JMenu("File");
JMenuItem menuFileOpen = new JMenuItem("Open..");
JMenuItem menuFileSave = new JMenuItem("Save..");
JMenuItem menuFileExit = new JMenuItem("Exit");
JMenu menuEdit = new JMenu("Edit");
JMenuItem menuFileCut = new JMenuItem("Cut");
JMenuItem font = new JMenuItem("Font");
JMenuItem menuFilePaste = new JMenuItem("Paste");
JTextArea fileArea = new JTextArea();
public Note() {
//menuFile.setIcon(new ImageIcon("D:\\���컢���ļ�\\eclipswork\\MyTest\\bin\\remove.png"));
// fileArea.setBorder(BorderFactory.createTitledBorder("mytextArea"));
this.setTitle("���±�");
Toolkit tool = this.getToolkit();// ����ͼ�꣡
Image myimage = tool.getImage("����.jpg");
this.setIconImage(myimage);
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
exit();
}
});
menuFileOpen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//fileOpen_actionPerformed(e);
}
});
menuFileSave.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fileSave_actionPerformed(e);
}
});
menuFileExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fileExit_actionPerformed(e);
}
});
menuFileCut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fileCut_actionPerformed(e);
}
});
menuFilePaste.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
filePaste_actionPerformed(e);
}
});
font.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fileColor_actionPerformed(e);
}
});
fileArea.getDocument().addDocumentListener(new DocumentListener() {
public void insertUpdate(DocumentEvent e) {
wasChange = isChange;
isChange = true;
}
public void removeUpdate(DocumentEvent e) {
wasChange = isChange;
isChange = true;
}
public void changedUpdate(DocumentEvent e) {
wasChange = isChange;
isChange = true;
}
});
setSize(500, 450);
menuBar.add(menuFile);
menuFile.setMnemonic('F');
menuBar.add(menuEdit);
menuEdit.setMnemonic('E');
menuFile.add(menuFileOpen);
menuFileOpen.setMnemonic('O');// ���ʽ�;
menuFileOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,
InputEvent.CTRL_MASK));// ��ݽ�;
menuFile.add(menuFileSave);
menuFileSave.setMnemonic('S');
menuFileSave.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
InputEvent.CTRL_MASK));
menuFile.addSeparator();
menuFile.add(menuFileExit);
menuFileExit.setMnemonic('E');
menuEdit.add(menuFileCut);
menuFileCut.setMnemonic('C');
menuFileCut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,
InputEvent.CTRL_MASK));
menuEdit.add(menuFilePaste);
menuFilePaste.setMnemonic('P');
menuFilePaste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P,
InputEvent.CTRL_MASK));
menuEdit.add(font);
font.setMnemonic('N');
font.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,
InputEvent.CTRL_MASK));
this.getContentPane().add(new JScrollPane(fileArea));
setJMenuBar(menuBar);
fileArea.setLineWrap(true);
}
public void fileExit_actionPerformed(ActionEvent e) {
System.exit(0);
}
public void fileOpen_actionPerformed(ActionEvent e) {
// ������filter;
JFileChooser fileChooser = new JFileChooser();
// fileChooser.addChoosableFileFilter(new
// myFilter("*.txt","Files(*.txt)"));
fileChooser.addChoosableFileFilter(fileChooser.getFileFilter());
if (fileChooser.APPROVE_OPTION != fileChooser.showOpenDialog(this))
return;
// �������ļ���
BufferedReader dataIn = null;
try {
dataIn = new BufferedReader(new FileReader(fileChooser
.getSelectedFile().getPath()));
String c = null;
do {
c = dataIn.readLine();
if (c != null)
fileArea.append(c + "\n");
} while (c != null);
} catch (Exception ex) {
System.out.println("Catch exception:" + ex.toString());
}
}
public void exit() {
if (isChange == false)
System.exit(1);
else {
int decision = JOptionPane.showConfirmDialog(this,
"The File has Change.\n"
+ "Do you want to save the change?", "Notepad",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.WARNING_MESSAGE);
if (decision == JOptionPane.YES_OPTION) {
// �����ǽ��ļ�д������!
try {
JFileChooser fileSave = new JFileChooser();
fileSave.setDialogTitle("�����ļ�");
// fileSave.addChoosableFileFilter(new
// myFilter("*.txt","Files(*.txt)"));
fileSave.addChoosableFileFilter(fileSave.getFileFilter());
if (fileSave.APPROVE_OPTION != fileSave
.showSaveDialog(this))
return;
BufferedWriter dataOut = new BufferedWriter(
new BufferedWriter(new FileWriter(fileSave
.getSelectedFile())));
String c = null;
isChange = false;
do {
String str = fileArea.getText();
dataOut.write(str);
dataOut.close();
} while (c != null);
} catch (Exception e2) {
System.out.println("Catch exception:���!" + e2.toString());
}
} else if (decision == JOptionPane.NO_OPTION)
System.exit(1);
else if (decision == JOptionPane.CANCEL_OPTION)
;
;
}
// innerclass.fileSave_actionPerformed();
}
public void fileSave_actionPerformed(ActionEvent e1) {
// �����ǽ��ļ�д������!
try {
JFileChooser fileSave = new JFileChooser();
fileSave.setDialogTitle("�����ļ�");
// fileSave.addChoosableFileFilter(new
// myFilter("*.txt","Files(*.txt)"));
fileSave.addChoosableFileFilter(fileSave.getFileFilter());
if (fileSave.APPROVE_OPTION != fileSave.showSaveDialog(this))
return;
BufferedWriter dataOut = new BufferedWriter(new BufferedWriter(
new FileWriter(fileSave.getSelectedFile() + ".txt")));
// RandomAccessFile dataOut=new
// RandomAccessFile(fileSave.getSelectedFile(),"rw");
String c = null;
isChange = false;
do {
String str = fileArea.getText();
dataOut.write(str);
dataOut.close();
} while (c != null);
} catch (Exception e2) {
System.out.println("Catch exception:���!" + e2.toString());
}
}
public static void main(String arg[]) {
//new MyUIManager();
Note nt = new Note();
JLookAndFeelMenu menu = new JLookAndFeelMenu(nt);
nt.menuBar.add(menu);
nt.show();
}
public void fileCut_actionPerformed(ActionEvent e) {
fileArea.cut();
}
public void filePaste_actionPerformed(ActionEvent e) {
fileArea.paste();
}
public void fileColor_actionPerformed(ActionEvent e) {
JColorChooser fileColor = new JColorChooser();
// fileArea.setForeground(fileColor.showDialog(this,"��ɫ",Color.red));
// fileArea.setSelectionColor(fileColor.showDialog(this,"��ɫ",Color.red));
fileArea.setSelectionColor(fileColor
.showDialog(this, "��ɫ", Color.black));
}
}