操作系统课程设计----二级文件系统.doc_第1页
操作系统课程设计----二级文件系统.doc_第2页
操作系统课程设计----二级文件系统.doc_第3页
操作系统课程设计----二级文件系统.doc_第4页
操作系统课程设计----二级文件系统.doc_第5页
已阅读5页,还剩13页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

学号10225608129武汉理工大学华夏学院课 程 设 计课程名称 操作系统课程设计题目 为LINUX 设计一个简单的二级文件系统专 业 软件技术 班 级 2081班 姓 名 赵然 成 绩 指导教师 赵传斌、 司晓梅 2011年1月17日 至 2011年1月21日课程设计任务书设计题目:为LINUX 设计一个简单的二级文件系统设计目的:1、通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能及内部实现。2、提高学生的程序设计能力、 提高算法设计质量与程序设计素质 。设计任务:(在规定的时间内完成下列任务)为LINUX 设计一个简单的二级文件系统。要求做到以下几点:1、可以实现下列几条命令(至少4条)Login用户登录Dir列文件目录Create创建文件Delete删除文件Open打开文件Close关闭文件Read读文件Write写文件2、列目录时要列出文件名、物理地址、保护码和文件长度。3、源文件可以进行读写保护。时间安排: 1月 17日 布置课程设计任务;分配题目后,查阅资料、 准备程序; 1月 18日1月20 日上机调试程序、书写课程设计报告;1月21 日上午提交课程设计报告及相关文档。地点:学校机房(具体见现代教育中心大屏幕安排)具体要求:1、课程设计报告按统一通用格式书写,具体格式要求请在网络上查阅2、每位学生应独立完成各自的任务且每天至少在设计室工作半天指 导 教 师 签 名: 11年 1月 7日教研室主任(或责任教师)签名: 11年 1月 7 日1.实现原理首先,实现Login用户登录,(用户名:zhaoran 密码:1234)必须登录成功才能进入文件系统进行查看,进入后,通过树状展示文件目录(默认文件目录是C:Program Files),右侧显示文件夹图标或者文件图标,选中节点鼠标右击弹出菜单,有新建目录,新建文件,删除文件,打开文件,属性菜单项,并分别实现其功能。2.开发环境开发工具 MyEclipse 7.0开发语言 Java3.关键算法实现流程图3.1流程图登陆验证账号密码目录右键选择操作新建目录新建文件删除打开属性结束账号错误账号正确3.2具体算法代码3.2.1登陆模块public class Login extends JFrame private static final long serialVersionUID = 1L;private JPanel jContentPane = null;private JLabel jLabel1 = null;private JLabel jLabel2 = null;private JLabel jLabel = null;private JTextField jTextField1 = null;private JPasswordField jPasswordField = null;private JButton jButton1 = null;private JButton jButton2 = null;private JTextField getJTextField1() if (jTextField1 = null) jTextField1 = new JTextField();jTextField1.setPreferredSize(new Dimension(10, 25);jTextField1.setBounds(new Rectangle(183, 59, 169, 30);return jTextField1;private JPasswordField getJPasswordField() if (jPasswordField = null) jPasswordField = new JPasswordField();jPasswordField.setBounds(new Rectangle(183, 99, 169, 30);jPasswordField.addKeyListener(new java.awt.event.KeyAdapter()public void keyPressed(java.awt.event.KeyEvent e)if(e.getKeyChar()=KeyEvent.VK_ENTER)test(););return jPasswordField;public static void main(String args) SwingUtilities.invokeLater(new Runnable() public void run() Login thisClass = new Login();thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);thisClass.setVisible(true););public Login() super();initialize();private void initialize() this.setSize(400, 250);Dimension d=Toolkit.getDefaultToolkit().getScreenSize();Dimension fsize=this.getSize();this.setLocation(d.width-fsize.width)/2, (d.height-fsize.height)/2);this.setContentPane(getJContentPane();this.setTitle(二级文件系统);private JButton getJButton2() if (jButton2 = null) jButton2 = new JButton();jButton2.setBounds(new Rectangle(218, 167, 90, 32);jButton2.setText(取消);jButton2.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent e) System.exit(0););return jButton2;private JPanel getJContentPane() if (jContentPane = null) jLabel = new JLabel();jLabel.setText(密码:);jLabel.setHorizontalAlignment(SwingConstants.CENTER);jLabel.setBounds(new Rectangle(27, 101, 132, 29);jLabel2 = new JLabel();jLabel2.setText(用户名:);jLabel2.setBounds(new Rectangle(27, 59, 133, 29);jLabel2.setHorizontalAlignment(SwingConstants.CENTER);jLabel2.setPreferredSize(new Dimension(10, 15);jLabel1 = new JLabel();jLabel1.setText(登陆界面);jLabel1.setFont(new Font(u534eu6587u5b8bu4f53, Font.BOLD, 24);jLabel1.setBounds(new Rectangle(0, 0, 389, 32);jLabel1.setForeground(new Color(255, 0, 54);jLabel1.setHorizontalAlignment(SwingConstants.CENTER);jContentPane = new JPanel();jContentPane.setLayout(null);jContentPane.add(jLabel1, null);jContentPane.add(jLabel2, null);jContentPane.add(jLabel, null);jContentPane.add(getJTextField1(), null);jContentPane.add(getJPasswordField(), null);jContentPane.add(getJButton1(), null);jContentPane.add(getJButton2(), null);return jContentPane;private JButton getJButton1() if (jButton1 = null) jButton1 = new JButton();jButton1.setBounds(new Rectangle(79, 168, 84, 33);jButton1.setText(确定);jButton1.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) test(););return jButton1;public void test()if(jTextField1.getText().equals(zhaoran)&String.valueOf(jPasswordField.getPassword().equals(1234)String aa=aa,bb;Contents.main(aa); setVisible(false);elseJOptionPane.showMessageDialog(Login.this, 输入错误!请重新输入!);3.2.2新建文件目录private class newMenuAction implements ActionListener public void actionPerformed(ActionEvent arg0) try String Name = JOptionPane.showInputDialog(创建目录名称:); if (!Name.equals() TreePath path = tree.getSelectionPath(); MutableTreeNode node = (MutableTreeNode) path.getLastPathComponent(); DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); MutableTreeNode newNode = new DefaultMutableTreeNode(Name); tree.fireTreeExpanded(path); if (node.getAllowsChildren()model.insertNodeInto(newNode, node, 0);else JOptionPane.showMessageDialog(null, 不能给文件追加下级目录!);return;String fullPath = ;for (Object obj : path.getPath() String str = obj.toString();if (str.endsWith()str = str.substring(0, str.length() - 1);if (fullPath.equals()fullPath += str;elsefullPath += + str;File parentDir = new File(fullPath);if (parentDir.isDirectory() File currentFile = new File(fullPath + + Name);currentFile.mkdir(); else JOptionPane.showMessageDialog(null, 文件名不能为空!); catch (HeadlessException e) e.printStackTrace();3.2.3新建文件private class newFileAction implements ActionListener public void actionPerformed(ActionEvent e) TreePath tp = tree.getSelectionPath();String fullPath = ;for (Object obj : tp.getPath() String str = obj.toString();if (str.endsWith()str = str.substring(0, str.length() - 1);if (fullPath.equals()fullPath += str;elsefullPath += + str;String FileName = JOptionPane.showInputDialog(创建文件名称:);if (!FileName.equals(null) File f = new File(fullPath + + FileName);try f.createNewFile(); catch (IOException e1) / TODO Auto-generated catch blocke1.printStackTrace(); else JOptionPane.showMessageDialog(null, 文件名不能为空!);3.2.4删除功能private class MenuAction implements ActionListener public void actionPerformed(ActionEvent e) TreePath tp = tree.getSelectionPath();DefaultMutableTreeNode node = (DefaultMutableTreeNode) tp.getLastPathComponent();DefaultTreeModel dtm = (DefaultTreeModel) tree.getModel();dtm.removeNodeFromParent(node);String fullPath = ;for (Object obj : tp.getPath() String str = obj.toString();if (str.endsWith()str = str.substring(0, str.length() - 1);if (fullPath.equals()fullPath += str;elsefullPath += + str;File currentFile = new File(fullPath);if (currentFile.isFile()currentFile.delete();elsedeleteDir(currentFile);public static boolean deleteDir(File dir) if (dir.isDirectory() String subDir = dir.list();for (String s : subDir) deleteDir(new File(dir, s);return dir.delete();3.2.5打开文件public class Open_File public static void main(String args) DemoWindow2 dw = new DemoWindow2(打开文件);Toolkit theKit = dw.getToolkit();Dimension wndSize = theKit.getScreenSize();dw.setBounds(wndSize.width/3,wndSize.height/3,wndSize.width/3,wndSize.height/3);dw.setVisible(true);class DemoWindow2 extends JFrame implements ActionListener, Runnable private static final long serialVersionUID = 1L;JTextArea jta = new JTextArea();int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;JScrollPane jsp = new JScrollPane(jta, v, h);JPanel jp1 = new JPanel();JButton jb = new JButton(打开文件);public DemoWindow2(String title) super(title);jp1.add(jb);add(jsp);add(jp1, BorderLayout.SOUTH);jb.addActionListener(this);public void actionPerformed(ActionEvent e) new Thread(this).start();public void run() jta.setText();JFileChooser jfc = new JFileChooser(System.getProperty(user.home);jfc.setFileFilter(new TXTFilter();if (jfc.showOpenDialog(this) = JFileChooser.APPROVE_OPTION) File file = jfc.getSelectedFile();if (file != null) try FileInputStream fis = new FileInputStream(file);ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(this, 读取进度, fis);ProgressMonitor pm = pmis.getProgressMonitor();pm.setMillisToDecideToPopup(10);pm.setMillisToPopup(0);byte readbyte = new byte10;while (pmis.read(readbyte) 0) jta.append(new String(readbyte, GB2312);Thread.sleep(10);if (pm.isCanceled() jta.append(nn终止读取文件!);pmis.close(); catch (Exception e) System.out.println(e.getMessage();class TXTFilter extends FileFilter public boolean accept(File f) if (f.isDirectory() return true;String filePostfix = txt ;for (String str : filePostfix) if (getExtension(f).equals(str)return true;return false;public String getDescription() return TXT文件(*.txt);public static String getExtension(File f) String ext = ;String s = f.getName();int i = s.lastIndexOf(.);if (i 0 & i s.length() - 1) ext = s.substring(i + 1).toLowerCase();return ext;3.2.6查看文件属性public class Proper extends JFrame private static final long serialVersionUID = 1L;private JPanel jContentPane = null; private String fullPath;private JTextArea jTextArea = null;private JScrollPane jScrollPane = null;public Proper(String fullPath) super();this.fullPath=fullPath;initialize();private void initialize() this.setSize(332, 221);Dimension d=Toolkit.getDefaultToolkit().getScreenSize();Dimension fsize=this.getSize();this.setLocation(d.width-fsize.width)/2, (d.height-fsize.height)/2);this.setContentPane(getJContentPane();this.setTitle(查看文件属性);this.setVisible(true);private JPanel getJContentPane() if (jContentPane = null) jContentPane = new JPanel();jContentPane.setLayout(null);jContentPane.add(getJScrollPane();return jContentPane;private JScrollPane getJScrollPane() if (jScrollPane = null) jScrollPane = new JScrollPane();jScrollPane.setBounds(new Rectangle(3, 1, 319, 185);jScrollPane.setViewportView(getJTextArea();return jScrollPane;private JTextArea getJTextArea() if (jTextArea = null) jTextArea = new JTextArea();jTextArea.setBounds(new Rectangle(3, 1,

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论