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


setResizable (false);
setSize (800, 600);
setLocationRelativeTo (null);
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
setVisible (true);
}
public static void main ( String[] args )
{
SwingUtilities.invokeLater (new Runnable ()
{
@Override
public void run ()
{
new MenuTester ();
}
});
}
@Override
public void actionPerformed ( ActionEvent e )
{
String command = e.getActionCommand ();
if ("新建".equals (command))
{
scrollPane.setVisible (true);
validate ();
}
else if ("关闭".equals (command))
{
scrollPane.setVisible (false);
textArea.setText ("");
validate ();
}
else if ("打开".equals (command))
{
scrollPane.setVisible (true);
validate ();
try
{
FileReader fr = new FileReader (FILE);
char[] cs = new char[1];
while (-1 != ( fr.read (cs) ))
{
textArea.append (new String (cs));
}
fr.close ();
}
catch (Exception e1)
{
e1.printStackTrace ();
}
}
else if ("保存".equals (command))
{
try
{
FileWriter fw = new FileWriter (FILE);
fw.write (textArea.getText ());
fw.flush ();
fw.close ();
}
catch (IOException e1)
{
e1.printStackTrace();
}
}
}
}
求一个用Java编写的文本编辑器代码import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class MyTextEditor extends JFrame implements ActionListener,ItemListener,MouseListener
{
private File file;
private JTextArea textarea;
private JRadioButtonMenuItemrbmi_red,rbmi_blue,rbmi_green;
private JMenuItem menuitem_copy,menuitem_cut,menuitem_paste,menuitem_seek;
private JMenuItem menuitem_song,menuitem_fang,menuitem_kai;//字体变量
private JMenuItem menuitem_normal,menuitem_bold,menuitem_italic;//字形变量
private JMenuItem menuitem_20,menuitem_30,menuitem_40;//字号变量
private JMenuItem menuitem_exit,menuitem_infor;
private JPopupMenu popupmenu;
private JMenuItem menuitem_red,menuitem_green,menuitem_blue;
private JDialog dialog,dialog1;
private JButton button_seek;
private JTextField textfield_seek;
private JLabel label_seek,label_infor;
Stringseek;
public MyTextEditor()
{
super("文本编辑器");
this.setSize(400,300);
this.setLocation(360,300);
this.setDefaultCloseOperation(HIDE_ON_CLOSE);
Container ss=this.getContentPane();
this.textarea = new JTextArea();
JScrollPane dd=new JScrollPane(textarea);
ss.add(dd);
textarea.addMouseListener(this);
this.addMenu();
this.setVisible(true);
this.Dialog();
this.Dialog1();
this.file = null;
}
public MyTextEditor(String filename)
{
this();
if (filename!=null)
{
this.file = new File(filename);
this.setTitle(filename);
this.textarea.setText(this.readFromFile());
}
}
public MyTextEditor(File file)
{
this();
if (file!=null)
{
this.file = file;
this.setTitle(this.file.getName());
this.textarea.setText(this.readFromFile());
}
}
public void Dialog()//建立对话框java文件编辑器的代码的方法
{
dialog=new JDialog(this,"查找",true);
dialog.setLayout(new FlowLayout());
dialog.setSize(200,90);
label_seek=new JLabel("查找内容");
dialog.add(label_seek);
textfield_seek=new JTextField(10);
dialog.add(textfield_seek);
button_seek=new JButton("查找");
dialog.add(button_seek);
button_seek.addActionListener(this);
}
public void Dialog1()

推荐阅读