thực hiện phân tích, thiết kế và lập trình theo hướng đối tượng để quản lí đối tượng và các thao tác của Xây dựng chương trình mô phỏng chương trình soạn thảo Notepa

41 263 0
thực hiện phân tích, thiết kế và lập trình theo hướng đối tượng để quản lí đối tượng và các thao tác của Xây dựng chương trình mô phỏng chương trình soạn thảo Notepa

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

VIỆN ĐẠI HỌC MỞ HÀ NỘI KHOA CÔNG NGHỆ THÔNG TIN BÁO CÁO BÀI TẬP LỚN MÔN: LẬP TRÌNH HƯỚNG ĐỐI TƯỢNG ĐỀ SỐ : LTHDT.HKI.0810 XÂY DỰNG CHƯƠNG TRÌNH MƠ PHỎNG CHƯƠNG TRÌNH SOẠN THẢO NOTEPAD Giảng viên hướng dẫn ` : Sinh viên thực hiên `: Trịnh Thị Xuân Nguyễn Thành An Nguyễn Thị Hà Li Lê Minh Ngọc Lê Đức Trung Hà Nội – - 16A2 17A2 16A2 16A2 PHÂN CÔNG CÔNG VIỆC Họ Tên Công việc Nguyễn Thành An Lê Minh Ngọc Nguyễn Thị Hà Li Lê Đức Trung Làm chức about Làm chức menu edit Làm chức menu format Làm giao diện , làm chức menu file , viết báo cáo Đánh giá Ghi - MỤC LỤC - I II III Xác định toán Phát biểu vấn đề Mục tiêu Các chức Xác định sơ đồ lớp toán Giao diện phần mền Phân tích lớp Sơ đồ quan hệ lớp Mơ tả thuật toán – thao tác Các chức Mơ tả thao tác thực chức 2.1 file 2.2 edit 2.3 format 2.4 about Thuật toán code 3.1 new file 3.2 open file 3.3 save & save as 3.4 exit 3.5 edit 3.6 format 3.7 about I Xác Định Bài Toán 1.Phát biểu vấn đề - - Phân tích đề : “ Thực phân tích – thiết kế lập trình hướng đối tượng để quản lý đối tượng thao tác “ xây dựng chương trình mơ chương trình soạn thảo Notepad “ Đây chương trình soạn thảo văn đơn giản dễ dùng , ứng dụng cần thiết đời sống người dùng để lưu trữ liệu dạng văn , Giao diện thân thiện với người dùng , có tính thay đổi kiểu chữ cỡ chữ phông chữ , tìm kiếm thay , Mục tiêu - Người dùng nhập liệu dạng văn để lưu trữ Các chức - Các chức chương trình : File - Tạo file - Mở file - Lưu file - Lưu đè file Edit - Chọn toàn - Sao chép - Cắt - Dán - Undo - Redo - Tìm kiếm - Thay Format - Thay đổi phông chữ , cỡ chữ , kiểu chữ About - Hiện thông tin nhóm lập trình II Xác Định Sơ Đồ Lớp Của Bài Toán Giao diện phần mền - Danh sách menu chương trình - Giao diện change font - Giao diện tìm kiếm - Giao diện replace - Giao diện about ( thơng tin nhóm ) Phân tích lớp  Lớp File - Thuộc tính Phương thức : : Tên file Tạo file , mở file , lưu file , lưu đè file : Nôi dung text , phông chữ , kiểu chữ , cỡ chữ  Lớp Text - Thuộc tính - Phương thức : chép nội dung ( copy ) , cắt nội dung ( cut ) , dán nội dung ( paste ) , trở lại ( undo ) , redo , tìm nội dung ( find ) , thay nội dung ( replace ) , thay đổi phông chữ , kiểu chữ , cỡ chữ Sơ đồ quan hệ lớp File Tên File File() Text Nội dung Phông chữ Kiểu chữ Cỡ chữ Newfile() Openfile() SaveFile() Saveasfile() About Thông tin nhóm lập trình III MƠ TẢ THUẬT TỐN – THAO TÁC Các chức  - Giao diện chương trình Nhập liệu từ bàn phím Có thể dùng phím tắt để thực chức File Tạo file ( Ctrl + N ) Mở file ( Ctrl + O ) Text() Copy() Cut() Paste() Redo() Undo() Replace() Find() Format() return; } JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Save as "); fileChooser.setFileFilter(new FileNameExtensionFilter("Text file", "txt")); int openDialog = fileChooser.showOpenDialog(null); if (openDialog == JFileChooser.APPROVE_OPTION) { String path = fileChooser.getSelectedFile().toString(); File temp = new File(path); if (temp.exists()) { String[] yesNo = {"Yes", "No"}; int question = JOptionPane.showOptionDialog(fileChooser, "File already existed, you want to replace?", "Warning!", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, yesNo, yesNo[1]); if (!(question == 0)) { saveAs(); } } PrintWriter writer; try { writer = new PrintWriter(path + ".txt"); writer.println(taText.getText()); writer.close(); currentFile = path.substring(path.lastIndexOf("\\") + 1) + ".txt"; isSaved = true; } catch (FileNotFoundException ex) { Logger.getLogger(J2LP0006.class.getName()).log(Level.SEVERE, null, ex); } } } public void saveFile() { if (taText.getText().trim().equals("")) { return; } if (isSaved || !currentFile.equals("")) { PrintWriter writer; try { writer = new PrintWriter(currentFile); writer.println(taText.getText()); writer.close(); } catch (FileNotFoundException ex) { Logger.getLogger(J2LP0006.class.getName()).log(Level.SEVERE, null, ex); } } else { saveAs(); } isSaved = true; } 3.4exit Bắt đầu File lưu sai Lưu file Thoát chương trình Kết Thúc public void exit() { String text = taText.getText(); String[] selection = {"Save", "Don't Save", "Cancel"}; if (!text.trim().equals("") && !isSaved) { int select = JOptionPane.showOptionDialog(null, "Do you want to save change?", "My Text Editor (MTE)", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, selection, selection[2]); switch (select) { case 0: if (isSaved) { saveFile(); } else { saveAs(); } System.exit(0); break; case 1: System.exit(0); break; } } else { System.exit(0); } } 3.5 Edit UndoManager undoManager = new UndoManager(); public void redo() { try { undoManager.redo(); } catch (CannotRedoException cre) { } } public void undo() { try { undoManager.undo(); } catch (CannotUndoException cue) { } } public void copy() { String selectedText = taText.getSelectedText(); StringSelection stringSelection = new StringSelection(selectedText); clipboard.setContents(stringSelection, null); } public void cut() { String selectedText = taText.getSelectedText(); StringSelection stringSelection = new StringSelection(selectedText); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(stringSelection, null); taText.replaceSelection(""); } public void paste() { Transferable content = clipboard.getContents(this); try { String dstData = (String) content.getTransferData(DataFlavor.stringFlavor); int position = taText.getCaretPosition(); taText.replaceRange(dstData, position, position); } catch (UnsupportedFlavorException | IOException ex) { Logger.getLogger(J2LP0006.class.getName()).log(Level.SEVERE, null, ex); } } public void find() { String find = Find.tfFind.getText(); String text = J2LP0006.taText.getText(); int caretPosition = J2LP0006.taText.getCaretPosition(); String textPart1; String textPart2; if (Find.rNext.isSelected()) { textPart1 = text.substring(0, caretPosition); textPart2 = text.substring(caretPosition); if (textPart2.contains(find)) { J2LP0006.taText.select(textPart1.length() + textPart2.indexOf(find), textPart1.length() + textPart2.indexOf(find) + find.length()); } } else { // textPart1 = text.substring(0, caretPosition - find.length() + 1); textPart1 = text.substring(0, caretPosition); if (textPart1.lastIndexOf(find) >= 0) { J2LP0006.taText.select(textPart1.lastIndexOf(find), textPart1.lastIndexOf(find) + find.length()); } } } public void findOnReplace() { String find = Replace.tfFind.getText(); String text = J2LP0006.taText.getText(); if (text.contains(find)) { J2LP0006.taText.select(text.indexOf(find), text.indexOf(find) + find.length()); Replace.bReplace.setVisible(true); } } public void replace() { String replace = Replace.tfReplace.getText(); if (!Replace.cbAll.isSelected()) { J2LP0006.taText.replaceSelection(replace); } else { String text = J2LP0006.taText.getText(); text = text.replace(Replace.tfFind.getText(), Replace.tfReplace.getText()); System.out.println(text); J2LP0006.taText.setText(text); } Replace.bReplace.setVisible(false); } 3.6 Format public void init() { java.awt.Font fontDefault = J2LP0006.taText.getFont(); DefaultListModel fontList = new DefaultListModel(); String fonts[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNa mes(); for (int i = 0; i < fonts.length; i++) { fontList.addElement(fonts[i]); } listFont.setModel(fontList); listFont.setSelectedValue(fontDefault.getName(), true); DefaultListModel fontStyle = new DefaultListModel(); fontStyle.addElement("Plain"); fontStyle.addElement("Bold"); fontStyle.addElement("Italic"); fontStyle.addElement("Bold Italic"); listStyle.setModel(fontStyle); listStyle.setSelectedIndex(fontDefault.getStyle()); DefaultListModel fontSize = new DefaultListModel(); for (int i = 3; i

Ngày đăng: 16/01/2019, 13:15

Từ khóa liên quan

Mục lục

  • I . Xác Định Bài Toán

    • 1.Phát biểu vấn đề

    • 2. Mục tiêu

    • 3. Các chức năng

    • II . Xác Định Sơ Đồ Lớp Của Bài Toán

      • 1. Giao diện phần mền

      • 2. Phân tích lớp

      • 3. Sơ đồ quan hệ các lớp

      • III. MÔ TẢ THUẬT TOÁN – THAO TÁC

        • 1 .Các chức năng chính

        • 2. Mô Tả Chi Tiết Các Thao Tác Thực Hiện Chức Năng

          • 2.1 File

          • 2.2 Edit

          • 2.3 Format

          • 2.4 About

          • 3 . Thuật toán và code

            • 3.1. new file ( tạo file mới )

            • 3.2 Open file ( mở file )

            • 3.3 Save & Save As

            • 3.4 exit

            • 3.5 Edit

            • 3.6 Format

            • 3.7 . About

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan