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

java 文本編輯器

上傳人:hjk****65 文檔編號(hào):106072584 上傳時(shí)間:2022-06-13 格式:DOCX 頁(yè)數(shù):11 大?。?2.15KB
收藏 版權(quán)申訴 舉報(bào) 下載
java 文本編輯器_第1頁(yè)
第1頁(yè) / 共11頁(yè)
java 文本編輯器_第2頁(yè)
第2頁(yè) / 共11頁(yè)
java 文本編輯器_第3頁(yè)
第3頁(yè) / 共11頁(yè)

下載文檔到電腦,查找使用更方便

15 積分

下載資源

還剩頁(yè)未讀,繼續(xù)閱讀

資源描述:

《java 文本編輯器》由會(huì)員分享,可在線閱讀,更多相關(guān)《java 文本編輯器(11頁(yè)珍藏版)》請(qǐng)?jiān)谘b配圖網(wǎng)上搜索。

1、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;imp

2、ort 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 java

3、x.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 serialV

4、ersionUID = -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 =

5、new JMenuItem(打開(kāi)); 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

6、 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

7、String(); String filePath = ; int dot, mark; public MyFrame() chooser.setSize(400, 350); chooser.setDialogTitle(學(xué)海無(wú)涯苦作舟); 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 BorderLay

8、out(); 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.

9、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 List

10、enActionForJfilechooser(); 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.ad

11、dActionListener(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 ActionList

12、ener 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 FileOutpu

13、tStream(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

14、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); clas

15、s 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 = selectedSt

16、ring(); 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(); cla

17、ss taListener implements CaretListener public void caretUpdate(CaretEvent e) dot = e.getDot(); / 取得光標(biāo)開(kāi)始位置 mark = e.getMark();/ 取得光標(biāo)結(jié)束位置 class copyListener implements ActionListener public void actionPerformed(ActionEvent e) selected = selectedString(); class exitListener implements ActionListener pu

18、blic 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 fi

19、le.createNewFile(); catch (IOException e1) e1.printStackTrace(); try filestream = new FileInputStream(file); la.setText(打開(kāi)的文件是: + file.getName(); catch (Exception e1) e1.printStackTrace(); try ta.read(filestream, this); catch (Exception e1) e1.printStackTrace(); if (e.getSource() = open) int state =

20、 chooser.showOpenDialog(null); file = chooser.getSelectedFile(); if (file != null & state = JFileChooser.APPROVE_OPTION) try filestream = new FileInputStream(file); la.setText(打開(kāi)的文件是: + file.getName(); filePath =file.getPath(); catch (Exception e1) e1.printStackTrace(); try ta.read(filestream, this)

21、; 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(存儲(chǔ)文件名為: + file.getName(); filePath =file.getPath(); else if (result = JFileChooser.CANCEL_

22、OPTION) la.setText(您沒(méi)有選擇任何文件); 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 i

23、oe) 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 sta

24、tic 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);

25、 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 (

26、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 * re

27、turn 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: 編輯器啟動(dòng) * 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);

展開(kāi)閱讀全文
溫馨提示:
1: 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
2: 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
3.本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
5. 裝配圖網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

相關(guān)資源

更多
正為您匹配相似的精品文檔
關(guān)于我們 - 網(wǎng)站聲明 - 網(wǎng)站地圖 - 資源地圖 - 友情鏈接 - 網(wǎng)站客服 - 聯(lián)系我們

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

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


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