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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

java课程设计.docx

1、java课程设计郑州轻工业学院课 程 设 计 任 务 书题目 记事本程序 专业、班级 互联网09-1班 学号 540912010120 姓名 孟繁兴 主要内容、基本要求、主要参考资料等:使用图形用户界面实现。能实现编辑、保存、另存为、查找替换等功能。 参考文献: 郑晓艳 Java程序设计教程 清华大学出版社 第一版 雍俊海 Java程序设计习题集 清华大学出版社 第一版 金保华 Java程序设计实用教程 科学出版社 第一版完 成 期 限: 2011/7/2 指导教师签名: 课程负责人签名: 2011年7月2日郑州轻工业学院本科Java高级程序设计课程设计总结报告设计题目:记事本程序学生姓名:孟

2、繁兴院 系:国际教育学院 专 业:互联网班 级:09-1学 号:540912010120指导教师:黄永丽、宋保卫、金松河 2011年7月2日一、引言11项目的名称 记事本程序12项目背景和目标 背景:掌握图形用户界面设计方法,掌握常用swing组件的使用和事件处理程序设计;掌握文件的I/O操作或程序对数据库的访问。 目标:利用eclipse开发环境,使用图形用户界面实现,能实现编辑、保存、另存为、查找替换等功能。二、需求分析21系统概述使用图形用户界面实现,能实现编辑、保存、另存为、查找替换等功能。22系统运行环境 Jdk-eclipse23功能需求描述 能实现编辑、保存、另存为、查找替换等功

3、能。三、总体设计31开发与设计的总体思想 a分析题目 b根据自己的想法搭建程序界面 c为各个菜单项添加事件处理程序32模块设计 a主界面模块图 1b.菜单栏界面模块图 2图3图4图5四、详细设计1主界面模块public class Editor extends JFrame implements ActionListener private JMenu file, edit, view, about; private JMenuBar jmb; private JTextArea jta; private JScrollPane jsp; private JPopupMenu pop; pri

4、vate boolean wasSaved = true; private File currentFile = null; private Object text; public static void main(String args) new Editor().init(); public Editor() this.setName(文本编辑器1.0); pop = new JPopupMenu(); file = new JMenu(文件); edit = new JMenu(编辑); view = new JMenu(查看); about = new JMenu(关于); jmb =

5、 new JMenuBar(); jta = new JTextArea(30, 30); jsp = new JScrollPane(jta); jta.addMouseListener(new MouseAdapter() Override public void mouseClicked(MouseEvent arg0) if (arg0.getButton() = MouseEvent.BUTTON1) pop.setVisible(false); Override public void mouseReleased(MouseEvent e) if (e.getButton() =

6、MouseEvent.BUTTON3) pop.show(edit, e.getX(), e.getY(); pop.setVisible(true); ); jta.getDocument().addDocumentListener(new DocumentListener() Override public void changedUpdate(DocumentEvent arg0) wasSaved = false; Override public void insertUpdate(DocumentEvent arg0) wasSaved = false; Override publi

7、c void removeUpdate(DocumentEvent arg0) wasSaved = false; ); JMenuItem item; file.add(item = new JMenuItem(新建); item.addActionListener(this); file.add(item = new JMenuItem(打开.); item.addActionListener(this); file.addSeparator(); file.add(item = new JMenuItem(保存); item.addActionListener(this); file.a

8、dd(item = new JMenuItem(另存为.); item.addActionListener(this); file.addSeparator(); file.add(item = new JMenuItem(退出); item.addActionListener(this); file.addSeparator(); edit.add(item = new JMenuItem(复制); item.addActionListener(this); edit.add(item = new JMenuItem(粘贴); item.addActionListener(this); ed

9、it.add(item = new JMenuItem(剪切); item.addActionListener(this); edit.addSeparator(); edit.add(item = new JMenuItem(替换.); item.addActionListener(this); edit.add(item = new JMenuItem(查找.); item.addActionListener(this); edit.addSeparator(); edit.add(item = new JMenuItem(全选); item.addActionListener(this)

10、; view.add(item = new JMenuItem(字体.); item.addActionListener(this); view.add(item = new JMenuItem(颜色.); item.addActionListener(this); about.add(item = new JMenuItem(关于.); item.addActionListener(this); 2.菜单栏界面模块A文件菜单模块保存界面截图图6图7保存界面代码if (command.equals(保存) if (!wasSaved) if (currentFile = null) JFile

11、Chooser jfc = new JFileChooser(); jfc.showSaveDialog(this); File f = jfc.getSelectedFile(); if (f != null) savetoFile(f); currentFile = f; else savetoFile(currentFile); return; public void savetoFile(File f) FileWriter fw = null; try fw = new FileWriter(f); fw.write(jta.getText(); fw.flush(); wasSav

12、ed = true; catch (IOException e) e.printStackTrace(); finally if (fw != null) try fw.close(); catch (IOException e) 打开已保存文件界面截图图8图9打开已保存文件代码if (command.equals(打开.) if (askSave() = 0) return; if (askSave() = 1) jta.setText(); JFileChooser jfc = new JFileChooser(); jfc.showSaveDialog(this); File f = j

13、fc.getSelectedFile(); if (f != null) currentFile = f; openFile(f); return; public void openFile(File f) FileReader fr = null; BufferedReader br = null; try fr = new FileReader(f); br = new BufferedReader(fr); String str = null; while (str = br.readLine() != null) jta.append(str + n); catch (Exceptio

14、n e) e.printStackTrace(); finally try Thread.sleep(200); catch (InterruptedException e1) wasSaved = false; if (br != null) try br.close(); catch (Exception e) if (fr != null) try fr.close(); catch (Exception e) 文件另存为界面截图图10图11 文件另存为代码 if (command.equals(另存为.) JFileChooser jfc = new JFileChooser(); j

15、fc.showSaveDialog(this); File f = jfc.getSelectedFile(); if (f != null) savetoFile(f); currentFile = f; return; public void savetoFile(File f) FileWriter fw = null; try fw = new FileWriter(f); fw.write(jta.getText(); fw.flush(); wasSaved = true; catch (IOException e) e.printStackTrace(); finally if

16、(fw != null) try fw.close(); catch (IOException e) 退出界面截图图12图13 退出界面代码 if (command.equals(退出) if (askSave() = 0) return; else System.exit(0); public int askSave() if (!wasSaved) / 如果没有保存 int choice = JOptionPane.showConfirmDialog(this, 是否保存文件?, 保存文件?, JOptionPane.YES_NO_CANCEL_OPTION); switch (choic

17、e) case JOptionPane.OK_OPTION: / 要求保存文件 if (currentFile = null) / 如果是新建文件 JFileChooser jfc = new JFileChooser(); jfc.showSaveDialog(this); File f = jfc.getSelectedFile(); if (f != null) savetoFile(f); currentFile = f; else / 如果是打开的旧文件 savetoFile(currentFile); return 1; case JOptionPane.NO_OPTION: re

18、turn 1;/ 不保存文件 case JOptionPane.CANCEL_OPTION: return 0;/ 取消 return -1; B.编辑菜单模块复制模块截图图14复制模块代码if (command.equals(复制) jta.copy(); pop.setVisible(false); 粘贴模块截图图15图16粘贴模块代码if (command.equals(粘贴) jta.paste(); pop.setVisible(false); 剪切界面截图图17图18剪切界面代码if (command.equals(剪切) jta.cut(); pop.setVisible(fal

19、se); 全选界面截图图19图20全选界面代码if (command.equals(全选) jta.selectAll(); C.查看菜单模块颜色菜单模块截图图21图22图23图24颜色菜单模块代码if (command.equals(颜色.) Color c = JColorChooser.showDialog(this, 请选择文字颜色, Color.BLACK); jta.setForeground(c); return; 五、实现和源程序import java.awt.BorderLayout;import java.awt.Color;import java.awt.Font;imp

20、ort java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.io.BufferedReader;import java.io.File;import java.io.FileReader;import java.io.Fil

21、eWriter;import java.io.IOException;import javax.swing.AbstractButton;import javax.swing.JColorChooser;import javax.swing.JFileChooser;import javax.swing.JFrame;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JOptionPane;import javax.swing.JPopupMe

22、nu;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.event.DocumentEvent;import javax.swing.event.DocumentListener;import javax.swing.text.JTextComponent;public class Editor extends JFrame implements ActionListener private JMenu file, edit, view, about; private JMenuBar

23、jmb; private JTextArea jta; private JScrollPane jsp; private JPopupMenu pop; private boolean wasSaved = true; private File currentFile = null; private Object text; public static void main(String args) new Editor().init(); public Editor() this.setName(文本编辑器1.0); pop = new JPopupMenu(); file = new JMe

24、nu(文件); edit = new JMenu(编辑); view = new JMenu(查看); about = new JMenu(关于); jmb = new JMenuBar(); jta = new JTextArea(30, 30); jsp = new JScrollPane(jta); jta.addMouseListener(new MouseAdapter() Override public void mouseClicked(MouseEvent arg0) if (arg0.getButton() = MouseEvent.BUTTON1) pop.setVisib

25、le(false); Override public void mouseReleased(MouseEvent e) if (e.getButton() = MouseEvent.BUTTON3) pop.show(edit, e.getX(), e.getY(); pop.setVisible(true); ); jta.getDocument().addDocumentListener(new DocumentListener() Override public void changedUpdate(DocumentEvent arg0) wasSaved = false; Overri

26、de public void insertUpdate(DocumentEvent arg0) wasSaved = false; Override public void removeUpdate(DocumentEvent arg0) wasSaved = false; ); JMenuItem item; file.add(item = new JMenuItem(新建); item.addActionListener(this); file.add(item = new JMenuItem(打开.); item.addActionListener(this); file.addSeparator(); file.add(item = new JMenuItem(保存); item.addActionListener(this); file.add(item = new JMenuItem(另存为.); item.addActionListener(this); file.addSeparator(); file.add(item = new JMenuItem(退出); item.addActionListener(this); file.addSeparator(); edit.add(item = n

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

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