
正文
小说软件代码java java软件小说阅读
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
怎样用实现对txt的自动分段(像小说软件一样)?用Java可以实现吗?
自动分段??
那就是按行分了吧
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
public class EBook {
static final int PAGE_LINE =6;//每页6行
public static void main(String[] args) {
File f = new File("c:\\test.txt");
BufferedReader br;
try {
br = new BufferedReader(new FileReader(f));
String temp;
int line = 0;
int page = 1;
while ((temp = br.readLine()) != null) {
if(line%PAGE_LINE==0){
System.out.println("==========="+page+"页===========");
page++;
}
line++;
System.out.println(temp);
}
br.close();
} catch (Exception e) {
}
}
}
输出样式
相关问答
Q1: 谁能帮我写个Java小项目,是简单的,就写小说TXT阅读器的好了,最少要用到流和集合。麻烦注释下可以吗?
只提供一个小说阅读,如下
package reader;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
public class Notebook {
private JFrame frame;
private JTextArea textArea;
private JMenuBar menuBar;
private JMenu file, format, search, help;
private JMenuItem open, exit;
private JMenuItem font, color, background, speed;
private JMenuItem find, changeto;
private JMenuItem helps, about;
private Boolean autoLineWrap = true;
private String fileName = "未命名";// 文件名
// private File currentFile ;
private JScrollPane jsp;
private JScrollBar jsb;
private Speed sped;
private font font1;
int delay = 10;
Timer timer = new Timer(delay, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jsb.setValue(jsb.getValue() + jsb.getUnitIncrement());
}
});
public Notebook() {
frame = new JFrame();
frame.setTitle("未命名");
frame.setLayout(new BorderLayout());
textArea = new JTextArea();
textArea.setFont(new Font("宋体", Font.PLAIN, 18));// 设置默认字体样式字号
// set input textArea 设置编辑区
textArea.setText("");
textArea.setEditable(false);
textArea.setLineWrap(autoLineWrap);// 设置自动换行
jsp = new JScrollPane(textArea);// set Scroll
jsb = jsp.getVerticalScrollBar();
jsb.addAdjustmentListener(new AdjustmentListener() {
public void adjustmentValueChanged(AdjustmentEvent e) {
int i;
i = jsb.getUnitIncrement();
System.out.println(i);
}
});
frame.add(jsp, BorderLayout.CENTER);
// 菜单
menuBar = new JMenuBar();
file = new JMenu("文件");
file.setMnemonic('F');
format = new JMenu("格式");
search = new JMenu("搜索");
help = new JMenu("帮助");
menuBar.add(file);
menuBar.add(format);
menuBar.add(search);
menuBar.add(help);
// 文件菜单项
open = new JMenuItem("打开...", KeyEvent.VK_O);
exit = new JMenuItem("退出");
file.add(open);
file.add(exit);
// 格式菜单项
// autoLine = new JCheckBoxMenuItem("自动换行");
font = new JMenuItem("字体...");
color = new JMenuItem("颜色...");
background = new JMenuItem("背景颜色...");
speed = new JMenuItem("滚屏速度...");
// format.add(autoLine);
format.add(font);
format.add(color);
format.add(background);
format.add(speed);
// 搜索菜单项
find = new JMenuItem("查找...");
changeto = new JMenuItem("转到...");
search.add(find);
search.add(changeto);
// 帮助菜单项
helps = new JMenuItem("帮助");
about = new JMenuItem("关于");
help.add(helps);
help.add(about);
// 设置菜单条
menuBar.add(file);
menuBar.add(format);
menuBar.add(search);
menuBar.add(help);
frame.setJMenuBar(menuBar);
// sped///
sped = new Speed(jsb, timer);
font1 = new font(textArea);
// 调用监听方法
addEventHandler();
// ////
textArea.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
timer.start();
}
if (e.getClickCount() == 1) {
timer.stop();
}
}
public void mouseEntered(MouseEvent arg0) {
}
public void mouseExited(MouseEvent arg0) {
}
public void mousePressed(MouseEvent arg0) {
}
public void mouseReleased(MouseEvent arg0) {
}
});
// 监听上下键//
textArea.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent arg0) {
if (arg0.getKeyCode() == KeyEvent.VK_UP) {
jsb.setValue(jsb.getValue() - jsb.getUnitIncrement());
}
if (arg0.getKeyCode() == KeyEvent.VK_DOWN) {
jsb.setValue(jsb.getValue() + jsb.getUnitIncrement());
}
}
public void keyReleased(KeyEvent arg0) {
}
public void keyTyped(KeyEvent arg0) {
}
});
//
textArea.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
timer.start();
}
if (e.getClickCount() == 1) {
timer.stop();
}
}
public void mouseEntered(MouseEvent arg0) {
}
public void mouseExited(MouseEvent arg0) {
}
public void mousePressed(MouseEvent arg0) {
}
public void mouseReleased(MouseEvent arg0) {
}
});
}
// /////////初始化frame////////////////
protected void frameInit() {
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
frame.setSize(d.width, d.height);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Dimension b = frame.getSize();
}
private void addEventHandler() {
// 文件项的监听
open.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fileOpen();
jsb.setValue(0);
}
});
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fileExit();
}
});
// 格式菜单的监听
font.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
font1.addEventHandler();
}
});
color.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
formatColor();
}
});
background.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
formatBackground();
}
});
speed.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
sped.liser();
}
});
}
// ////////文件项的方法/////////////////////////
private void fileOpen() {
textArea.setText("");
JFileChooser fileChooser = new JFileChooser();
fileChooser.showOpenDialog(frame);
File file = fileChooser.getSelectedFile();
if (file == null)
return;
fileName = file.getName();// 获得文件名
frame.setTitle(file.getAbsolutePath());
FileInputStream fis = null;
BufferedReader br = null;
try {
fis = new FileInputStream(file);
br = new BufferedReader(new InputStreamReader(fis));
String str = null;
while ((str = br.readLine()) != null) {
textArea.append(str + "\n");
}
System.out.println("打开成功");
textArea.setCaretPosition(0);
} catch (IOException e1) {
JOptionPane.showMessageDialog(frame, "文件不存在或已被损坏");
} finally {
if (br != null)
try {
br.close();
} catch (IOException e) {
}
if (fis != null)
try {
fis.close();
} catch (IOException e) {
}
}
}
private void fileExit() {
int option = -1;
Object options[] = { "Yes", "No" };
option = JOptionPane.showOptionDialog(frame, "是否退出阅读?", "exit",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
options, options[0]);
switch (option) {
case JOptionPane.YES_OPTION:
System.exit(0);
}
}
// //////////////////////////////////////////////////////////
// ///////////////格式项的方法/////////////////////////////////
private void formatColor() {
// 弹出颜色色选择器对话框
Color color = JColorChooser.showDialog(textArea, "选择颜色", Color.BLACK);
textArea.setForeground(color);
}
private void formatBackground() {
// 弹出颜色色选择器对话框
Color color = JColorChooser.showDialog(textArea, "选择颜色", Color.BLACK);
textArea.setBackground(color);
}
// ////////////////////////////////////////////////////////////
public static void main(String args[]) {
Notebook nt = new Notebook();
nt.frameInit();
}
}
class font {
private JTextArea textArea;
private JButton ok, cancel;
private JComboBox fontName, fontSize, fontStyle;
GraphicsEnvironment ge;// 定义系统字体对象
String[] size = { "8", "10", "12", "14", "16", "18", "20", "22", "24",
"26", "28", "32", "36", "48", "72", "96" };
String[] style = { "PLAIN", "BOLD", "ITALIC" };
JFrame jf = new JFrame("字体设置");
public font(JTextArea textArea) {
this.textArea = textArea;
JLabel label1 = new JLabel(
" 字体 ");
JLabel label2 = new JLabel(" 字号 ");
JLabel label3 = new JLabel(" 样式 ");
ge = GraphicsEnvironment.getLocalGraphicsEnvironment();// 获取系统字体
String[] fontname = ge.getAvailableFontFamilyNames();
fontName = new JComboBox(fontname);
fontSize = new JComboBox(size);
fontStyle = new JComboBox(style);
ok = new JButton("确定");
cancel = new JButton("取消");
jf.setLayout(new BorderLayout());
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
JPanel p3 = new JPanel();
p1.add(label1);
p1.add(label2);
p1.add(label3);
p2.add(fontName);
p2.add(fontSize);
p2.add(fontStyle);
p3.add(ok);
p3.add(cancel);
jf.add(p1, BorderLayout.NORTH);
jf.add(p2, BorderLayout.CENTER);
jf.add(p3, BorderLayout.SOUTH);
jf.setSize(360, 200);
jf.setLocation(300, 200);
jf.setVisible(false);
jf.setResizable(false);
// addEventHandler();
}
void addEventHandler() {
jf.setVisible(true);
ok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String n1 = (String) fontName.getSelectedItem();
int n2 = fontStyle.getSelectedIndex();
String n3 = (String) fontSize.getSelectedItem();
textArea.setFont(new Font(n1, n2, Integer.parseInt(n3)));
jf.setVisible(false);
}
});
cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jf.setVisible(false);//
}
});
}
}
class Speed implements ItemListener {
private JScrollBar jsb;
private JFrame jfrm;
private JLabel jlb1;
// JLabel jlb2;
private JButton jbt;
// private JCheckBox jcheckbox;
private JComboBox jcbb;
Integer sudu;
Timer timer;
private Integer msg[] = { 1, 10, 18, 36, 48, 66, 80, 90 };
public Speed(final JScrollBar jsb, final Timer timer) {
this.jsb = jsb;
this.timer = timer;
jfrm = new JFrame();
jlb1 = new JLabel("滚屏速度");
jbt = new JButton("确定");
// jcheckbox = new JCheckBox("自动滚屏");
jcbb = new JComboBox(msg);
jfrm.setLayout(new FlowLayout());
jfrm.add(jlb1);
jfrm.add(jcbb);
// jfrm.add(jcheckbox); jfrm.add(jbt);
jfrm.setVisible(false);
jcbb.setEditable(true);
jfrm.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
jfrm.pack();
}
void liser() {
jfrm.setVisible(true);
// /////监听复选框///////////////////////////
jcbb.addItemListener(this);
/*
* jcbb.addActionListener(new ActionListener(){ public void
* actionPerformed(ActionEvent e) {
* jcbb.setSelectedIndex(jcbb.getSelectedIndex()); }});
*/
// ///////监听按钮//////////////////////////
jbt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
jfrm.setVisible(false);
}
});
// ////////////////////////////////////
/*
* jcheckbox.addItemListener(new ItemListener(){ public void
* itemStateChanged(ItemEvent e) { if(jcheckbox.isSelected()==false){
* System.out.println("false"); timer.stop(); }
* if(jcheckbox.isSelected()==true){ timer.start(); } }} );
*/
}
@Override
public void itemStateChanged(ItemEvent arg0) {
sudu = (Integer) jcbb.getSelectedItem();
// jcbb.setSelectedItem(msg);//jcbb.updateUI() ;
jsb.setUnitIncrement(sudu.intValue());
}
}
Q2: 我想要制作一个看小说的软件,内容等等我都想好了,要怎样能制作成功?
那当然是要具备相关的电脑知识了~~~最起码C语言 C++ java 等程序设计语言你是要会的(个人觉得C 就行 万能啊) 再一个你还需要耐心 很大的耐心 我们那会做程序 编写代码 成天眼都冒绿光
咳咳.............实在不行,你也舍得了钱的话,把你的要求一说,可以直接去请人给你做一套!!!高手在人间 啊
Q3: java问题 我用流读取一个txt小说,把小说的内容放进一个集合里, 代码怎么写?
public static void main(String[] args) {
try{
File file = new File("E:\\a.txt");//创建文件对象
BufferedReader br = new BufferedReader(new FileReader(file)); //创建读取流
//读取数据
String temp = br.readLine();
String line;
while((line = br.readLine()) != null){
temp += "," + line;
}
if(temp == null){
System.out.println();
}else{
//分割字符串
String []str = temp.split(",");
//创建double数组并赋值
Double[] d = new Double[str.length];
for(int i = 0 ;i str.length ;i++){
d[i] = Double.parseDouble(str[i]);
}
//打印double数组
for(int i = 0 ; i d.length ; i++){
System.out.println(d[i]);
}
}
}catch(Exception e){
}
Q4: java语言框架编写小说阅读器代码
int option = -1;
Object options[] = { "Yes", "No" };
option = JOptionPane.showOptionDialog(frame, "是否退出阅读?", "exit",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
options, options[0]);
switch (option) {
case JOptionPane.YES_OPTION:
System.exit(0);
}
}
Q5: 怎么用java在nokia6120c上生成一个手机小说阅读器
呵呵,阅读器不是生成的,而是安装的,安装程序是可以网上下载的
在百度中或谷歌中搜索java版的手机阅读器,会找到你所要求的:
另注意:
nokia6120c 操作系统为Symbian S60 第三版因此不太适合安装智能机型版的Nokia Symbian阅读器
但nokia6120c 支持 MIDP2.0 和CLDC1.1
比较合适跑java软件,运行普通java阅读器之类软件多多有余。
请楼主上网上搜索。 注意java版的安装程序是.jad和.jar文件
而symbian版的阅读器为.sis
不要下错了。
哦忘了还有要交待, nokia6120c手机安装上阅读器后,从网上下载文章看是没有问题的,不过我忘了nokia6120c是否支持 jsr75可选包,如果支持的话就能把文章下载到本地空间看。如果不支持的话不仅不能下载到本地,而且会使得引用了jsr75包的安装文件无法安装。 这个就在乎楼主多多尝试一下了,或者上网下载一些对手机java性能进行测试的程序测一下
关于小说软件代码java和java软件小说阅读的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







