大理学院课程教案
(实验教学)
课程名称: 应用软件课程设计
课程类型:( 2 )1、必修;2、选修;3、其它
授课对象: 电子信息科学与技术专业(本科) 2013 级 1班
授课时间: 2016 至 2017 学年 1 学期
计划学时: 32 学时(其中:理论 0 ,实验: 32 )
任课教师: 赵文昌
所属学院: 工程学院
课程管理部门(教研室): 信息技术教研室
大理学院教务处 制
课程名称:应用软件课程设计
教 材:
讲 授 人: 赵文昌 专业技术职务:讲师
学 历: 研究生 学 位:硕士
讲授题目:简单记事本设计
所属章节: 计划学时:16
教学目的和要求:
应用Java图形用户界面技术和文件处理编写一个简易记事本程序,要求能够新建文件、保存文件、对选定 文件进行字体设置、进行查/替换以及定制操作等。 同时,需要对程序可能出现的异常进行处理。其主要
目的包括教学重点:
教学难点:
教学方法:
讲授
使用教具:
多媒体
思 考 题:
参考资料:
1. 小型记事本(该java源文件由两个类构成,名称为Notepad.java) import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; class mynotepad extends JFrame { File file=null; Color d; mynotepad() { initTextContent(); initMenu(); initAboutDialog(); } void initTextContent() { getContentPane().add(new JScrollPane(content)); } JTextPane content=new JTextPane(); JFileChooser openfile=new JFileChooser(); JColorChooser opencolor=new JColorChooser(); JDialog about=new JDialog(this); JMenuBar menu=new JMenuBar(); //菜单栏的各个菜单项 JMenu[] menus=new JMenu[]{new JMenu("文件"),new JMenu("编辑"),new JMenu("关于")}; //"文件"菜单项的四个下拉菜单 //编辑菜单的四个下拉菜单 JMenuItem optionofmenu[][]=new JMenuItem[][]{{new JMenuItem("新建"),new JMenuItem("打开"),new JMenuItem("保存"),new JMenuItem("退出")}, {new JMenuItem("复制"),new JMenuItem("剪切"),new JMenuItem("粘贴"),new JMenuItem("颜")}, {new JMenuItem("关于")} }; void initMenu() { for(int i=0;i<menus.length;i++) { menu.add(menus[i]); for(int j=0;j<optionofmenu[i].length;j++) { menus[i].add(optionofmenu[i][j]); optionofmenu[i][j].addActionListener( action ); } } this.setJMenuBar(menu); } ActionListener action=new ActionListener() { //添加事件监听 public void actionPerformed(ActionEvent e) { String name = e.getActionCommand(); JMenuItem MI=(Source(); if("新建".equals(name)) { content.setText(""); file=null; } else if("打开".equals(name)) { if(file !=null) openfile.setSelectedFile(file); int returnVal=openfile.showOpenDialog(mynotepad.this); if(returnVal==JFileChooser.APPROVE_OPTION) { SelectedFile(); unfold(); } } else if("保存".equals(name)) { if(file!=null) openfile.setSelectedFile(file); int returnVal=openfile.showSaveDialog(mynotepad.this); if(returnVal==JFileChooser.APPROVE_OPTION) { SelectedFile(); saving(); } } else if("退出".equals(name)) { mynotepad f=new mynotepad(); int s=JOptionPane.showConfirmDialog(f,"退出?","退出",JOptionPane.YES_NO_OPTION); if(s==JOptionPane.YES_OPTION) it(0); } else if("剪切".equals(name)) { content.cut(); } else if("复制".equals(name)) { py(); } else if("粘贴".equals(name)) { content.paste(); } else if("颜".equals(name)) { color=JColorChooser.showDialog(mynotepad.this,"",color); content.setForeground(color); } else if("关于".equals(name)) { about.setSize(300,150); about.show(); } } }; void saving() { try { FileWriter Writef=new FileWriter(file); Writef.Text()); Writef.close(); } catch(Exception e) { e.printStackTrace(); } } void unfold() { notepad++ try { FileReader Readf=new FileReader(file); int len=(int)file.length(); char []buffer=new char[len]; ad(buffer,0,len); Readf.close(); content.setText(new String(buffer)); } catch(Exception e) { e.printStackTrace(); } } void initAboutDialog() { about.setLayout(new GridLayout(3,1)); ContentPane().setBackground(Color.white); ContentPane().add(new JLabel("我的记事本程序"));//对话框内容 ContentPane().add(new JLabel("制作者:Fwx")); ContentPane().add(new JLabel("2007年12月")); about.setModal(true); //设置对话框前端显示 about.setSize(100,100); about.setLocation(250,170); //设置对话框显示位置 }; } public class Notepad { public static void main(String args[]) { //入口main函数 mynotepad noted=new mynotepad(); noted.addWindowListener(new WindowAdapter() { }); noted.setTitle("我的记事本程序"); //记事本标题 noted.setSize(640,320); //设置记事本大小 noted.show(); noted.setLocation(150,100); //设置记事本显示位置 } } |
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论