java課程設計文本編輯器
Ⅰ 如何用Java編寫文本編輯器
package myclass;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import com.sun.tools.hat.internal.parser.Reader;
public class MyTxt extends JFrame implements ActionListener
{
JTextArea ta;
JMenuItem open,save,myexit,open1,save1;
JMenuItem ,palse;
JMenuBar mb;
JPopupMenu popm;
JScrollPane sp;
public void createmenu()
{
mb=new JMenuBar();
JMenu m1=new JMenu("文件");
JMenu m2=new JMenu("編輯");
JMenu m3=new JMenu("字體");
mb.add(m1);mb.add(m2);m2.add(m3);
open=new JMenuItem("打開");
//ImageIcon ii = new ImageIcon("a.gif");
//open.setIcon(new ImageIcon("b.gif"));
open.addActionListener(this);
save=new JMenuItem("保存");
save.addActionListener(this);
myexit=new JMenuItem("退出");
myexit.addActionListener(this);
m1.add(open);m1.add(save);m1.add(myexit);
=new JMenuItem("復制");
palse=new JMenuItem("粘貼");
m2.add();m2.add(palse);
popm=new JPopupMenu ();
open1=new JMenuItem("打開");
open1.addActionListener(this);
save1=new JMenuItem("保存");
save1.addActionListener(this);
popm.add(open1);popm.add(save1);
ta.add(popm);
ta.addMouseListener(new MyMouseEvent(this));
}
class MyMouseEvent extends MouseAdapter
{
MyTxt myparentFrame;
MyMouseEvent ( MyTxt m)
{
myparentFrame=m;
}
public void mouseReleased(MouseEvent e)
{
if(e.isPopupTrigger())
myparentFrame.popm.show((Component)e.getSource(),e.getX(),e.getY()); }
}
public MyTxt ()
{
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
dispose();
System.exit(0);
}
});
ta=new JTextArea(10,30);
add(ta,BorderLayout.CENTER);
Panel p1=new Panel();
add(p1,BorderLayout.SOUTH);
setVisible(true);
setSize(500,500);
//pack();
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();//獲取屏幕大小
int w = getSize().width;
int h = getSize().height;
int x = (dim.width-w)/2;
int y = (dim.height-h)/2;
setLocation(x,y);
createmenu();
setJMenuBar(mb);
sp = new JScrollPane(ta);
getContentPane().add(sp);
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand()=="打開")
try
{
openfile();
}
catch(IOException ex){}
if(e.getActionCommand()=="保存")
{
try {
savefile();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
if(e.getActionCommand()=="退出")
{
dispose();
System.exit(0);
}
}
public void savefile() throws IOException
{
FileDialog fd=new FileDialog(this,"保存",FileDialog.SAVE);
fd.setVisible(true);
FileWriter fw=new FileWriter( fd.getDirectory()+fd.getFile());
for(int i=0;i<ta.getText().length();i++)
{
fw.write(ta.getText().charAt(i));
}
fw.close();
}
public void openfile() throws IOException
{
FileDialog fd=new FileDialog(this,"打開",FileDialog.LOAD);
fd.setVisible(true);
FileReader fr=new FileReader( fd.getDirectory()+fd.getFile());
int n=0;
int row=10;
while((n=fr.read())!=-1)
{
ta.append(""+(char)n);
row--;
if(row==0)
{
ta.append("\n");
row=20;
}
}
fr.close();
}
public static void main(String []args)
{
MyTxt tw=new MyTxt();
}
}
Ⅱ 麻煩高手推薦幾款比較適合初學者編寫JAVA程序的文本編輯器
notepad++ //一個支持多種語言的文本編輯器,帶有代碼提示、語法高亮功能!
editplus //支持Java語言。有語法高亮功能。沒有代碼提示!
ultraedit //同editplus
Ⅲ 在Java中編寫文本編輯器
http://www.pudn.com/downloads40/sourcecode/mobile/j2me/detail140240.html
Ⅳ 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編寫一個簡單的文本編輯器
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();
}
}
Ⅷ 用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();
}
}
Ⅸ 用java設計一個 文本編輯器
1.1 可以用列表 將程序中的函數列出-----這個好做,JList,JTable,JLabel等都可回以。
1.2 點擊列表項 可以還原答到程序的相關行----什麼意思?
2.1 新建函數時 可以彈出對話框 用以輸入函數名和函數體-----這也好做,前者用JTextfield,後者就看你是函數意義了。
2.2 並在程序中自動生成代碼----什麼代碼?好像和1.2同,意義不清。
你這里的函數的概念是什麼?都包括什麼符號?多變數?微積分?泛涵?
總要有各定域才好。你的應用對象是中學生?大學生?還是財會人員?
要對這里的函數有個明確表示,不然輸入函數體的時候會有很多 exception的。
當然如果是編程的函數的概念就好辦了。只需要動態編譯所輸入的代碼,看能否過就好。
但話又說回來,面向對象的編程,就java來說重載,復用,還有繼承,抽象,這個涵數和其他的關系如何考慮啊?
能說說問題的出處?目的?需求?。。。。。。
謝謝。