想问一下用JAVA怎么实现类似于word的文字处理功能。老师叫弄一个这样的软件,就是比如在文本框里输入自己想处理的一段文字,然后点一些按钮就会自动把这段文字弄成相应的
格式。主要是用来处理毕业论文的格式的。主要功能大概有:
段落方面:对齐方式,缩进,行间距
文字方面:字体,大小,粗细大家都知道毕业论文的格式复杂,用JAVA弄起来会不会很麻烦呢?
可以的话大概用哪些类就能实现呢?
格式。主要是用来处理毕业论文的格式的。主要功能大概有:
段落方面:对齐方式,缩进,行间距
文字方面:字体,大小,粗细大家都知道毕业论文的格式复杂,用JAVA弄起来会不会很麻烦呢?
可以的话大概用哪些类就能实现呢?
解决方案 »
- 请指教!JAVA 中 判断是不是数字 的两段 代码 有什么区别??
- 一个关于BufferedReader的问题!求救啊!
- 关于socket(连接池)的一个问题(急,在先等,谢谢)
- 客户端通信
- SOS!请教大家一个JNI问题了。
- 各位兄弟姐妹,谁用java做过图象获取及处理,请进来看看,有分相送的哦!
- 如何获取系统下cpu,内存,硬盘使用情况
- Jbuilder的简单问题
- 请问怎样创建一个Date对象!!
- 请大家帮帮忙,小弟初学java!!
- 为什么double类型9999999999999999.0,输出的是10000000000000000?
- 关于StringIndexOutOfBoundsException
可以用一下flex和bison
换word吧
//JTextPane功能比较强大,参见如下程序
import java.awt.*;
import javax.swing.*;
import javax.swing.text.*;
public class TTextPane
{
public static void main(String args[])throws BadLocationException
{
JFrame frm=new JFrame();
JTextPane jtp=new JTextPane();
frm.getContentPane().add(new JScrollPane(jtp),BorderLayout.CENTER);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final StyleContext sc=new StyleContext();
final DefaultStyledDocument dsd=new DefaultStyledDocument(sc);
jtp.setDocument(dsd);jtp.setDragEnabled(true);
Style defaultStyle=sc.getStyle(sc.DEFAULT_STYLE); final Style mainStyle=sc.addStyle("mainStyle", defaultStyle);
StyleConstants.setForeground(mainStyle, Color.blue);
StyleConstants.setFontSize(mainStyle, 10);
StyleConstants.setLeftIndent(mainStyle, 20);
StyleConstants.setFirstLineIndent(mainStyle, 10); final Style secondStyle=sc.addStyle("secondStyle", null);
StyleConstants.setForeground(secondStyle, Color.red); final Style thirdStyle=sc.addStyle("thiredStyle", null);
StyleConstants.setForeground(thirdStyle, Color.green);
StyleConstants.setFontSize(thirdStyle, 30); new Thread(new Runnable(){
public void run(){
try{
dsd.setLogicalStyle(0, mainStyle);
dsd.insertString(0, text, null);
dsd.setParagraphAttributes(0, 1, secondStyle, false);
dsd.setParagraphAttributes(1, 1, thirdStyle, false);
}catch(BadLocationException e){}
}
}).start();
frm.setSize(400,300);
frm.setVisible(true);System.out.println("####");
}
public static final String text =
"Attributes, Styles and Style Contexts\n" +
"The simple PlainDocument class that you saw in the previous " +
"chapter is only capable of holding text. The more complex text " +
"components use a more sophisticated model that implements the " +
"StyledDocument interface. StyledDocument is a sub-interface of " +
"Document that contains methods for manipulating attributes that " +
"control the way in which the text in the document is displayed.\n " +
"The Swing text package contains a concrete implementation of " +
"StyledDocument called DefaultStyledDocument that is used as the " +
"default model for JTextPane and is also the base class from which " +
"more specific models, such as the HTMLDocument class that handles " +
"input in HTML format, can be created. In order to make use of " +
"DefaultStyledDocument and JTextPane, you need to understand how " +
"Swing represents and uses attributes.\n";
}
//呵呵,调整一下格式,让你看的清楚一些
import java.awt.*;
import javax.swing.*;
import javax.swing.text.*;
public class TTextPane
{
public static void main(String args[])throws BadLocationException
{
JFrame frm=new JFrame();
JTextPane jtp=new JTextPane();
frm.getContentPane().add(new JScrollPane(jtp),BorderLayout.CENTER);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final StyleContext sc=new StyleContext();
final DefaultStyledDocument dsd=new DefaultStyledDocument(sc);
jtp.setDocument(dsd);jtp.setDragEnabled(true);
Style defaultStyle=sc.getStyle(sc.DEFAULT_STYLE); final Style mainStyle=sc.addStyle("mainStyle", defaultStyle);
StyleConstants.setForeground(mainStyle, Color.blue);
StyleConstants.setFontSize(mainStyle, 10);
StyleConstants.setLeftIndent(mainStyle, 20);
StyleConstants.setFirstLineIndent(mainStyle, 10); final Style secondStyle=sc.addStyle("secondStyle", null);
StyleConstants.setForeground(secondStyle, Color.red); final Style thirdStyle=sc.addStyle("thiredStyle", null);
StyleConstants.setForeground(thirdStyle, Color.green);
StyleConstants.setFontSize(thirdStyle, 30); new Thread(new Runnable(){
public void run(){
try{
dsd.setLogicalStyle(0, mainStyle);
dsd.insertString(0, text, null);
dsd.setParagraphAttributes(0, 1, secondStyle, false);
dsd.setParagraphAttributes(1, 1, thirdStyle, false);
}catch(BadLocationException e){}
}
}).start();
frm.setSize(400,300);
frm.setVisible(true);System.out.println("####");
}
public static final String text =
"Attributes, Styles and Style Contexts\n" +
"The simple PlainDocument class that you saw in the previous " +
"chapter is only capable of holding text. The more complex text " +
"components use a more sophisticated model that implements the " +
"StyledDocument interface. StyledDocument is a sub-interface of " +
"Document that contains methods for manipulating attributes that " +
"control the way in which the text in the document is displayed.\n " +
"The Swing text package contains a concrete implementation of " +
"StyledDocument called DefaultStyledDocument that is used as the " +
"default model for JTextPane and is also the base class from which " +
"more specific models, such as the HTMLDocument class that handles " +
"input in HTML format, can be created. In order to make use of " +
"DefaultStyledDocument and JTextPane, you need to understand how " +
"Swing represents and uses attributes.\n";
}
其一,word功能强大.
其二,用Java实现的话, 这个打印的话,貌似有点问题.
其三,如果是提交电子档的话,那么你存储文件的格式就有问题了.你如何存储?就算你设计了一套存储及读取的办法,如果与word的格式不一样,别人如何看呢?
再说一句,虽然JTextPane功能很多了,可以设定字体,各种颜色,背景色,缩进等等,但是它的功能肯定无法与word相比,我们设计可视化程序,如果使用系统或者是相关类库提供的现呈组件,目的是方便,但是其功能肯定有一定的局限性.如果你真的想设计很个性化的可视化程序,可能就需要自己设计UI组件,比如说使用最简单的GDI绘图函数,进行显示.