文本編輯器java
㈠ 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();
}
}