package fileproject;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JScrollPane;
import java.awt.Rectangle;
import javax.swing.JTextPane;
import javax.swing.JTextArea;
import javax.swing.JRadioButton;
import javax.swing.JFileChooser;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.JOptionPane;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Date;
import java.text.DateFormat;
import java.util.Locale;
import com.borland.dbswing.FontChooser;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2008</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class FileFrame extends JFrame {
JPanel contentPane;
JMenuBar MenuBar = new JMenuBar();
JMenu FileMenu = new JMenu();
JMenuItem MenuItemFirst = new JMenuItem();
JMenuItem MenuItemSecond = new JMenuItem();
JMenuItem MenuItemseventh = new JMenuItem();
JScrollPane jsp = new JScrollPane();
JTextArea txashow = new JTextArea();
JFileChooser fcselect = new JFileChooser();
JMenuItem MenuItemthird = new JMenuItem();
JMenuItem MenuItemforth = new JMenuItem();
JMenuItem MenuItemFifth = new JMenuItem();
JMenuItem MenuItemsixth = new JMenuItem();
JMenu editMenu = new JMenu();
JMenuItem MenuItemeighth = new JMenuItem();
JMenuItem MenuItemninth = new JMenuItem();
JMenuItem MenuItemtenth = new JMenuItem();
JMenuItem MenuItemeleventh = new JMenuItem();
JMenuItem MenuItemtweleventh = new JMenuItem();
JMenuItem MenuItemthirteenth = new JMenuItem();
JMenuItem MenuItemforteenth = new JMenuItem();
JMenuItem MenuItemfifteenth = new JMenuItem();
JMenuItem MenuItemsixteenth = new JMenuItem();
JMenuItem MenuItemseventeenth = new JMenuItem();
JMenu fontMenu = new JMenu();
JMenuItem MenuItemeighteenth = new JMenuItem();
JMenuItem MenuItemninteenth = new JMenuItem();
JMenu searchMenu = new JMenu();
JMenuItem MenuItemtwentieth = new JMenuItem();
JMenu helpMenu = new JMenu();
JMenuItem MenuItemtwentyfirst = new JMenuItem();
JMenuItem MenuItemtwentysecond = new JMenuItem();
FontChooser fontchoose = new FontChooser();
public FileFrame() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
this.setJMenuBar(MenuBar);
setSize(new Dimension(406, 389));
setTitle("记事本程序");
FileMenu.setText("文件");
MenuItemFirst.setText("新建");
MenuItemFirst.addActionListener(new
FileFrame_MenuItemFirst_actionAdapter(this));
MenuItemSecond.setText("打开");
MenuItemSecond.addActionListener(new
FileFrame_MenuItemSecond_actionAdapter(this));
MenuItemseventh.setText("退出");
MenuItemseventh.addActionListener(new
FileFrame_MenuItemThird_actionAdapter(this));
jsp.setBounds(new Rectangle( -1, 2, 404, 337));
MenuItemthird.setText("保存");
MenuItemthird.addActionListener(new FileFrame_jMenuItem1_actionAdapter(this));
MenuItemforth.setText("另存为");
MenuItemforth.addActionListener(new FileFrame_jMenuItem2_actionAdapter(this));
MenuItemFifth.setText("页面设置");
MenuItemsixth.setText("打印");
editMenu.setText("编辑");
MenuItemeighth.setText("撤销");
MenuItemninth.setText("剪切");
MenuItemtenth.setText("复制");
MenuItemeleventh.setText("粘贴");
MenuItemtweleventh.setText("删除");
MenuItemthirteenth.setText("查找");
MenuItemforteenth.setText("查找下一个");
MenuItemfifteenth.setText("替换");
MenuItemsixteenth.setText("转到");
MenuItemseventeenth.setActionCommand("时间/日期");
MenuItemseventeenth.setText("时间日期");
MenuItemseventeenth.addActionListener(new
FileFrame_MenuItemseventeenth_actionAdapter(this));
fontMenu.setText("格式");
MenuItemeighteenth.setText("自动换行");
MenuItemninteenth.setText("字体");
MenuItemninteenth.addActionListener(new
FileFrame_MenuItemninteenth_actionAdapter(this));
searchMenu.setText("查看");
MenuItemtwentieth.setText("状态栏");
helpMenu.setText("帮助");
MenuItemtwentyfirst.setText("帮助主题 ");
MenuItemtwentysecond.setText("关于记事本");
fontchoose.setFrame(this);
MenuBar.add(FileMenu);
MenuBar.add(editMenu);
MenuBar.add(fontMenu);
MenuBar.add(searchMenu);
MenuBar.add(helpMenu);
FileMenu.add(MenuItemFirst);
FileMenu.add(MenuItemSecond);
FileMenu.add(MenuItemthird);
FileMenu.add(MenuItemforth);
FileMenu.addSeparator();
FileMenu.add(MenuItemFifth);
FileMenu.add(MenuItemsixth);
FileMenu.addSeparator();
FileMenu.add(MenuItemseventh);
contentPane.add(jsp);
jsp.getViewport().add(txashow);
editMenu.add(MenuItemeighth);
editMenu.addSeparator();
editMenu.add(MenuItemninth);
editMenu.add(MenuItemtenth);
editMenu.add(MenuItemeleventh);
editMenu.add(MenuItemtweleventh);
editMenu.addSeparator();
editMenu.add(MenuItemthirteenth);
editMenu.add(MenuItemforteenth);
editMenu.addSeparator();
editMenu.add(MenuItemfifteenth);
editMenu.add(MenuItemsixteenth);
editMenu.addSeparator();
editMenu.add(MenuItemseventeenth);
fontMenu.add(MenuItemeighteenth);
fontMenu.add(MenuItemninteenth);
searchMenu.add(MenuItemtwentieth);
helpMenu.add(MenuItemtwentyfirst);
helpMenu.add(MenuItemtwentysecond);
}
public void MenuItemFirst_actionPerformed(ActionEvent e) {
if (!txashow.getText().equals("")) {
//当记事本中有内容时,点击新建,弹出是否想保存文件对话框,
int j = JOptionPane.showConfirmDialog(this, "文件"+this.getTitle()+"的文字已经改变\n想保存文件吗?","记事本",JOptionPane.INFORMATION_MESSAGE);
//0表示是,1表示否,2表示撤销
if (j == 0) {
//当点击是,弹出保存对话框
int k = fcselect.showSaveDialog(this);
//k为0表示保存,k为1表示撤销
if (k == 0) {
//保存是按照存储路径和文件名来保存的
/*获取存储路径fcselect.getCurrentDirectory(); 存储路径,方法的返回值是一个File类
获取文件名 fcselect.getSelectedFile().getName()
在存储路径下,将文件以文件名存放*/
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(
fcselect.getCurrentDirectory().toString() +
fcselect.getSelectedFile().getName()));
bw.write(txashow.getText());
bw.flush();
txashow.setText("");
} catch (IOException ex) {
ex.print