java记事本.docx

上传人:b****1 文档编号:10685622 上传时间:2023-05-27 格式:DOCX 页数:19 大小:67.35KB
下载 相关 举报
java记事本.docx_第1页
第1页 / 共19页
java记事本.docx_第2页
第2页 / 共19页
java记事本.docx_第3页
第3页 / 共19页
java记事本.docx_第4页
第4页 / 共19页
java记事本.docx_第5页
第5页 / 共19页
java记事本.docx_第6页
第6页 / 共19页
java记事本.docx_第7页
第7页 / 共19页
java记事本.docx_第8页
第8页 / 共19页
java记事本.docx_第9页
第9页 / 共19页
java记事本.docx_第10页
第10页 / 共19页
java记事本.docx_第11页
第11页 / 共19页
java记事本.docx_第12页
第12页 / 共19页
java记事本.docx_第13页
第13页 / 共19页
java记事本.docx_第14页
第14页 / 共19页
java记事本.docx_第15页
第15页 / 共19页
java记事本.docx_第16页
第16页 / 共19页
java记事本.docx_第17页
第17页 / 共19页
java记事本.docx_第18页
第18页 / 共19页
java记事本.docx_第19页
第19页 / 共19页
亲,该文档总共19页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

java记事本.docx

《java记事本.docx》由会员分享,可在线阅读,更多相关《java记事本.docx(19页珍藏版)》请在冰点文库上搜索。

java记事本.docx

java记事本

java记事本

界面展示:

代码:

packagecn.hlbrc.jsb;

importjavax.swing.SwingUtilities;

importjava.awt.BorderLayout;

importjavax.swing.JPanel;

importjavax.swing.JFrame;

importjava.awt.Dimension;

importjava.awt.event.ActionEvent;

importjava.awt.event.ActionListener;

importjavax.swing.JFileChooser;

importjavax.swing.JMenuBar;

importjavax.swing.JMenu;

importjavax.swing.JMenuItem;

importjavax.swing.JOptionPane;

importjavax.swing.JTextArea;

importjavax.swing.JTextField;

importjavax.swing.KeyStroke;

//importjavax.xml.crypto.Date;

importjava.awt.Rectangle;

importjava.awt.event.InputEvent;

importjava.awt.event.KeyEvent;

importjava.awt.Color;

importjava.awt.Font;

importjava.io.BufferedWriter;

importjava.io.File;

importjava.io.FileNotFoundException;

importjava.io.FileReader;

importjava.io.FileWriter;

importjava.io.IOException;

publicclassjsbextendsJFrame{

privatestaticfinallongserialVersionUID=1L;

privateJPaneljContentPane=null;

privateJMenuBarjJMenuBar=null;

privateJMenum1=null;

privateJMenum2=null;

privateJMenum3=null;

privateJMenum4=null;

privateJMenuItemt1=null;

privateJMenuItemt2=null;

privateJMenuItemt3=null;

privateJMenuItemt4=null;

privateJMenuItemt5=null;

privateJMenuItemt6=null;

privateJMenuItemt7=null;

privateJMenuItemt8=null;

privateJMenuItemt9=null;

privateJMenuItemt10=null;

privateJMenuItemt11=null;

Stringstr;

privateJMenuItemjMenuItem=null;

privateJMenuItemt12=null;

privateJMenuItemt13=null;

privateJMenuItemt14=null;

privateJMenuItemt15=null;

privateJTextAreatf1=null;

FileReaderfr;

booleanflag=false;

/**

*ThismethodinitializesjJMenuBar

*

*@returnjavax.swing.JMenuBar

*/

privateJMenuBargetJJMenuBar(){

if(jJMenuBar==null){

jJMenuBar=newJMenuBar();

jJMenuBar.add(getM1());

jJMenuBar.add(getM2());

jJMenuBar.add(getM3());

jJMenuBar.add(getM4());

}

returnjJMenuBar;

}

/**

*Thismethodinitializesm1

*@return

*

*@returnjavax.swing.JMenu

*/

privateJMenugetM1(){

if(m1==null){

m1=newJMenu();

m1.setText("文件");

m1.add(getT1());

m1.add(getT2());

m1.add(getT3());

m1.add(getT4());

}

returnm1;

}

privateJMenugetM2(){

if(m2==null){

m2=newJMenu();

m2.setText("编辑");

m2.add(getT5());

m2.add(getT6());

m2.add(getT7());

m2.add(getT8());

m2.add(getT9());

m2.add(getT10());

m2.add(getT11());

}

returnm2;

}

privateJMenugetM3(){

if(m3==null){

m3=newJMenu();

m3.setText("格式");

m3.add(getT12());

m3.add(getT13());

}

returnm3;

}

privateJMenugetM4(){

if(m4==null){

m4=newJMenu();

m4.setText("系统");

m4.add(getJMenuItem());

m4.add(getT14());

m4.add(getT15());

}

returnm4;

}

/**

*Thismethodinitializest1

*

*@returnjavax.swing.JMenuItem

*/

privateJMenuItemgetT1(){

if(t1==null){

t1=newJMenuItem();

t1.setText("新建");

t1.addActionListener(newjava.awt.event.ActionListener(){

publicvoidactionPerformed(java.awt.event.ActionEvente){

if(!

tf1.getText().equals(""))

if(JOptionPane.showConfirmDialog(null,

"是否保存文件内容","保存文件",JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION){

JFileChooserjf=newJFileChooser();

jf.showSaveDialog(jsb.this);

tf1.setText("");

}

}

});

}

returnt1;

}

/**

*Thismethodinitializest2

*

*@returnjavax.swing.JMenuItem

*/

privateJMenuItemgetT2(){

if(t2==null){

t2=newJMenuItem();

t2.setText("打开");

t2.addActionListener(newjava.awt.event.ActionListener(){

publicvoidactionPerformed(java.awt.event.ActionEvente){

JFileChooserjf=newJFileChooser();

jf.showOpenDialog(jsb.this);

Filef=jf.getSelectedFile();

try{

fr=newFileReader(f);

}catch(FileNotFoundExceptione1){

//TODO自动生成catch块

e1.printStackTrace();

}

intdata;

Stringstr=newString();

try{

while((data=fr.read())!

=-1)

str=str+(char)data;

}catch(IOExceptione1){

//TODO自动生成catch块

e1.printStackTrace();

}

tf1.setText(str);

}

});

}

returnt2;

}

/**

*Thismethodinitializest3

*

*@returnjavax.swing.JMenuItem

*/

privateJMenuItemgetT3(){

if(t3==null){

t3=newJMenuItem();

t3.setText("保存");

t3.addActionListener(newjava.awt.event.ActionListener(){

publicvoidactionPerformed(java.awt.event.ActionEvente){

JFileChooserjf=newJFileChooser();

jf.showSaveDialog(jsb.this);

Filef=jf.getSelectedFile();

}

});

}

returnt3;

}

/**

*Thismethodinitializest4

*

*@returnjavax.swing.JMenuItem

*/

privateJMenuItemgetT4(){

if(t4==null){

t4=newJMenuItem();

t4.setText("另存为");

t4.addActionListener(newjava.awt.event.ActionListener(){

publicvoidactionPerformed(java.awt.event.ActionEvente){

JFileChooserjf=newJFileChooser();

jf.showSaveDialog(jsb.this);

}

});

}

returnt4;

}

/**

*Thismethodinitializesj1

*

*@returnjavax.swing.JTextArea

*/

/**

*Thismethodinitializesm2

*

*@returnjavax.swing.JMenu

*/

/**

*Thismethodinitializest5

*

*@returnjavax.swing.JMenuItem

*/

privateJMenuItemgetT5(){

if(t5==null){

t5=newJMenuItem();

t5.setText("复制");

t5.addActionListener(newjava.awt.event.ActionListener(){

publicvoidactionPerformed(java.awt.event.ActionEvente){

str=tf1.getSelectedText();

t5.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,

InputEvent.CTRL_MASK));

}

});

}

returnt5;

}

/**

*Thismethodinitializest6

*

*@returnjavax.swing.JMenuItem

*/

privateJMenuItemgetT6(){

if(t6==null){

t6=newJMenuItem();

t6.setText("贴粘");

t6.addActionListener(newjava.awt.event.ActionListener(){

publicvoidactionPerformed(java.awt.event.ActionEvente){

tf1.setText(tf1.getText()+str);

//tf1.get

t6.setAccelerator(

KeyStroke.getKeyStroke(KeyEvent.VK_V,

InputEvent.CTRL_MASK));

}

});

}

returnt6;

}

/**

*Thismethodinitializest7

*

*@returnjavax.swing.JMenuItem

*/

privateJMenuItemgetT7(){

if(t7==null){

t7=newJMenuItem();

t7.setText("剪切");

t7.addActionListener(newjava.awt.event.ActionListener(){

publicvoidactionPerformed(java.awt.event.ActionEvente){

t7.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,

InputEvent.CTRL_MASK));

str=tf1.getSelectedText();

tf1.replaceSelection("");//从text中删除被选取文本

}

});

}

returnt7;

}

/**

*Thismethodinitializest8

*

*@returnjavax.swing.JMenuItem

*/

privateJMenuItemgetT8(){

if(t8==null){

t8=newJMenuItem();

t8.setText("删除");

}

returnt8;

}

/**

*Thismethodinitializest9

*

*@returnjavax.swing.JMenuItem

*/

privateJMenuItemgetT9(){

if(t9==null){

t9=newJMenuItem();

t9.setText("全选");

}

returnt9;

}

/**

*Thismethodinitializest10

*

*@returnjavax.swing.JMenuItem

*/

privateJMenuItemgetT10(){

if(t10==null){

t10=newJMenuItem();

t10.setText("查找");

}

returnt10;

}

/**

*Thismethodinitializest11

*

*@returnjavax.swing.JMenuItem

*/

privateJMenuItemgetT11(){

if(t11==null){

t11=newJMenuItem();

t11.setText("替换");

}

returnt11;

}

/**

*Thismethodinitializesm3

*

*@returnjavax.swing.JMenu

*/

/**

*Thismethodinitializesm4

*

*@returnjavax.swing.JMenu

*/

/**

*ThismethodinitializesjMenuItem

*

*@returnjavax.swing.JMenuItem

*/

privateJMenuItemgetJMenuItem(){

if(jMenuItem==null){

jMenuItem=newJMenuItem();

}

returnjMenuItem;

}

/**

*Thismethodinitializest12

*

*@returnjavax.swing.JMenuItem

*/

privateJMenuItemgetT12(){

if(t12==null){

t12=newJMenuItem();

t12.setText("颜色");

}

returnt12;

}

/**

*Thismethodinitializest13

*

*@returnjavax.swing.JMenuItem

*/

privateJMenuItemgetT13(){

if(t13==null){

t13=newJMenuItem();

t13.setText("字体");

}

returnt13;

}

/**

*Thismethodinitializest14

*

*@returnjavax.swing.JMenuItem

*/

privateJMenuItemgetT14(){

if(t14==null){

t14=newJMenuItem();

}

returnt14;

}

/**

*Thismethodinitializest15

*

*@returnjavax.swing.JMenuItem

*/

privateJMenuItemgetT15(){

if(t15==null){

t15=newJMenuItem();

t15.setText("退出");

t15.addActionListener(newjava.awt.event.ActionListener(){

publicvoidactionPerformed(java.awt.event.ActionEvente){

System.exit(0);//退出

}

});

}

returnt15;

}

/**

*Thismethodinitializestf1

*

*@returnjavax.swing.JTextArea

*/

privateJTextAreagetTf1(){

if(tf1==null){

tf1=newJTextArea();

tf1.setAutoscrolls(true);

}

returntf1;

}

/**

*@paramargs

*/

publicstaticvoidmain(String[]args){

//TODO自动生成方法存根

SwingUtilities.invokeLater(newRunnable(){

publicvoidrun(){

jsbthisClass=newjsb();

thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

thisClass.setVisible(true);

}

});

}

/**

*Thisisthedefaultconstructor

*/

publicjsb(){

super();

initialize();

}

/**

*Thismethodinitializesthis

*

*@returnvoid

*/

privatevoidinitialize(){

this.setSize(477,295);

this.setJMenuBar(getJJMenuBar()

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 工程科技 > 建筑土木

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2