第三版在第二版的基础上增加了

保存 以及另存为的选项。

并且完善了简单的菜单栏。

SaveAndSaveAs类:

public class SaveAndSaveAs { public SaveAndSaveAs(JTextArea textArea,String filePath){BufferedWriter bw = null;try {OutputStream os = new FileOutputStream(filePath);bw = new BufferedWriter(new OutputStreamWriter(os));for (String value : textArea.getText().split("\n")) {bw.write(value);bw.newLine();//换行}} catch (IOException e1) {e1.printStackTrace();} finally {if (bw != null) {try {bw.close();} catch (IOException e1) {e1.printStackTrace();}}}}
}

WordStyleSet类:

public class WordStyleSet {public static void StyleSet(JTextArea jtextarea,String wordName,int wordStyle,int wordSize){Font font = new Font(wordName,wordStyle,wordSize);jtextarea.setFont(font);}
}

Display_txt类:

public class Display_txt extends JFrame {JFrame jframe = new JFrame();JTextArea content,wordSizeSetArea,wordStyleSetArea,wordNameSetArea;JMenuBar menubar = new JMenuBar();JMenu menu_file = new JMenu("文件");JMenu menu_about = new JMenu("关于");JMenuItem menuItem_open = new JMenuItem("打开");JMenuItem menuItem_save = new JMenuItem("保存");JMenuItem menuItem_saveAs = new JMenuItem("另存为");JMenuItem menuItem_exit = new JMenuItem("退出");JMenuItem menuItem_about = new JMenuItem("软件说明");boolean flag = true;String str_filePath = null;public Display_txt(){//文字输入框(文字显示窗口)content = new JTextArea(10,50);content.setAutoscrolls(true);JScrollPane contentScroll = new JScrollPane(content);content.setBorder(BorderFactory.createBevelBorder(1));JPanel upper = new JPanel(new BorderLayout());upper.add(contentScroll);//字体大小设置窗口wordSizeSetArea = new JTextArea(1,3);wordSizeSetArea.setBorder(BorderFactory.createBevelBorder(1));wordSizeSetArea.setText("12");//字体样式设置窗口(加粗等)wordStyleSetArea = new JTextArea(1,3);wordStyleSetArea.setBorder(BorderFactory.createBevelBorder(1));wordStyleSetArea.setText("0");//字体名字设置窗口(宋体等)wordNameSetArea = new JTextArea(1,3);wordNameSetArea.setBorder(BorderFactory.createBevelBorder(1));wordNameSetArea.setText("宋体");//(菜单栏)文件——打开menuItem_open.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){try{JFileChooser jfc = new JFileChooser();if(jfc.showOpenDialog(jframe)==JFileChooser.APPROVE_OPTION ){str_filePath = jfc.getSelectedFile().getAbsolutePath();BufferedReader bufferedReader = new BufferedReader(new FileReader(str_filePath));String str_line;while((str_line=bufferedReader.readLine())!=null){if(flag){content.setText(str_line);flag = false;}else{content.setText(content.getText()+"\n"+str_line);}}bufferedReader.close();}}catch(FileNotFoundException e1){e1.printStackTrace();}catch(IOException e2){e2.printStackTrace();}}});//按钮JButton wordSizeSet = new JButton("设置字体大小");wordSizeSet.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){try{WordStyleSet.StyleSet(content,wordNameSetArea.getText(),Integer.parseInt(wordStyleSetArea.getText()),Integer.parseInt(wordSizeSetArea.getText()));}catch(Exception e0){e0.printStackTrace();               }}});//按钮JButton wordStyleSet = new JButton("设置字体样式");wordStyleSet.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){try{WordStyleSet.StyleSet(content,wordNameSetArea.getText(),Integer.parseInt(wordStyleSetArea.getText()),Integer.parseInt(wordSizeSetArea.getText()));}catch(Exception e0){e0.printStackTrace();                }}});//按钮JButton wordNameSet = new JButton("设置字体名字");wordNameSet.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){try{WordStyleSet.StyleSet(content,wordNameSetArea.getText(),Integer.parseInt(wordStyleSetArea.getText()),Integer.parseInt(wordSizeSetArea.getText()));}catch(Exception e0){e0.printStackTrace();              }}});//(菜单栏)文件——另存为menuItem_saveAs.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){JFileChooser jfc = new JFileChooser();if(jfc.showSaveDialog(jframe)==JFileChooser.APPROVE_OPTION )new SaveAndSaveAs(content,jfc.getSelectedFile().getPath());}});//(菜单栏)文件——保存menuItem_save.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){new SaveAndSaveAs(content,str_filePath);}});//(菜单栏)文件——退出menuItem_exit.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){System.exit(0);}   });//(菜单栏)关于——软件说明menuItem_about.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){JOptionPane.showMessageDialog(jframe, "版本1.0    作者:snnile","软件说明", JOptionPane.INFORMATION_MESSAGE); }});menu_file.add(menuItem_open);menu_file.add(menuItem_save);menu_file.add(menuItem_saveAs);menu_file.add(menuItem_exit);menubar.add(menu_file);menu_about.add(menuItem_about);menubar.add(menu_about);JPanel buttonp = new JPanel();buttonp.add(wordSizeSet);buttonp.add(wordSizeSetArea);buttonp.add(wordStyleSet);buttonp.add(wordStyleSetArea);buttonp.add(wordNameSet);buttonp.add(wordNameSetArea);JPanel all = new JPanel(new GridLayout(1,1));all.add(upper);jframe.add(menubar,BorderLayout.NORTH);jframe.add(buttonp,BorderLayout.SOUTH);jframe.add(all,BorderLayout.CENTER);jframe.pack();Toolkit tool = Toolkit.getDefaultToolkit();Dimension screen = tool.getScreenSize();jframe.setLocation(screen.width/2-jframe.getWidth()/2,screen.height/2-jframe.getHeight()/2);jframe.setTitle("TXT小说阅读器");jframe.setVisible(true);jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}public static void main(String args[]){Display_txt display_demo = new Display_txt();}}

图一:

图二:

图三:

图四:

图五:

java实现极简单的 TXT小说阅读器(第三版)相关推荐

  1. java实现极简单的 TXT小说阅读器

    public class Display_txt extends JFrame { JFrame jframe = new JFrame(); JTextArea content; boolean f ...

  2. java实现极简单的 TXT小说阅读器(第二版)

    第二版在第一版的基础上增加了 对文字大小.样式.名字的改变功能. WordStyleSet类: public class WordStyleSet {public static void StyleS ...

  3. 北大青鸟java第一单元项目_北大青鸟java第一单元项目迷你TXT小说阅读器

    [实例简介] 自用 已通过老师检测 得分88分 北大青鸟java第一单元项目迷你TXT小说阅读器,可以作为java se学习项目也可以作为其他项目,项目完整可直接运行 [实例截图] [核心代码] TX ...

  4. C# 写一个简单的TXT小说阅读器

    目的 上班的时候看小说不是要上那些网站看,就是要下载txt用那些文本阅读器看,很是麻烦.就想做一个简单的txt小说阅读器.要求不高,只要能打开txt文档并显示章节目录,并且能够点击跳转至章节处即可. ...

  5. 安卓手机上有哪些好用的txt小说阅读器?

    txt格式是一款非常常见的小说格式,很多手机由于自身不能直接打开txt格式文件或者软件使用感较差而给我们阅读带来困扰.今天小编就为大家介绍几款可以在安卓手机上使用的txt小说阅读器. 第一款:neat ...

  6. 套路继续, .txt 小说阅读器功能开发

    1, 解决一个 bug 正文结尾 (最后一行最后一个字)跟右边界, 有多余的空白间隔 Core Text 的渲染流程,就是富文本绘制 从流程上看, 感觉这一页的文字分配少了,给他加点字,就满了 // ...

  7. 因为无聊 自己写的一个 TXT小说阅读器 PC版(winfrom)

    应为无聊 自己写的一个 TXT小说阅读器,支持老板键,自动贴边隐藏,划水神器^^ 主要特色: ①支持拖拽txt文件到阅读器中自动打开txt文件,主要代码: //拖拽TXT文件到窗体并加载TXT文件pr ...

  8. Mac苹果电脑上有哪些好用的txt小说阅读器?

    epub.txt是常见的电子书格式,我们在网上下载小说时经常会遇到.Mac电脑由于系统的"挑剔性",想必平时大家通常会遇到自己使用的小说阅读器不能在Mac系统上兼容的问题,今天小编 ...

  9. PC免费简约开源的TXT小说阅读器(提取章节、书籍分组管理、记忆阅读进度、换肤、换字体、换主题)仅支持Windows

    最近自己做了个小说阅读器,就是下面这个东西啦,目前仅支持Window系统 个人喜欢在电脑.平板上等大屏幕设备上阅读小说或电子书籍.原因其一是屏幕足够大,可以选择更舒服的字体大小:其二是觉得小屏幕看字体 ...

最新文章

  1. ASP.NET Core WebAPI中的分析工具MiniProfiler
  2. 博士申请 | 宾夕法尼亚州立大学招收机器学习/人工智能方向全奖博士
  3. 众辰nz200变频器使用说明书_ABB变频器
  4. C++for_each| bind1st | ptr_fun | std::function的用法
  5. 基于CentOS7,MySQL5.7的 读写分离
  6. (14)Vivado开发流程(FPGA不积跬步101)
  7. python中select模块_基于python select.select模块通信的实例讲解 如何用python写个串口通信的程序...
  8. LLVM 4中将加入新的LLVM链接器LLD
  9. 统计学习方法读书笔记9-朴素贝叶斯习题
  10. 【Python实例第30讲】F检验与互信息
  11. 2023计算机毕业设计SSM最新选题之java企业财务报销审核系统n8191
  12. halcon学习笔记4-字符识别(包括汉字识别)
  13. 暑期作息时间表模板_暑假作息时间表
  14. MSP MCU I2C入门指南
  15. 教你怎样激励自己做好每一件事
  16. QObject::killTimer: Timers cannot be stopped from another thread
  17. Python: 使用max()获取列表中重复出现次数最多的元素
  18. FormData对象用法
  19. JCJC错别字检测新功能:检测日期格式
  20. [HBNIS2018]excel破解1

热门文章

  1. vmware tool下载安装
  2. C# 保存窗体为图片(保存纵断面图)
  3. 允许或禁止未知来源apk的安装
  4. python中的魔方方法
  5. AD142A0芯片程序空间资源空间分布的总结
  6. Matlab2014b GUI封装exe方法
  7. 特征工程7种常用方法
  8. 解决Stm32出现..\HARDWARE\ADC\adc.c(22): error: #20: identifier ADC_InitTypeDef is undefined异常
  9. 申请Oracle Cloud永久免费主机服务
  10. SSH学习(个人笔记)