JavaSE的记事本的设计与实现

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
JAVA语言课程设计报告 题 目:记事本的制作 设 计 者: 专业班级: 学 号: 2012年 12 月 24 日 目录 1、系统需求分析 3 2.系统总体设计 3 3 系统详细设计 5 4软件测试 13 5 系统总结 13 6系统设计心得体会 13 7参考文献 13 1、系统需求分析 1.1系统名称: Window记事本 1.2系统介绍: 开发一个window记事本,主要有一个主界面及以下功能: 1:文件的新建,打开,保存,打印,另存等; 2:对文件的编辑,如全选,复制,剪切,粘贴等; 3:对文件的格式操作,如自动换行,字体等; 4:帮助,包括帮助主题,关于。 1.3开发环境 Eclipse 2.系统总体设计 2.1 系统功能结构图 2.2系统文件结构图 2.3系统编辑结构图 2.4系统格式、帮助结构图 3 系统详细设计 3.1.主界面 主界面主要是用于对选择相应的功能进行相应的功能,主界面主要包括文件,编辑,格式,帮助四个下拉菜单功能。 重要代码: ①创建界面,安装各种监听器 public Notebook() { setTitle("记事本 -- 刘兴钢"); con=getContentPane(); text=new JTextArea(); JSPane=new JScrollPane(text); createMenu(); createPopupMenu(); setJMenuBar(mainMenuBar); con.add(JSPane,BorderLayout.CENTER); text.setComponentPopupMenu(popMenu); text.getDocument().addDocumentListener(this); text.addKeyListener(new handleKey()); text.addMouseListener(new handleMouse()); setSize(400,300); setVisible(true); ② 菜单代码 public void createMenu(){ //创建JMenuBar mainMenuBar=new JMenuBar(); //创建四个JMenu fileMenu=new JMenu("文件"); editMenu=new JMenu("编辑"); formatMenu=new JMenu("格式"); helpMenu=new JMenu("帮助"); 3.2.字体设计界面 主要代码 import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import java.awt.*; public class fontDialog extends JDialog implements ActionListener,ListSelectionListener{ public static final int Cancle=0; public static final int OK=1; public static final String [] style={"正常","斜体","粗体","粗斜体"}; public static final String [] size={"8","9","10","11","12","14","16", "18","20","22","24","26","28","36","48","72"}; private Font userFont=null; private int userSelect=Cancle; private JFrame parent=null; private Container con; private JScrollPane nameSPane,styleSPane,sizeSPane; private JPanel panel[]; private JLabel nameLbl,styleLbl,sizeLbl; private JTextField nameText,styleText,sizeText; private JList nameList,styleList,sizeList; private JButton OKBtn,cancleBtn; public fontDialog() { this(null); } public fontDialog(JFrame owner){ super(owner,true); parent=owner; setTitle("字体"); con=getContentPane(); BoxLayout box=new BoxLayout(con,BoxLayout.Y_AXIS); con.setLayout(box); panel=new JPanel[4]; for(int i=0;i<3;i++){ panel[i]=new JPanel(); panel[i].setLayout(new GridLayout(1,3)); } panel[3]=new JPanel(); panel[3].setLayout(new FlowLayout()); nameLbl=new JLabel("字体"); styleLbl=new JLabel("字形"); sizeLbl=new JLabel("大小"); panel[0].add(nameLbl); panel[0].add(styleLbl); panel[0].add(sizeLbl); nameText=new JTextField("宋体"); nameText.setColumns(5); nameText.setEditable(false); styleText=new JTextField("正常"); styleText.setColumns(5); styleText.setEditable(false); sizeText=new JTextField("12"); sizeText.setColumns(5); sizeText.setEditable(false); panel[1].add(nameText); panel[1].add(styleText); panel[1].add(sizeText); GraphicsEnvironment eq = GraphicsEnvironment.getLocalGraphicsEnvironment(); String[] availableFonts= eq.getAvailableFontFamilyNames(); nameList=new JList(availableFonts); nameList.addListSelectionListener(this); nameSPane=new JScrollPane(nameList); styleList=new JList(style); styleList.addListSelectionListener(this); styleSPane=new JScrollPane(styleList); sizeList=new JList(size); sizeList.addListSelectionListener(this); sizeSPane=new JScrollPane(sizeList); panel[2].add(nameSPane); panel[2].add(styleSPane); panel[2].add(sizeSPane); OKBtn=new JButton("确定"); OKBtn.addActionListener(this); cancleBtn=new JButton("取消"); cancleBtn.addActionListener(this); panel[3].add(OKBtn); panel[3].add(cancleBtn); for(int i=0;i<4;i++) con.add(panel[i]); } public int showFontDialog(){ setSize(300,300); int x,y; if (parent!=null){ x=parent.getX()+30; y=parent.getY()+30; }else{ x=150; y=100; } setLocation(new Point(x,y)); setVisible(true); return userSelect; } public Font getFont(){ return userFont; } public void actionPerformed(ActionEvent e){ int styleIndex=Font.PLAIN,fontSize; if(e.getSource()==OKBtn){ if(styleText.getText().equals("正常")) styleIndex=Font.PLAIN; if(styleText.getText().equals("斜体")) styleIndex=Font.ITALIC; if(styleText.getText().equals("粗体")) styleIndex=Font.BOLD; if(styleText.getText().equals("粗斜体")) styleIndex=Font.BOLD | Font.ITALIC; fontSize=Integer.parseInt(sizeText.getText()); userFont=new Font(nameText.getText(),styleIndex,fontSize); userSelect=OK; setVisible(false); }else{ userSelect=Cancle; setVisible(false); } } public void valueChanged(ListSelectionEvent e){ if (e.getSource()==nameList) nameText.setText((String)nameList.getSelectedValue()); if (e.getSource()==styleList) styleText.setText((String)styleList.getSelectedValue()); if (e.getSource()==sizeList) sizeText.setText((String)sizeList.getSelectedValue()); } } 3.3.保存界面 代码 int doSave(){ FileOutputStream fout; byte content[]; int flag; if (!haveName){ flag = doSaveAs(); }else if(changed){ try{ fout=new FileOutputStream(file); content=text.getText().getBytes(); fout.write(content); fout.close(); changed=false; flag = 1; }catch(FileNotFoundException e){ JOptionPane.showMessageDialog(this,"指定的文件名称或属性有问题!"); flag = 0; }catch(IOException e){ JOptionPane.showMessageDialog(this,"无法写文件,请检查文件是否被锁定"); flag = 0; } }else{ flag =1; } return flag; } 3.4.打印设计界面

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序画家

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值