導航:首頁 > 編程語言 > java文本編輯器課程設計

java文本編輯器課程設計

發布時間:2023-08-06 19:39:42

java 文本編輯器

這么說吧,其實java版的記事本就是一個JTextArea再加上一些菜單項,再加上查找對話框、替換對版話框等。權
除了在「打開」「保存」「新建」等操作時要判斷一下是否彈出「編輯文件已改變,是否保存」的對話框,別的沒多大難度吧。。。。

參考網址里是一個基本實現所有windows自帶記事本的程序,裡面分ReplaceDialog.java、Notepad.java、FontDialog.java、FindDialog.java四個文件,顧名思義,共要建四個類。

你要自己實現的話,可以一步一步地來,慢慢加入復雜的功能。
要的話留下郵箱。

Ⅱ 如何用java編寫一個簡單的文本編輯器

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

public class f1 extends Frame implements ActionListener
{
private MenuBar menubar=new MenuBar();
private Menu filemenu=new Menu("文件");
private Menu editmenu=new Menu("編輯");
private Menu formmenu=new Menu("格式");
private MenuItem[] itemf=new MenuItem[4];
private MenuItem[] iteme=new MenuItem[6];
private MenuItem[] items=new MenuItem[2];
private TextArea tf=new TextArea();

public int a=0,b=0,c=0,style=Font.PLAIN,size=15;
public String s1="red:"+a+" "+"green:"+b+" "+"blue"+c,
s2="宋體";

public String[] sz1={"10","16","24","30","32","36"},
sz2={"宋體","黑體","幼圓","隸書","行楷","Arial","Georgia"},
sz3={"粗體","傾斜","常規","粗斜"};

JDialog dialog=new JDialog(this,"字體",true);
Container cp=dialog.getContentPane();
JLabel[] lb=new JLabel[8];
JLabel lb1=new JLabel(s1,JLabel.LEFT);
JButton b1=new JButton("確定"),
b2=new JButton("取消");
JComboBox jc1=new JComboBox(),
jc2=new JComboBox(),
jc3=new JComboBox();
JScrollBar jb1=new JScrollBar(JScrollBar.HORIZONTAL,10,5,0,260);
JScrollBar jb2=new JScrollBar(JScrollBar.HORIZONTAL,10,5,0,260);
JScrollBar jb3=new JScrollBar(JScrollBar.HORIZONTAL,10,5,0,260);

Ⅲ 《Java》期末課程設計

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class QuestionOne {

/**
* 編程將從鍵盤輸入文本中的子字元串「word」替換為字元串「world」, 並刪除所有的子字元串「this」。
* 序程要求:程序中要包含局遲有注釋,對於使用的變數和方法的功能要加以說明。
*/
public static void main(String[] args) {
BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in));

String message = null; // 存儲用戶輸瞎臘友入的字元磨槐串
try {
while ((message = reader.readLine()) != null) {
// 列印處理前的字元串
System.out.println("輸入的字元串為:" + message);

// 把 word 替換為 world
message = message.replaceAll("word", "world");

// 把 this 替換為 空
message = message.replaceAll("this", "");

// 列印處理後的字元串
System.out.println("處理後為:" + message);
}
} catch (Exception e) {
e.printStackTrace();
System.out.println("出現異常,程序退出!");
}
}
}

Ⅳ java的一個簡單記事本程序設計

這個功能要全些!

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.dbswing.*;
import java.io.*;
import javax.swing.text.*;
import javax.swing.event.*;

/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/

public class Frame1 extends JFrame {
JPanel contentPane;
JMenuBar jMenuBar1 = new JMenuBar();
JMenu jMenuFile = new JMenu();
JMenuItem jMenuFileExit = new JMenuItem();
JMenu jMenuHelp = new JMenu();
JMenuItem jMenuHelpAbout = new JMenuItem();
JLabel statusBar = new JLabel();
BorderLayout borderLayout1 = new BorderLayout();
JScrollPane jScrollPane1 = new JScrollPane();
JTextArea jTextArea1 = new JTextArea();
JMenu jMenu1 = new JMenu();
JMenu jMenu2 = new JMenu();
JMenuItem jMenuItem1 = new JMenuItem();
JMenuItem jMenuItem2 = new JMenuItem();
JMenuItem jMenuItem3 = new JMenuItem();
JMenuItem jMenuItem4 = new JMenuItem();
JMenuItem jMenuItem5 = new JMenuItem();
JMenuItem jMenuItem6 = new JMenuItem();
JMenuItem jMenuItem7 = new JMenuItem();
JMenuItem jMenuItem9 = new JMenuItem();
JMenuItem jMenuItem10 = new JMenuItem();
JMenuItem jMenuItem11 = new JMenuItem();
FontChooser fontChooser1 = new FontChooser();
JCheckBoxMenuItem jCheckBoxMenuItem1 = new JCheckBoxMenuItem();
JFileChooser jFileChooser1 = new JFileChooser();
String currentFileName=null;
boolean motified=false;
Document document1;

//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
document1 = jTextArea1.getDocument();
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(600, 400));
this.setTitle("文本編輯器");
statusBar.setText(" ");
jMenuFile.setText("文件");
jMenuFileExit.setText("退出");
jMenuFileExit.addActionListener(new Frame1_jMenuFileExit_ActionAdapter(this));
jMenuHelp.setText("幫助");
jMenuHelpAbout.setText("關於");
jMenuHelpAbout.addActionListener(new Frame1_jMenuHelpAbout_ActionAdapter(this));
jTextArea1.setText("");
jMenu1.setText("編輯");
jMenu2.setText("格式");
jMenuItem4.setText("新建");
jMenuItem4.addActionListener(new Frame1_jMenuItem4_actionAdapter(this));
jMenuItem3.setText("打開");
jMenuItem3.addActionListener(new Frame1_jMenuItem3_actionAdapter(this));
jMenuItem2.setText("保存");
jMenuItem2.addActionListener(new Frame1_jMenuItem2_actionAdapter(this));
jMenuItem1.setText("另存為");
jMenuItem1.addActionListener(new Frame1_jMenuItem1_actionAdapter(this));
jMenuItem5.setText("剪切");
jMenuItem5.addActionListener(new Frame1_jMenuItem5_actionAdapter(this));
jMenuItem6.setText("復制");
jMenuItem6.addActionListener(new Frame1_jMenuItem6_actionAdapter(this));
jMenuItem7.setText("粘貼");
jMenuItem7.addActionListener(new Frame1_jMenuItem7_actionAdapter(this));
jMenuItem9.setText("字體");
jMenuItem9.addActionListener(new Frame1_jMenuItem9_actionAdapter(this));
jMenuItem10.setText("前景色");
jMenuItem10.addActionListener(new Frame1_jMenuItem10_actionAdapter(this));
jMenuItem11.setText("背景色");
fontChooser1.setFrame(this);
fontChooser1.setTitle("字體");
jCheckBoxMenuItem1.setText("自動換行");
jCheckBoxMenuItem1.addActionListener(new Frame1_jCheckBoxMenuItem1_actionAdapter(this));
document1.addDocumentListener(new Frame1_document1_documentAdapter(this));
jMenuFile.add(jMenuItem4);
jMenuFile.add(jMenuItem3);
jMenuFile.add(jMenuItem2);
jMenuFile.add(jMenuItem1);
jMenuFile.addSeparator();
jMenuFile.add(jMenuFileExit);
jMenuHelp.add(jMenuHelpAbout);
jMenuBar1.add(jMenuFile);
jMenuBar1.add(jMenu1);
jMenuBar1.add(jMenu2);
jMenuBar1.add(jMenuHelp);
this.setJMenuBar(jMenuBar1);
contentPane.add(statusBar, BorderLayout.SOUTH);
contentPane.add(jScrollPane1, BorderLayout.CENTER);
jScrollPane1.getViewport().add(jTextArea1, null);
jMenu1.add(jMenuItem5);
jMenu1.add(jMenuItem6);
jMenu1.add(jMenuItem7);
jMenu2.add(jCheckBoxMenuItem1);
jMenu2.add(jMenuItem9);
jMenu2.add(jMenuItem10);
jMenu2.add(jMenuItem11);
}
//File | Exit action performed
public void jMenuFileExit_actionPerformed(ActionEvent e) {
if(giveUp())
System.exit(0);
}
//Help | About action performed
public void jMenuHelpAbout_actionPerformed(ActionEvent e) {
Frame1_AboutBox dlg = new Frame1_AboutBox(this);
Dimension dlgSize = dlg.getPreferredSize();
Dimension frmSize = getSize();
Point loc = getLocation();
dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);
dlg.setModal(true);
dlg.pack();
dlg.show();
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
//super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
jMenuFileExit_actionPerformed(null);
}
}

void jMenuItem9_actionPerformed(ActionEvent e) {
fontChooser1.setSelectedFont(jTextArea1.getFont());
if(fontChooser1.showDialog())
jTextArea1.setFont(fontChooser1.getSelectedFont());

this.repaint();
}

void jMenuItem10_actionPerformed(ActionEvent e) {
Color color=JColorChooser.showDialog(this,"前景色",jTextArea1.getForeground());
if(color!=null)
jTextArea1.setForeground(color);

this.repaint();
}

void jCheckBoxMenuItem1_actionPerformed(ActionEvent e) {
jTextArea1.setLineWrap(jCheckBoxMenuItem1.isSelected());
}

void jMenuItem5_actionPerformed(ActionEvent e) {
jTextArea1.cut();
}

void jMenuItem7_actionPerformed(ActionEvent e) {
jTextArea1.paste();
}

void jMenuItem6_actionPerformed(ActionEvent e) {
jTextArea1.();
}

void jMenuItem4_actionPerformed(ActionEvent e) {
if(giveUp()){
jTextArea1.setText("");
currentFileName=null;
motified=false;
}
}

void jMenuItem3_actionPerformed(ActionEvent e) {
if(!giveUp()){
return;
}
if(JFileChooser.APPROVE_OPTION==jFileChooser1.showOpenDialog(this)){
openFile(jFileChooser1.getSelectedFile().getPath());
this.repaint();
}
}

void openFile(String fileName){
try{
File file=new File(fileName);
int size=(int)file.length();
int chars_read=0;

FileReader in=new FileReader(file);
char[] data=new char[size];
while(in.ready()){
chars_read+=in.read(data,chars_read,size-chars_read);
}
jTextArea1.setText(new String(data,0,chars_read));
this.currentFileName=fileName;
this.motified=false;
}
catch(IOException e){
jTextArea1.setText("打開文件"+fileName+"錯");
}
}

boolean saveFile(){
if(currentFileName==null)
return saveAsFile();
try{
FileWriter out=new FileWriter(currentFileName);
String text=jTextArea1.getText();
out.write(text);
out.close();
this.motified=false;
return true;
}
catch(IOException e){
}
return false;
}

boolean saveAsFile(){
if(JFileChooser.APPROVE_OPTION==jFileChooser1.showSaveDialog(this)){
currentFileName=jFileChooser1.getSelectedFile().getPath();
return saveFile();
}else{
return false;
}
}

void jMenuItem2_actionPerformed(ActionEvent e) {
saveFile();
}

void jMenuItem1_actionPerformed(ActionEvent e) {
saveAsFile();
}

void document1_changedUpdate(DocumentEvent e) {
motified=true;
}

void document1_insertUpdate(DocumentEvent e) {
motified=true;
}

void document1_removeUpdate(DocumentEvent e) {
motified=true;
}

boolean giveUp(){
if(!motified)
return true;

int temp=JOptionPane.showConfirmDialog(this,"保存修改嗎?","Text Edit",JOptionPane.YES_NO_CANCEL_OPTION);
switch(temp){
case JOptionPane.YES_OPTION: return saveFile();
case JOptionPane.NO_OPTION: return true;
case JOptionPane.CANCEL_OPTION:
default:
return false;
}
}
}

class Frame1_jMenuFileExit_ActionAdapter implements ActionListener {
Frame1 adaptee;

Frame1_jMenuFileExit_ActionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuFileExit_actionPerformed(e);
}
}

class Frame1_jMenuHelpAbout_ActionAdapter implements ActionListener {
Frame1 adaptee;

Frame1_jMenuHelpAbout_ActionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuHelpAbout_actionPerformed(e);
}
}

class Frame1_jMenuItem9_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;

Frame1_jMenuItem9_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuItem9_actionPerformed(e);
}
}

class Frame1_jMenuItem10_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;

Frame1_jMenuItem10_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuItem10_actionPerformed(e);
}
}

class Frame1_jCheckBoxMenuItem1_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;

Frame1_jCheckBoxMenuItem1_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jCheckBoxMenuItem1_actionPerformed(e);
}
}

class Frame1_jMenuItem5_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;

Frame1_jMenuItem5_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuItem5_actionPerformed(e);
}
}

class Frame1_jMenuItem7_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;

Frame1_jMenuItem7_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuItem7_actionPerformed(e);
}
}

class Frame1_jMenuItem6_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;

Frame1_jMenuItem6_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuItem6_actionPerformed(e);
}
}

class Frame1_jMenuItem4_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;

Frame1_jMenuItem4_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuItem4_actionPerformed(e);
}
}

class Frame1_jMenuItem3_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;

Frame1_jMenuItem3_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuItem3_actionPerformed(e);
}
}

class Frame1_jMenuItem2_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;

Frame1_jMenuItem2_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuItem2_actionPerformed(e);
}
}

class Frame1_jMenuItem1_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;

Frame1_jMenuItem1_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuItem1_actionPerformed(e);
}
}

class Frame1_document1_documentAdapter implements javax.swing.event.DocumentListener {
Frame1 adaptee;

Frame1_document1_documentAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void insertUpdate(DocumentEvent e) {
adaptee.document1_insertUpdate(e);
}
public void removeUpdate(DocumentEvent e) {
adaptee.document1_removeUpdate(e);
}
public void changedUpdate(DocumentEvent e) {
adaptee.document1_changedUpdate(e);
}
}

閱讀全文

與java文本編輯器課程設計相關的資料

熱點內容
電子資料文件有哪些 瀏覽:241
猥瑣貓表情教程 瀏覽:599
android音頻文件格式 瀏覽:458
漫畫臉app哪裡可以下載 瀏覽:959
購買歡樂升級歡樂豆 瀏覽:282
學習智能機器人用什麼編程最好 瀏覽:655
蘋果手機如何管控app 瀏覽:633
mn文件夾 瀏覽:590
安卓平板通用刷機包下載 瀏覽:751
安卓獲取內部存儲路徑 瀏覽:880
寫代碼兩台顯示器 瀏覽:327
unitypackage壓縮文件 瀏覽:493
奕心安卓 瀏覽:563
使用土地的有關證明文件包含哪些 瀏覽:493
數據標注哪裡可以接 瀏覽:482
在家自學編程下什麼學 瀏覽:705
最近很火的app軟體是什麼軟體 瀏覽:862
ai文字工具 瀏覽:157
蘭博玩游戲路徑怎麼選擇正確文件 瀏覽:972
淘寶直通車恢復老版本 瀏覽:510

友情鏈接