模拟记事本的程序JAVA语言_附完整代码

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
模拟记事本的程序
源自文库
import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import javax.swing.event.*; public class Frame1 extends JFrame { Container c = new Container(); Label la = new Label("java 文本编辑器!"); JMenuBar jmb = new JMenuBar(); JMenu file = new JMenu("文件"); JMenu edit = new JMenu("编辑"); JMenu option = new JMenu("选项"); JMenu about = new JMenu("关于"); JMenuItem open = new JMenuItem("打开"); JMenuItem save = new JMenuItem("另存为"); JMenuItem exit = new JMenuItem("退出"); JMenuItem copy = new JMenuItem("复制"); JMenuItem cut = new JMenuItem("剪切"); JMenuItem paste = new JMenuItem("粘贴"); JMenuItem delete = new JMenuItem("删除所有"); JMenuItem italic = new JMenuItem("斜体"); JMenuItem bold = new JMenuItem("粗体"); JMenuItem version = new JMenuItem("版本"); JTextPane ta = new JTextPane(); JFileChooser chooser = new JFileChooser(); FileInputStream filestream = null; myversion exitversion = new myversion(); String selected = new String(); int dot, mark; public Frame1() { chooser.setSize(400, 350); chooser.setDialogTitle("java 期末作业!"); chooser.setVisible(true); la.setSize(200, 20); la.setBackground(Color.orange); Font f = new Font("TimesRoman", Font.PLAIN, 16); c = this.getContentPane(); c.setLayout(new BorderLayout()); c.add(ta, "Center");
this.setJMenuBar(jmb); jmb.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 0)); jmb.add(file); jmb.add(edit); jmb.add(option); jmb.add(about); jmb.add(la); file.add(open); file.add(save); file.add(exit); edit.add(copy); edit.add(cut); edit.add(paste); edit.add(delete); option.add(italic); option.add(bold); about.add(version); //about.add(help); open.addActionListener(new ListenActionForJfilechooser()); save.addActionListener(new ListenActionForJfilechooser()); exit.addActionListener(new exitListener()); copy.addActionListener(new copyListener()); cut.addActionListener(new cutListener()); paste.addActionListener(new pasteListener()); delete.addActionListener(new deleteListener()); italic.addActionListener(new italicListener()); bold.addActionListener(new boldListener()); version.addActionListener(new showversion()); ta.addCaretListener(new taListener()); ta.setFont(f); } //当点击 Blod 后,字体变为粗体响应事件 class boldListener implements ActionListener { public void actionPerformed(ActionEvent e) { Font f = new Font("TimesRoman", Font.BOLD, 16); ta.setFont(f); } } //点击 ITalic 后,字体变为斜体响应事件 class italicListener implements ActionListener { public void actionPerformed(ActionEvent e) { Font f = new Font("TimesRoman", Font.ITALIC, 16); ta.setFont(f); }
相关文档
最新文档