日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java简单文本编译器_java -简易文本编辑器

發(fā)布時間:2023/12/2 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java简单文本编译器_java -简易文本编辑器 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.io.*;

/**

*

Title:java -簡易文本編輯器

*

*

Description: 08.5.5 簡易功能

* 1。 打開文件時,無法選擇文件,需手動輸入

* 2. 文件大小超出 多行文本域時,未實現(xiàn)滾動?*?

*

*

Copyright: Copyright (c) 2008

*

*

Company:

*

* @author not attributable

* @version 1.0

*/

public class Eidter implements ActionListener{

JFrame f;

JMenuItem menuItemOpen,menuItemSave,menuItemQuit;

JTextArea jtTet;

String directory = "E://";

String? fileName="";

public Eidter() {

f = new JFrame("無標(biāo)題-記事本");

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

f.setJMenuBar(createJMenuBar());

jtTet = new JTextArea(25,40);

f.getContentPane().add(jtTet);

f.setSize(500,500);

f.setDefaultLookAndFeelDecorated(true);

f.setVisible(true);

}

public JMenuBar createJMenuBar(){

JMenuBar file = new JMenuBar();

JMenu begin = new JMenu("文件");

menuItemOpen= new JCheckBoxMenuItem("打開");

begin.add(menuItemOpen);

menuItemSave = new JCheckBoxMenuItem("保存");

begin.add(menuItemSave);

menuItemQuit = new JCheckBoxMenuItem("退出");

begin.add(menuItemQuit);

menuItemOpen.addActionListener(this);

menuItemSave.addActionListener(this);

menuItemQuit.addActionListener(this);

file.add(begin);

return? file;

}

public void actionPerformed(ActionEvent e){

if(e.getSource() == menuItemOpen){

jtTet.setText(" ");

String[] text = new String[256];

int i=0;

try{

fileName=JOptionPane.showInputDialog(null,"請輸入文件名","打開",JOptionPane.YES_NO_CANCEL_OPTION);

File openFile = new File(fileName);

if(! openFile.exists()){

JOptionPane.showMessageDialog(null,"文件不存在!");

}

else

{

f.setTitle(fileName+"--記事本");

BufferedReader in = new BufferedReader(new FileReader(openFile));

while((text[i]=in.readLine())!=null){

jtTet.append(text[i]);

jtTet.append("/n");

i++;

}

in.close();

}

}catch(IOException ex){

System.out.println("io exception!");

}

}

if(e.getSource() == menuItemSave){

if(fileName.length() == 0){?????????????? try{?????????????????? File openFile = new File("E://未命名.txt");?????????????????? BufferedWriter out = new BufferedWriter(new FileWriter(?????????????????????????? openFile));?????????????????? out.write(jtTet.getText());?????????????????? out.close();??????????????? }catch(IOException ex){?????????? System.out.println("io exception!");?????????? }???????? }?????????? else?????????? {?????????????? try{???????????????????? File openFile = new File(fileName);???????????????????? BufferedWriter out = new BufferedWriter(new FileWriter(???????????????????????????? openFile));???????????????????? out.write(jtTet.getText());???????????????????? out.close();????????????????? }catch(IOException ex){???????????? System.out.println("io exception!");???????????? }?????????? }??????? }??????? if(e.getSource() == menuItemQuit){?????????? System.exit(0);??????? }??? }??? public static void main(String[] args) {?????? Eidter f = new Eidter();??? }

總結(jié)

以上是生活随笔為你收集整理的java简单文本编译器_java -简易文本编辑器的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。