java实现极简单的 TXT小说阅读器(第二版)
第二版在第一版的基础上增加了
对文字大小、样式、名字的改变功能。
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;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("宋体");//按钮JButton filePath = new JButton("打开文件");filePath.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(); }}});JPanel buttonp = new JPanel();buttonp.add(filePath);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(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小说阅读器(第二版)相关推荐
- java实现极简单的 TXT小说阅读器(第三版)
第三版在第二版的基础上增加了 保存 以及另存为的选项. 并且完善了简单的菜单栏. SaveAndSaveAs类: public class SaveAndSaveAs { public SaveAnd ...
- java实现极简单的 TXT小说阅读器
public class Display_txt extends JFrame { JFrame jframe = new JFrame(); JTextArea content; boolean f ...
- 北大青鸟java第一单元项目_北大青鸟java第一单元项目迷你TXT小说阅读器
[实例简介] 自用 已通过老师检测 得分88分 北大青鸟java第一单元项目迷你TXT小说阅读器,可以作为java se学习项目也可以作为其他项目,项目完整可直接运行 [实例截图] [核心代码] TX ...
- C# 写一个简单的TXT小说阅读器
目的 上班的时候看小说不是要上那些网站看,就是要下载txt用那些文本阅读器看,很是麻烦.就想做一个简单的txt小说阅读器.要求不高,只要能打开txt文档并显示章节目录,并且能够点击跳转至章节处即可. ...
- 因为无聊 自己写的一个 TXT小说阅读器 PC版(winfrom)
应为无聊 自己写的一个 TXT小说阅读器,支持老板键,自动贴边隐藏,划水神器^^ 主要特色: ①支持拖拽txt文件到阅读器中自动打开txt文件,主要代码: //拖拽TXT文件到窗体并加载TXT文件pr ...
- 安卓手机上有哪些好用的txt小说阅读器?
txt格式是一款非常常见的小说格式,很多手机由于自身不能直接打开txt格式文件或者软件使用感较差而给我们阅读带来困扰.今天小编就为大家介绍几款可以在安卓手机上使用的txt小说阅读器. 第一款:neat ...
- 套路继续, .txt 小说阅读器功能开发
1, 解决一个 bug 正文结尾 (最后一行最后一个字)跟右边界, 有多余的空白间隔 Core Text 的渲染流程,就是富文本绘制 从流程上看, 感觉这一页的文字分配少了,给他加点字,就满了 // ...
- Mac苹果电脑上有哪些好用的txt小说阅读器?
epub.txt是常见的电子书格式,我们在网上下载小说时经常会遇到.Mac电脑由于系统的"挑剔性",想必平时大家通常会遇到自己使用的小说阅读器不能在Mac系统上兼容的问题,今天小编 ...
- PC免费简约开源的TXT小说阅读器(提取章节、书籍分组管理、记忆阅读进度、换肤、换字体、换主题)仅支持Windows
最近自己做了个小说阅读器,就是下面这个东西啦,目前仅支持Window系统 个人喜欢在电脑.平板上等大屏幕设备上阅读小说或电子书籍.原因其一是屏幕足够大,可以选择更舒服的字体大小:其二是觉得小屏幕看字体 ...
最新文章
- Linux停用“黑名单”,因为这是敏感词,涉嫌种族歧视
- XCODE 所有DeviceSupport
- Linux上用Docker部署Net Core项目
- 2020 年 4 月全国程序员工资新鲜出炉,我拖后腿了!
- [cocoapods]安装cocoapods
- IntelliJ IDEA快捷键学习
- 开放搜索查询分析服务架构解读
- 腾讯音乐娱乐集团宣布管理层调整,着眼长远战略发展与行业生态布局
- 【ECJTU_ACM 11级队员2012年暑假训练赛(8) - F - A Mame】
- Python一些常用模块
- 破解,汉化,越狱,解锁,为什么中国的大神总是“昙花一现”?
- 2020年信工所考研经验分享
- VIX 指数构造详细证明过程
- Agilent GeneSpring GX V11.5_win32_win64扩展生物学分析软件
- vs2019(C语言) 使用教程
- 《我的眼睛--图灵识别》第四章:基础:图片识别
- 爱快可以外接文件服务器吗,听说爱快路由器也支持NAS了?
- java设计大全——计算机设计参考选题(SSM+SpringBoot+vue+html)(持续更新)
- The file Tomcat.exe was not found... Either the CATALINA_HOME environment variable is not defin
- Linux下安装pymysql步骤
热门文章
- Uber Go 风格指南中文版
- android手机听广播,RadioTime让你的android也能听收音机
- Element-UI组件之表单Form
- 发送垃圾邮件的僵尸网络——药物(多)、赌博、股票债券等广告+钓鱼邮件、恶意下载链接、勒索软件+推广加密货币、垃圾股票、色情网站(带宏的office文件、pdf等附件)...
- Ecplse常用快捷键
- 配置nginx的地址和路径的代理
- stm32mp1开发板入门pangu
- 好一场逗鹅冤:一瓶老干妈撬动BAT
- Pandas | 数据融合与拼接(Merge Concat)
- ctrl+c 不能使用,无法复制