九九热最新网址,777奇米四色米奇影院在线播放,国产精品18久久久久久久久久,中文有码视频,亚洲一区在线免费观看,国产91精品在线,婷婷丁香六月天

歡迎來到裝配圖網(wǎng)! | 幫助中心 裝配圖網(wǎng)zhuangpeitu.com!
裝配圖網(wǎng)
ImageVerifierCode 換一換
首頁 裝配圖網(wǎng) > 資源分類 > DOCX文檔下載  

java 文本編輯器

  • 資源ID:106072584       資源大小:22.15KB        全文頁數(shù):11頁
  • 資源格式: DOCX        下載積分:15積分
快捷下載 游客一鍵下載
會員登錄下載
微信登錄下載
三方登錄下載: 微信開放平臺登錄 支付寶登錄   QQ登錄   微博登錄  
二維碼
微信掃一掃登錄
下載資源需要15積分
郵箱/手機(jī):
溫馨提示:
用戶名和密碼都是您填寫的郵箱或者手機(jī)號,方便查詢和重復(fù)下載(系統(tǒng)自動生成)
支付方式: 支付寶    微信支付   
驗(yàn)證碼:   換一換

 
賬號:
密碼:
驗(yàn)證碼:   換一換
  忘記密碼?
    
友情提示
2、PDF文件下載后,可能會被瀏覽器默認(rèn)打開,此種情況可以點(diǎn)擊瀏覽器菜單,保存網(wǎng)頁到桌面,就可以正常下載了。
3、本站不支持迅雷下載,請使用電腦自帶的IE瀏覽器,或者360瀏覽器、谷歌瀏覽器下載即可。
4、本站資源下載后的文檔和圖紙-無水印,預(yù)覽文檔經(jīng)過壓縮,下載后原文更清晰。
5、試題試卷類文檔,如果標(biāo)題沒有明確說明有答案則都視為沒有答案,請知曉。

java 文本編輯器

package com.lf.frame;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Container;import java.awt.FlowLayout;import java.awt.Font;import java.awt.Frame;import java.awt.Label;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import javax.swing.JFileChooser;import javax.swing.JFrame;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JTextPane;import javax.swing.event.CaretEvent;import javax.swing.event.CaretListener;/* * Description: 文本編輯器 * modifyBy LIFENG * modifyDate 2014-6-24 上午09:55:58 */public class MyFrame extends JFrame /* Fields serialVersionUID: */ private static final long serialVersionUID = -2839804867272812883L; Container c = new Container(); Label la = new Label("書山有路勤為徑!"); JMenuBar jmb = new JMenuBar(); JMenu file = new JMenu("文件"); JMenu edit = new JMenu("編輯"); JMenu option = new JMenu("選項(xiàng)"); JMenu about = new JMenu("關(guān)于"); JMenuItem newFile = new JMenuItem("新建"); JMenuItem open = new JMenuItem("打開"); JMenuItem save = new JMenuItem("保存"); JMenuItem saveAs = new JMenuItem("另存為"); JMenuItem exit = new JMenuItem("退出"); JMenuItem copy = new JMenuItem("復(fù)制"); JMenuItem cut = new JMenuItem("剪切"); JMenuItem paste = new JMenuItem("粘貼"); JMenuItem delete = new JMenuItem("全部刪除"); JMenuItem italic = new JMenuItem("斜體"); JMenuItem bold = new JMenuItem("加粗"); JMenuItem version = new JMenuItem("版本"); JMenuItem help = new JMenuItem("幫助"); JTextPane ta = new JTextPane(); JFileChooser chooser = new JFileChooser(); FileInputStream filestream = null; Myversion exitversion = new Myversion(); String selected = new String(); String filePath = "" int dot, mark; public MyFrame() chooser.setSize(400, 350); chooser.setDialogTitle("學(xué)海無涯苦作舟"); chooser.setVisible(true); la.setSize(200, 20); la.setBackground(Color.orange); Font f = new Font("TimesRoman", Font.PLAIN, 16); c = this.getContentPane(); c.setLayout(new BorderLayout(); c.add(ta, "Center"); this.setJMenuBar(jmb); jmb.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 0); jmb.add(file); jmb.add(edit); jmb.add(option); jmb.add(about); jmb.add(la); file.add(newFile); file.add(open); file.add(save); file.add(saveAs); file.add(exit); edit.add(copy); edit.add(cut); edit.add(paste); edit.add(delete); option.add(italic); option.add(bold); about.add(version); about.add(help); newFile.addActionListener(new ListenActionForJfilechooser(); open.addActionListener(new ListenActionForJfilechooser(); save.addActionListener(new saveListener(); saveAs.addActionListener(new ListenActionForJfilechooser(); exit.addActionListener(new exitListener(); copy.addActionListener(new copyListener(); cut.addActionListener(new cutListener(); paste.addActionListener(new pasteListener(); delete.addActionListener(new deleteListener(); italic.addActionListener(new italicListener(); bold.addActionListener(new boldListener(); version.addActionListener(new showversion(); ta.addCaretListener(new taListener(); ta.setFont(f); /* * 關(guān)閉事件 */ this.addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent windowevent) System.exit(0); ); class saveListener implements ActionListener public void actionPerformed(ActionEvent e) if ("".equals(filePath) filePath = FileUtils.getFilePath(); File file = new File(filePath); if (!file.exists() try file.createNewFile(); catch (IOException e1) e1.printStackTrace(); FileOutputStream fileOutStream = null; try fileOutStream = new FileOutputStream(filePath); catch (FileNotFoundException fe) la.setText("File Not Found"); return; String content = ta.getText(); try fileOutStream.write(content.getBytes(); catch (IOException ioe) la.setText("寫入文件錯(cuò)誤"); finally try if (fileOutStream != null) fileOutStream.close(); catch (IOException ioe2) class boldListener implements ActionListener public void actionPerformed(ActionEvent e) Font f = new Font("TimesRoman", Font.BOLD, 16); ta.setFont(f); class italicListener implements ActionListener public void actionPerformed(ActionEvent e) Font f = new Font("TimesRoman", Font.ITALIC, 16); ta.setFont(f); class deleteListener implements ActionListener public void actionPerformed(ActionEvent e) Font f = new Font("TimesRoman", Font.PLAIN, 16); ta.setText(null); ta.setFont(f); class cutListener implements ActionListener public void actionPerformed(ActionEvent e) String s1 = new String(); selected = selectedString(); s1 = ta.getText(); int length = s1.length(); if (dot < mark) ta.setText(s1.substring(0, dot) + s1.substring(mark, length); else ta.setText(s1.substring(0, mark) + s1.substring(dot, length); class pasteListener implements ActionListener public void actionPerformed(ActionEvent e) ta.paste(); class taListener implements CaretListener public void caretUpdate(CaretEvent e) dot = e.getDot(); / 取得光標(biāo)開始位置 mark = e.getMark();/ 取得光標(biāo)結(jié)束位置 class copyListener implements ActionListener public void actionPerformed(ActionEvent e) selected = selectedString(); class exitListener implements ActionListener public void actionPerformed(ActionEvent e) System.exit(0); class ListenActionForJfilechooser implements ActionListener int result; File file; public void actionPerformed(ActionEvent e) if (e.getSource() = newFile) filePath = FileUtils.getFilePath(); file = new File(filePath); if (!file.exists() try file.createNewFile(); catch (IOException e1) e1.printStackTrace(); try filestream = new FileInputStream(file); la.setText("打開的文件是:" + file.getName(); catch (Exception e1) e1.printStackTrace(); try ta.read(filestream, this); catch (Exception e1) e1.printStackTrace(); if (e.getSource() = open) int state = chooser.showOpenDialog(null); file = chooser.getSelectedFile(); if (file != null && state = JFileChooser.APPROVE_OPTION) try filestream = new FileInputStream(file); la.setText("打開的文件是:" + file.getName(); filePath =file.getPath(); catch (Exception e1) e1.printStackTrace(); try ta.read(filestream, this); catch (Exception e1) e1.printStackTrace(); if (e.getSource() = saveAs) result = chooser.showSaveDialog(ta); file = null; if (result = JFileChooser.APPROVE_OPTION) file = chooser.getSelectedFile(); la.setText("存儲文件名為:" + file.getName(); filePath =file.getPath(); else if (result = JFileChooser.CANCEL_OPTION) la.setText("您沒有選擇任何文件"); FileOutputStream fileOutStream = null; if (file != null) try fileOutStream = new FileOutputStream(file); catch (FileNotFoundException fe) la.setText("File Not Found"); return; String content = ta.getText(); try fileOutStream.write(content.getBytes(); catch (IOException ioe) la.setText("寫入文件錯(cuò)誤"); finally try if (fileOutStream != null) fileOutStream.close(); catch (IOException ioe2) class showversion implements ActionListener public void actionPerformed(ActionEvent e) exitversion.setVisible(true); class Myversion extends Frame /* Fields serialVersionUID: */ private static final long serialVersionUID = -3636792638101875168L; Label l1 = new Label("Author: Lifeng"); Label l2 = new Label("Version 1.0"); Label l3 = new Label("2014.06.24"); Label l4 = new Label("Tel:18688746700"); Myversion() this.setLayout(new FlowLayout(FlowLayout.CENTER, 40, 20); this.add(l1); this.add(l2); this.add(l3); this.add(l4); this.setBounds(200, 180, 300, 200); this.addWindowListener(new myWindowListener(); class myWindowListener extends WindowAdapter public void windowClosing(WindowEvent e) exitversion.setVisible(false); String selectedString() String s = new String(); s = ta.getText(); if (dot < mark) s = s.substring(dot, mark); else s = s.substring(mark, dot); return s; package com.lf.frame;import java.io.File;/* * Description: 文件工具類 * modifyBy EX-LIFENG001 * modifyDate 2014-6-24 上午10:38:46 */public class FileUtils /* * Description: 獲得文件名 * author LIFENG * date 2014-6-24上午10:38:59 * return String */ public static String getFilePath() File path = new File("D:/"); File file = new File(path, "新建文本文檔.txt"); if (!file.exists() return "D:/新建文本文檔.txt" int count = 1; while (true) file = new File(path, "新建文本文檔(" + count + ").txt"); if (!file.exists() return "D:/新建文本文檔(" + count + ").txt" count +; package com.lf.frame;/* * Description: 編輯器啟動 * modifyBy LIFENG * modifyDate 2014-6-24 上午09:56:25 */public class EditorMain public static void main(String args) MyFrame frame1 = new MyFrame(); frame1.setSize(500, 400); frame1.setVisible(true);

注意事項(xiàng)

本文(java 文本編輯器)為本站會員(hjk****65)主動上傳,裝配圖網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對上載內(nèi)容本身不做任何修改或編輯。 若此文所含內(nèi)容侵犯了您的版權(quán)或隱私,請立即通知裝配圖網(wǎng)(點(diǎn)擊聯(lián)系客服),我們立即給予刪除!

溫馨提示:如果因?yàn)榫W(wǎng)速或其他原因下載失敗請重新下載,重復(fù)下載不扣分。




關(guān)于我們 - 網(wǎng)站聲明 - 網(wǎng)站地圖 - 資源地圖 - 友情鏈接 - 網(wǎng)站客服 - 聯(lián)系我們

copyright@ 2023-2025  zhuangpeitu.com 裝配圖網(wǎng)版權(quán)所有   聯(lián)系電話:18123376007

備案號:ICP2024067431-1 川公網(wǎng)安備51140202000466號


本站為文檔C2C交易模式,即用戶上傳的文檔直接被用戶下載,本站只是中間服務(wù)平臺,本站所有文檔下載所得的收益歸上傳人(含作者)所有。裝配圖網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對上載內(nèi)容本身不做任何修改或編輯。若文檔所含內(nèi)容侵犯了您的版權(quán)或隱私,請立即通知裝配圖網(wǎng),我們立即給予刪除!