西安文理学院数学与计算机工程学院 课程设计报告
附录
主要程序代码:
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 -
相关推荐: