ImageVerifierCode 换一换
格式:DOCX , 页数:26 ,大小:607.87KB ,
资源ID:21893318      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/21893318.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(文本编辑器的设计与实现文档格式.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

文本编辑器的设计与实现文档格式.docx

1、打开 菜单保存新建退出另存为文件剪切查找复制字体字号插入对象替换 图4.2.1 功能架构图4.2.2程序主要组件概括1.基本的Frame框架;2.菜单;3.打开文件对话框;4.保存文件对话框;5.颜色对话框;6.Choice下拉列表,运来实现字体设置;7.简单的帮助框架。4.3详细设计4.3.1文件打开与保存文本编辑器的保存和打开功能的实现用文件对话框及输入输出流来完成。先建立打开和保存对话框,在public void actionPerformed(ActionEvent e)里分别用FileWriter()和FileReader()方法实现保存和打开。filedialog_save=new

2、 FileDialog(this,保存文件对话框,FileDialog.SAVE); filedialog_save.setVisible(false); filedialog_load=new FileDialog(this,FileDialog.LOAD); filedialog_load.setVisible(false); filedialog_save.addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) filedialog_save.setVisible(false); );

3、filedialog_load.addWindowListener(new WindowAdapter() filedialog_load.setVisible(false); public void actionPerformed(ActionEvent e) if(e.getSource()=itemSave) filedialog_save.setVisible(true); if(filedialog_save.getFile()!=null) try File file=new File(filedialog_save.getDirectory(), filedialog_save.

4、getFile(); tofile=new FileWriter(file); out=new BufferedWriter(tofile); out.write(area.getText(),0,(area.getText().length(); out.close(); tofile.close(); catch(IOException e1) else if(e.getSource()=itemLoad) filedialog_load.setVisible(true); area.setText(null); String s; if(filedialog_load.getFile()

5、! tryFile file=new File(filedialog_load.getDirectory(), filedialog_load.getFile(); file_reader=new FileReader(file); in=new BufferedReader(file_reader); while(s=in.readLine()! area.append(s+n); in.close(); file_reader.close(); catch(IOException e1) 4.3.2字体,字形,字体大小的设置文本编辑器要实现对字体的设置,选用了GraphicsEnviron

6、ment对象调用String getAvailableFontFamilyNames()方法,该方法可以获取计算机上所有可用的字体名称,并存放到字符串数组中。Choice list;GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment(); String fontName=ge.getAvailableFontFamilyNames();public void itemStateChanged(ItemEvent e) String name=list.getSelectedItem();Font f=ne

7、w Font(name,Font.PLAIN,15); area.setFont(f); else if(e.getSource()=item8) /设置字形(常规,倾斜,加粗) Font font=area.getFont(); int style=font.getStyle(); style=style0; area.setFont(new Font(,style,font.getSize(); else if(e.getSource()=item9) style=style2; else if(e.getSource()=item10) int style=font.getStyle()

8、; style=style1; else if(e.getSource()=item11) /设置字体大小 area.setFont(new Font(font.getName(),style,12); else if(e.getSource()=item12) area.setFont(new Font(font.getName(),style,24); else if(e.getSource()=item13) area.setFont(new Font(font.getName(),style,36);4.3.3剪切,复制,粘贴设置文本编辑器中关于剪切,复制,粘贴功能的实现选用处理JTe

9、xtArea的DocumentEvent事件,通过area.cut(),area.copy(),area.paste()方法,点击“编辑”中相应菜单项可以选择将文本区中选中的内容剪切,复制,粘贴。 public void changedUpdate(DocumentEvent e) String s=area.getText(); public void removeUpdate(DocumentEvent e) changedUpdate(e); public void insertUpdate(DocumentEvent e) else if(e.getSource()=item2) ar

10、ea.cut(); else if(e.getSource()=item3) area.copy(); else if(e.getSource()=item4) area.paste();4.3.4插入子菜单,删除子菜单,创建格式菜单及其菜单项 JMenuItem insertItem=new JMenuItem(插入文本(K) insertItem.setMnemonic(K editMenu.add(insertItem); insertItem.addActionListener( new ActionListener() public void actionPerformed(Acti

11、onEvent event) JPanel insertPanel=new JPanel(); JLabel insertLabel=new JLabel(要插入的内容 JTextField inputText=new JTextField(10); insertPanel.add(insertLabel); insertPanel.add(inputText); JOptionPane.showMessageDialog(null,insertPanel); int fromIndex=displayText.getCaretPosition();/取得当前的光标位置 displayText

12、.insert(inputText.getText(),fromIndex); ); JMenuItem RemoveItem=new JMenuItem(删除(G) RemoveItem.setMnemonic(G editMenu.add(RemoveItem); RemoveItem.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) int start=displayText.getSelectionStart(); int end=displayText.getSelect

13、ionEnd(); displayText.replaceRange(null,start,end); ); editMenu.addSeparator(); bar.add( editMenu );/add editMenu JMenu formatMenu = new JMenu( 格式(R) formatMenu.setMnemonic( R4.3.5创建,添加帮助菜项 JMenu helpMenu = new JMenu( 帮助(H) helpMenu.setMnemonic( H JMenuItem helpItem = new JMenuItem( 帮助主题(H). helpIte

14、m.setMnemonic( helpMenu.add( helpItem ); helpItem.addActionListener( public void actionPerformed( ActionEvent event ) JTextArea helpText = new JTextArea( JScrollPane scroller = new JScrollPane(helpText); JOptionPane.showMessageDialog(null,scroller); bar.add( helpMenu ); /添加4.4设计成果4.4.1运行界面 图2 文本编辑器主

15、界面 图3文本编辑器编辑界面 图4文本编辑器文件界面 图5文本编辑器格式 图6文本编辑器查找界面 图7 文本编辑器帮助界面 图8文本编辑器字体名称界面 图9文本编辑器字体风格界面 图10文本编辑器中帮助中关于对话框 图11查找消息对话框 图12文本编辑器中另存为对话框4.4.2主要代码import java.awt.*;import java.awt.event.*;import java.awt.datatransfer.*;import javax.swing.*;import java.io.*;import java.lang.*; public class Notepad exten

16、ds JFrame private final Color colorvalues = Color.black, Color.blue, Color.red, Color.green ; /定义颜色数组 String styleNames = Bold, Italic ;/定义风格数组 String fontNames = 宋体华文行楷隶书/字体数组 String sizeString = new String30;/字号数组 int size = new int30;/与字号数组对应的字号整数,用于设置文字大小 private JRadioButtonMenuItem colorItems,

17、 fonts; private JCheckBoxMenuItem styleItems; private JTextArea displayText;/定义文本编辑区 private ButtonGroup fontGroup, colorGroup;/字体组,跟字色组 private int style;/字体风格 private JScrollPane scroll;/为文本编辑区提供滚动条 private String selectText = ;/存放文本编辑区中选中的文本内容 private JComboBox styleBox,fontBox,sizeBox;/工具栏 priva

18、te JPanel toolPanel;/存放工具栏 private int rowNumber = 0; private FileDialog fd = new FileDialog(this); / set up GUI public Notepad() super( 记事本 /创建菜单条 JMenuBar bar = new JMenuBar(); setJMenuBar( bar ) / 设置文件菜单及其菜单项 JMenu fileMenu = new JMenu( 文件(F) fileMenu.setMnemonic( F / 设置新建菜单项 JMenuItem newItem =

19、new JMenuItem( 新建(N) newItem.setMnemonic( N fileMenu.add( newItem ); newItem.addActionListener( new ActionListener() public void actionPerformed( ActionEvent event ) displayText.setText( ); / 设置打开菜单项 JMenuItem openItem = new JMenuItem( 打开(O) openItem.setMnemonic( O fileMenu.add( openItem ); openItem

20、.addActionListener( fd.setTitle(打开 /设置标题 fd.show(); if (fd.getFile() != null) File file = new File(fd.getFile(); /用从fd中取得的文件建立新文件,即打开的文件 displayText.setText( try FileReader f = new FileReader(file); BufferedReader b = new BufferedReader(f);/按行读打开的文件,然后传入文本域 String s; try while (s = b.readLine() ! di

21、splayText.append(s + n/将给定文本追加到文本域的当前文本(即把读的内容加入文本域) f.close(); b.close(); catch (IOException ex) catch (FileNotFoundException ex) else return; ); fileMenu.addSeparator(); /加分隔线 / 设置退出菜单项 JMenuItem exitItem = new JMenuItem( 退出(X) exitItem.setMnemonic( x fileMenu.add( exitItem ); exitItem.addActionLi

22、stener( public void actionPerformed( ActionEvent event ) System.exit( 0 ); );bar.add( fileMenu ); /剪切菜单选项 JMenuItem cutItem = new JMenuItem( 剪切(T) cutItem.setMnemonic( T editMenu.add( cutItem ); cutItem.addActionListener( selectText = displayText.getSelectedText();/取得选定的文本 int start = displayText.getSelectionStart();/选定的文本的开始位置 int end = displayText.getSelectionEnd();/选定的文本的结束位置 displayText.replaceRange(, start, end);/*用指定替换文本替换指定开始位置与结束位置之间的文本。 这里指定替换文本为空,即为剪切了文本*/ /复制菜单选项

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1