展开全部
有200多行的代码
package 记事本;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import com.borland.jbcl.layout.PaneLayout;
import com.borland.jbcl.layout.*;
/**
*
Title:
*
*
Description:
*
*
Copyright: Copyright (c) 2006
*
*
Company:
*
* @author not attributable
* @version 1.0
*/
public class NotepadFrame
extends JFrame {
JPanel contentPane;
JMenuBar jMenuBar1 = new JMenuBar();
JMenu jMenuFile = new JMenu();
JMenuItem jMenuFileExit = new JMenuItem();
JMenu jMenuHelp = new JMenu();
JMenuItem jMenuHelpAbout = new JMenuItem();
JMenuItem jMenuFileOpen = new JMenuItem();
JMenuItem jMenuFileSave = new JMenuItem();
JMenuItem jMenuFileNew = new JMenuItem();
JMenu jMenuEdit = new JMenu();
JMenuItem jMenuFileSaveAs = new JMenuItem();
JTextPane jTextPane = new JTextPane();
PaneLayout paneLayout1 = new PaneLayout();
JMenu jMenuFormat = new JMenu();
JMenuItem jMenuFormatFont = new JMenuItem();
JMenuItem jMenuEditUodo = new JMenuItem();
JMenuItem jMenuEditCut = new JMenuItem();
JMenuItem jMenuEditCopy = new JMenuItem();
JMenuItem jMenuEditPaste = new JMenuItem();
JMenuItem jMenuEditDelete = new JMenuItem();
JMenuItem jMenuEditFind = new JMenuItem();
JMenuItem jMenuEditFindNext = new JMenuItem();
JMenuItem jMenuEditReplace = new JMenuItem();
JMenuItem jMenuEditGoto = new JMenuItem();
JMenuItem jMenuEditSelectAll = new JMenuItem();
JMenuItem jMenuEditTimeDate = new JMenuItem();
public NotepadFrame() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
}
catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(paneLayout1);
setSize(new Dimension(400, 300));
setTitle("Frame Title");
jMenuFile.setText("文件");
jMenuFileExit.setText("退出");
jMenuFileExit.addActionListener(new
NotepadFrame_jMenuFileExit_ActionAdapter(this));
jMenuHelp.setText("Help");
jMenuHelpAbout.setText("About");
jMenuHelpAbout.addActionListener(new
NotepadFrame_jMenuHelpAbout_ActionAdapter(this));
jMenuFileOpen.setText("打开");
jMenuFileOpen.addActionListener(new
NotepadFrame_jMenuFileOpen_actionAdapter(this));
jMenuFileSave.setText("保存");
jMenuFileSave.addActionListener(new
NotepadFrame_jMenuFileSave_actionAdapter(this));
jMenuFileNew.setText("新建");
jMenuFileNew.addActionListener(new NotepadFrame_jMenuFileNew_actionAdapter(this));
jMenuEdit.setText("编辑");
jMenuFileSaveAs.setText("另存为");
jMenuFormat.setText("格式");
jMenuFormatFont.setText("字体");
jMenuEditUodo.setEnabled(false);
jMenuEditUodo.setText("撤销");
jMenuEditCut.setEnabled(false);
jMenuEditCut.setText("剪切");
jMenuEditCopy.setEnabled(false);
jMenuEditCopy.setText("复制");
jMenuEditPaste.setText("粘贴");
jMenuEditDelete.setEnabled(false);
jMenuEditDelete.setText("删除e68a84e8a2ad3231313335323631343130323136353331333233656564");
jMenuEditFind.setEnabled(false);
jMenuEditFind.setText("查找");
jMenuEditFindNext.setEnabled(false);
jMenuEditFindNext.setText("查找下一个");
jMenuEditReplace.setText("替换");
jMenuEditGoto.setEnabled(false);
jMenuEditGoto.setText("转到");
jMenuEditSelectAll.setText("全选");
jMenuEditTimeDate.setText("时间/日期");
jMenuBar1.add(jMenuFile);
jMenuFile.add(jMenuFileNew);
jMenuFile.add(jMenuFileOpen);
jMenuFile.addSeparator();
jMenuFile.add(jMenuFileSave);
jMenuFile.add(jMenuFileSaveAs);
jMenuFile.addSeparator();
jMenuFile.add(jMenuFileExit);
jMenuBar1.add(jMenuEdit);
jMenuBar1.add(jMenuFormat);
jMenuBar1.add(jMenuHelp);
jMenuHelp.add(jMenuHelpAbout);
contentPane.add(jTextPane,
new PaneConstraints("jTextPane1", "jTextPane1",
PaneConstraints.ROOT, 1.0F));
jMenuEdit.add(jMenuEditUodo);
jMenuEdit.addSeparator();
jMenuEdit.add(jMenuEditCut);
jMenuEdit.add(jMenuEditCopy);
jMenuEdit.add(jMenuEditPaste);
jMenuEdit.add(jMenuEditDelete);
jMenuEdit.addSeparator();
jMenuEdit.add(jMenuEditFind);
jMenuEdit.add(jMenuEditFindNext);
jMenuEdit.add(jMenuEditReplace);
jMenuEdit.add(jMenuEditGoto);
jMenuEdit.addSeparator();
jMenuEdit.add(jMenuEditSelectAll);
jMenuEdit.add(jMenuEditTimeDate);
jMenuFormat.add(jMenuFormatFont);
setJMenuBar(jMenuBar1);
}
/**
* File | Exit action performed.
*
* @param actionEvent ActionEvent
*/
void jMenuFileExit_actionPerformed(ActionEvent actionEvent) {
System.exit(0);
}
/**
* Help | About action performed.
*
* @param actionEvent ActionEvent
*/
void jMenuHelpAbout_actionPerformed(ActionEvent actionEvent) {
NotepadFrame_AboutBox dlg = new NotepadFrame_AboutBox(this);
Dimension dlgSize = dlg.getPreferredSize();
Dimension frmSize = getSize();
Point loc = getLocation();
dlg.setLocation( (frmSize.width - dlgSize.width) / 2 + loc.x,
(frmSize.height - dlgSize.height) / 2 + loc.y);
dlg.setModal(true);
dlg.pack();
dlg.setVisible(true);
}
public void jMenuFileNew_actionPerformed(ActionEvent e) {
String txtNew=jTextPane.getText();
if(!txtNew.equals("")){
int num=JOptionPane.showConfirmDialog(this,"是否保存","保存",JOptionPane.YES_NO_CANCEL_OPTION);
if(num==0){
JFileChooser saver=new JFileChooser("C:\\Documents and Settings\\163\\My Documents\\");
saver.showSaveDialog(jTextPane);
}
else if(num==1){
jTextPane.setText("");
}
}
}
public void jMenuFileOpen_actionPerformed(ActionEvent e) {
jTextPane.setText("");
JFileChooser opener = new JFileChooser();
opener.showOpenDialog(this);
try{
FileReader filechoosed=new FileReader(opener.getSelectedFile());
BufferedReader rf=new BufferedReader(filechoosed);
String rl=rf.readLine();
while(!rl.equals("")){
jTextPane.setText(jTextPane.getText()+rl+"\n");
rl=rf.readLine();
}
}catch(Exception ex){
System.out.println("error");
}
}
public void jMenuFileSave_actionPerformed(ActionEvent e) {
}
}
class NotepadFrame_jMenuFileNew_actionAdapter
implements ActionListener {
private NotepadFrame adaptee;
NotepadFrame_jMenuFileNew_actionAdapter(NotepadFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuFileNew_actionPerformed(e);
}
}
class NotepadFrame_jMenuFileOpen_actionAdapter
implements ActionListener {
private NotepadFrame adaptee;
NotepadFrame_jMenuFileOpen_actionAdapter(NotepadFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuFileOpen_actionPerformed(e);
}
}
class NotepadFrame_jMenuFileSave_actionAdapter
implements ActionListener {
private NotepadFrame adaptee;
NotepadFrame_jMenuFileSave_actionAdapter(NotepadFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuFileSave_actionPerformed(e);
}
}
class NotepadFrame_jMenuFileExit_ActionAdapter
implements ActionListener {
NotepadFrame adaptee;
NotepadFrame_jMenuFileExit_ActionAdapter(NotepadFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent actionEvent) {
adaptee.jMenuFileExit_actionPerformed(actionEvent);
}
}
class NotepadFrame_jMenuHelpAbout_ActionAdapter
implements ActionListener {
NotepadFrame adaptee;
NotepadFrame_jMenuHelpAbout_ActionAdapter(NotepadFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent actionEvent) {
adaptee.jMenuHelpAbout_actionPerformed(actionEvent);
}
}
已赞过
已踩过<
你对这个回答的评价是?
评论
收起