当前位置:首页 » 编程语言 » 文本编辑器java

文本编辑器java

发布时间: 2022-11-02 17:10:58

java 文本编辑器

不知道你的编辑器控件是不是用的JTextArea,如果是的话,有getSelectionStart()和getSelectedEnd()来获取起始地址和结束地址,至于字数,getSelectedText()得到字符串,就可以得到字数了吧。

运行这段代码:
public class MyText2 extends JFrame {
private JTextArea editorArea;
private JLabel lb_StatusBar;
public MyText2() {
super();

Container container = getContentPane();
editorArea = new JTextArea();
editorArea.setLineWrap(true);
editorArea.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
if(editorArea.getSelectedText() != null){
lb_StatusBar.setText(editorArea.getSelectionStart() + " " + editorArea.getSelectionEnd() + " Length:" + editorArea.getSelectedText().length()); //获取起始位置和结束位置,获取选取的字符串长度
}
}
});
JScrollPane scrollPane = new JScrollPane(editorArea);
container.add(scrollPane);

addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e){
dispose();
}
});
setTitle("MyText");
setSize(600, 400);
setVisible(true);
final JPanel statusBar = new JPanel();
final FlowLayout flowLayout = new FlowLayout();
flowLayout.setAlignment(FlowLayout.LEFT);
statusBar.setLayout(flowLayout);
getContentPane().add(statusBar, BorderLayout.SOUTH);
lb_StatusBar = new JLabel();
lb_StatusBar.setText("");
statusBar.add(lb_StatusBar);
}
public static void main(String args[]) {
MyText2 app = new MyText2();
}
}

㈡ java文本编辑器FileEditor

importjava.awt.*;
importjava.awt.event.*;
importjavax.swing.*;
importjava.io.*;


{
privateMenuBarmenubar=newMenuBar();
privateMenufilemenu=newMenu("文件");
privateMenueditmenu=newMenu("编辑");
privateMenuformmenu=newMenu("格式");
privateMenuItem[]itemf=newMenuItem[4];
privateMenuItem[]iteme=newMenuItem[6];
privateMenuItem[]items=newMenuItem[2];
privateTextAreatf=newTextArea();

publicinta=0,b=0,c=0,style=Font.PLAIN,size=15;
publicStrings1="red:"+a+""+"green:"+b+""+"blue"+c,
s2="宋体";

public

㈢ 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中编写文本编辑器

你想要的是这种东西吗

㈥ java课程设计:文本编辑器

网上很多伙计

㈦ 怎样用文本编辑器来运行java程序

推荐:Scite编辑器
google上面搜一个“Scite”,或者直接上官方网站http://www.scintilla.org/SciTE.html下一个,这个编辑器自带控制台的,环境变量设置好就可以编译运行(和默认设置环境变量一样)

㈧ 如何用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文本编辑器

留个邮箱,发给你。因为还有图标图片。

㈩ java语言写一个文本编辑器的源代码

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.util.*; //Date needed
import java.io.PrintWriter;
public class NotePad extends JFrame
{
JTextArea jta;
class newl implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
jta.setText("");
}
}

class openl implements ActionListener
{ public void actionPerformed(ActionEvent e)
{
JFileChooser jf=new JFileChooser();
jf.showOpenDialog(NotePad.this);

}

}
//保存文件的监听
class savel implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JFileChooser jf = new JFileChooser();
jf.showSaveDialog(NotePad.this);

}
}
//打印的监听 ?
class printl implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
// PrintWriter p = new PrintWriter(NotePad.this);
}
}
//退出记事本的监听
class exitl implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);//退出
}
}

//拷贝的监听
class l implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
jta.();
}
}

//粘贴的监听
class pastel implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
jta.paste();
}
}
//剪切的监听
class cutl implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
jta.cut();
}
}
//查找的监听

//添加日期的监听
class datel implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Date d=new Date();
jta.append(d.toString());
}
}

//构造函数
public NotePad()
{
jta=new JTextArea("",24,40);
JScrollPane jsp=new JScrollPane(jta);
JMenuBar jmb=new JMenuBar();
JMenu mFile=new JMenu("File");
JMenu mEdit=new JMenu("Edit");

JMenuItem mNew=new JMenuItem("New",KeyEvent.VK_N);
mNew.addActionListener(new newl());
mFile.add(mNew);

JMenuItem mOpen=new JMenuItem("Open",KeyEvent.VK_O);
mOpen.addActionListener(new openl());
mFile.add(mOpen);

JMenuItem mSave=new JMenuItem("Save");
mSave.addActionListener(new savel());
mFile.add(mSave);

mFile.addSeparator(); //添加分割线

JMenuItem mPrint = new JMenuItem("Print");
mPrint.addActionListener(new printl());
mFile.add(mPrint);

mFile.addSeparator(); //添加分割线

JMenuItem mExit=new JMenuItem("Exit");
mExit.addActionListener(new exitl());
mFile.add(mExit);
mFile.setMnemonic(KeyEvent.VK_F);

//编辑菜单的子菜单的处理
JMenuItem jmi;
jmi=new JMenuItem("Copy");
jmi.addActionListener(new l());
mEdit.add(jmi);

jmi=new JMenuItem("Cut");
jmi.addActionListener(new cutl());
mEdit.add(jmi);

jmi=new JMenuItem("Paste");
jmi.addActionListener(new pastel());
mEdit.add(jmi);

mEdit.addSeparator(); //添加分割线

jmi=new JMenuItem("Find");

mEdit.add(jmi);

jmi=new JMenuItem("FindNext");
mEdit.add(jmi);
mEdit.addSeparator();
jmi=new JMenuItem("Select All");
mEdit.add(jmi);
jmi=new JMenuItem("Date/Time");
jmi.addActionListener(new datel());
mEdit.add(jmi);

jmb.add(mFile);
jmb.add(mEdit);

this.setJMenuBar(jmb);

this.getContentPane().add(jsp);
this.setSize(200,200);
this.setVisible(true);
}
//主函数,程序入口点
public static void main(String s[])
{
new NotePad();
}

}

热点内容
python安装后怎么打开 发布:2025-01-10 11:08:35 浏览:870
phpjava架构 发布:2025-01-10 10:56:06 浏览:383
python二维排序 发布:2025-01-10 10:56:00 浏览:607
南水北调怎么配置 发布:2025-01-10 10:55:27 浏览:121
广数980系统参数密码是多少 发布:2025-01-10 10:55:25 浏览:577
androidhtml字体 发布:2025-01-10 10:55:01 浏览:787
数据库连接工厂模式 发布:2025-01-10 10:51:00 浏览:487
mac文件夹路径设置 发布:2025-01-10 10:48:12 浏览:803
shell脚本自动密码 发布:2025-01-10 10:46:29 浏览:766
安卓手机怎么切两个屏 发布:2025-01-10 10:33:51 浏览:684