欢迎来到天天文库
浏览记录
ID:37304582
大小:17.42 KB
页数:7页
时间:2019-05-21
《记事本java源代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、packagecom.wyh.day17;importjava.awt.*;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.InputEvent;importjava.awt.event.KeyEvent;importjava.awt.event.MouseEvent;importjava.awt.event.MouseListener;importjava.io.BufferedReade
2、r;importjava.io.BufferedWriter;importjava.io.File;importjava.io.FileNotFoundException;importjava.io.FileReader;importjava.io.FileWriter;importjava.io.IOException;importjava.io.Reader;importjava.io.Writer;importjavax.swing.*;publicclassTestnotePadextendsJFrameimpl
3、ementsActionListener,MouseListener{privateJMenufile_menu,file_menu2;privateJMenuItemfile_new_item,file_open_item,file_save_item,file_save_as_item,page_set_item,exit;privateJMenuItemcancel_item,cut_item,copy_item,paste_item,delete_item;privateJPopupMenupopupmenu;/
4、/快捷菜单privateJMenuBarbar;privateJTextAreatextArea;privateJScrollPanescroll;privateFilefile;privateJFileChooserchooser;publicTestnotePad(){this.setTitle("记事本");this.setIconImage(newImageIcon("images\记事本.jpg").getImage());this.setDefaultCloseOperation(EXIT_ON_CLOSE
5、);Dimensiond=newDimension(500,400);this.setLayout(newFlowLayout());this.setSize(d);this.init();this.addListener();this.setLocationRelativeTo(null);//简单居中this.setVisible(true);}publicvoidinit(){bar=newJMenuBar();file_menu=newJMenu("文件");file_new_item=newJMenuItem(
6、"新建");file_open_item=newJMenuItem("打开");file_save_item=newJMenuItem("保存");file_save_as_item=newJMenuItem("另存为");exit=newJMenuItem("退出");page_set_item=newJMenuItem("页面设置");file_new_item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,InputEvent.CTRL_MASK));fil
7、e_open_item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,InputEvent.CTRL_MASK));file_save_item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK));file_menu.add(file_new_item);file_menu.add(file_open_item);file_menu.add(file_save_ite
8、m);file_menu.add(file_save_as_item);file_menu.addSeparator();file_menu.add(page_set_item);file_menu.add(exit);bar.add(file_menu);file_menu2=newJMenu("编辑");canc
此文档下载收益归作者所有