java文件编辑器的代码 java文件编辑器的代码有哪些( 二 )


{
Date d=new Date();
jta.append(d.toString());
}
}
//构造函数
public NotePad()
{
jta=new JTextArea("",24,40);
JScrollPane jsp=new JScrollPane(jta);
JMenuBar jmb=new JMenuBar();
JMenumFile=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 copyl());
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=newJMenuItem("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.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
public class MenuTester extends JFrame implements ActionListener
{
private static final long serialVersionUID = 1L;
private static final String FILE = "d:/1.txt";
JTextArea textArea;
JScrollPane scrollPane;
public MenuTester ()
{
setTitle ("MenuTester");
setLayout (new BorderLayout ());
JMenuBar menuBar = new JMenuBar ();
JMenu[] menu = new JMenu[] { new JMenu ("文件"), new JMenu ("编辑") };
JMenuItem[] menuItem1 = new JMenuItem[] { new JMenuItem ("新建"), new JMenuItem ("打开"), new JMenuItem ("保存"), new JMenuItem ("关闭") };
JMenuItem[] menuItem2 = new JMenuItem[] { new JMenuItem ("复制"), new JMenuItem ("粘贴"), new JMenuItem ("剪切") };
for ( int i = 0; imenu.length; i++ )
{
menuBar.add (menu[i]);
}
for ( int i = 0; imenuItem1.length; i++ )
{
menu[0].add (menuItem1[i]);
}
for ( int i = 0; imenuItem2.length; i++ )
{
menu[1].add (menuItem2[i]);
}
menuItem1[0].addActionListener (this);
menuItem1[1].addActionListener (this);
menuItem1[2].addActionListener (this);
menuItem1[3].addActionListener (this);
setJMenuBar (menuBar);
textArea = new JTextArea ();
scrollPane = new JScrollPane (textArea);
scrollPane.setVisible (false);
add (scrollPane, BorderLayout.CENTER);

推荐阅读