第一范文网 - 专业文章范例文档资料分享平台

实现记事本功能模板

来源:用户分享 时间:2025/6/18 4:58:59 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

西安文理学院数学与计算机工程学院 课程设计报告

附录

主要程序代码:

import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*;

class mynotepad extends JFrame{

File file=null; Color color=Color.red; mynotepad(){ initTextContent(); initMenu(); initAboutDialog(); void initTextContent()

getContentPane().add(new JScrollPane(content));

JTextPane content=new JTextPane(); JColorChooser opencolor=new JColorChooser(); new JMenu new JMenu

JMenuItem optionofmenu[][]=new JMenuItem[][]{{

new JMenuItem; void initMenu(){

for(int i=0;i

for(int j=0;j

optionofmenu[i][j].addActionListener this.setJMenuBar(menu);

ActionListener action=new ActionListener(){

- 18 -

西安文理学院数学与计算机工程学院 课程设计报告

public void actionPerformed(ActionEvent e){

String name = e.getActionCommand(); JMenuItem MI=(JMenuItem)e.getSource(); if(file !=null)openfile.setSelectedFile(file);

int returnVal=openfile.showOpenDialog(mynotepad.this); if(returnVal==JFileChooser.APPROVE_OPTION){ file=openfile.getSelectedFile(); unfold(); else if .equals(name)){

if(file!=null) openfile.setSelectedFile(file);

int returnVal=openfile.showSaveDialog(mynotepad.this);

if(returnVal==JFileChooser.APPROVE_OPTION){ file=openfile.getSelectedFile(); else if .equals(name)){

mynotepad f=new mynotepad();

int s=JOptionPane.showConfirmDialog(

if(s==JOptionPane.YES_OPTION) System.exit(0);

color=JColorChooser.showDialog(mynotepad.this,\content.setForeground(color); void saving

try{

FileWriterWritef=newFileWriter(file); Writef.write(content.getText()); Writef.close();

catch(Exception e){e.printStackTrace();} void unfold(){

try{

FileReaderReadf=newFileReader(file);

- 19 -

西安文理学院数学与计算机工程学院 课程设计报告

int len=(int)file.length(); char []buffer=new char[len]; Readf.read(buffer,0,len); Readf.close();

content.setText(new String(buffer));

}catch(Exception e){e.printStackTrace();} void initAboutDialog(){

about.setLayout(new GridLayout(3,1));

about.getContentPane().setBackground(Color.white) about.setModal(true); about.setSize(100,100);

about.setLocation(250,170); public class Notepad{

public static void main(String args[]){ mynotepad noted=new mynotepad(); noted.addWindowListener(new WindowAdapter(){

noted.setSize(640,320); noted.show();

noted.setLocation(150,100);

参考文献:

C程序设计(第三版)

谭浩强,张基文编著.C语言程序设计教程 Herbert Schildt.C语言大全(第二版) C++面向对象程序设计

Harveym.Deitel C++大学教程(第二版) 吴文虎.程序设计大全[M] JAVA面向对象程序设计

Bruce Eckel.java编程思想.第四版

Cay S Horstmann,Gary Cornell.java核心技术卷一.第八版 Joshua Bloch.Effective Java中文版

相关资料网址:http://www.tup.tsinghua.edu.cn

http://www. ptpress.com.cn

- 20 -

搜索更多关于: 实现记事本功能模板 的文档
实现记事本功能模板.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c5pcmf5lk491cf865breu5a66i6tmib010wg_6.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top