11计科 实验十二 记事本制作Word文档格式.docx
- 文档编号:20338461
- 上传时间:2023-01-22
- 格式:DOCX
- 页数:13
- 大小:224.49KB
11计科 实验十二 记事本制作Word文档格式.docx
《11计科 实验十二 记事本制作Word文档格式.docx》由会员分享,可在线阅读,更多相关《11计科 实验十二 记事本制作Word文档格式.docx(13页珍藏版)》请在冰豆网上搜索。
fileMenu.setMnemonic('
F'
);
fileMenu.setText("
文件(F)"
newMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N,java.awt.event.InputEvent.CTRL_MASK));
newMenuItem.setMnemonic('
N'
newMenuItem.setText("
新建(N)"
newMenuItem.addActionListener(newjava.awt.event.ActionListener(){
publicvoidactionPerformed(java.awt.event.ActionEventevt){
newMenuItemActionPerformed(evt);
}
});
fileMenu.add(newMenuItem)
openMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O,java.awt.event.InputEvent.CTRL_MASK));
openMenuItem.setMnemonic('
O'
openMenuItem.setText("
打开(O)"
openMenuItem.addActionListener(newjava.awt.event.ActionListener(){
openMenuItemActionPerformed(evt);
fileMenu.add(openMenuItem);
saveMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S,java.awt.event.InputEvent.CTRL_MASK));
saveMenuItem.setMnemonic('
S'
saveMenuItem.setText("
保存(S)"
saveMenuItem.addActionListener(newjava.awt.event.ActionListener(){
saveMenuItemActionPerformed(evt);
fileMenu.add(saveMenuItem);
fileMenu.add(jSeparator1);
printMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P,java.awt.event.InputEvent.CTRL_MASK));
printMenuItem.setMnemonic('
P'
printMenuItem.setText("
打印(P)"
printMenuItem.setEnabled(false);
fileMenu.add(printMenuItem);
fileMenu.add(jSeparator2);
editMenu.add(copyMenuItem);
pasteMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V,java.awt.event.InputEvent.CTRL_MASK));
pasteMenuItem.setMnemonic('
pasteMenuItem.setText("
粘贴(P)"
pasteMenuItem.addActionListener(newjava.awt.event.ActionListener(){
pasteMenuItemActionPerformed(evt);
editMenu.add(pasteMenuItem);
editMenu.add(searchMenuItem);
searchnextMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F3,0));
searchnextMenuItem.setMnemonic('
searchnextMenuItem.setText("
查找下一个(N)"
searchnextMenuItem.addActionListener(newjava.awt.event.ActionListener(){
searchnextMenuItemActionPerformed(evt);
editMenu.add(searchnextMenuItem);
exchangeMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_H,java.awt.event.InputEvent.CTRL_MASK));
exchangeMenuItem.setMnemonic('
R'
exchangeMenuItem.setText("
替换(R)"
exchangeMenuItem.addActionListener(newjava.awt.event.ActionListener(){
exchangeMenuItemActionPerformed(evt);
editMenu.add(exchangeMenuItem);
editMenu.add(jSeparator5);
selectallMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A,java.awt.event.InputEvent.CTRL_MASK));
selectallMenuItem.setMnemonic('
A'
selectallMenuItem.setText("
全选(A)"
selectallMenuItem.addActionListener(newjava.awt.event.ActionListener(){
selectallMenuItemActionPerformed(evt);
editMenu.add(selectallMenuItem);
formatMenu.add(autodownCheckBoxMenuItem);
fontMenuItem.setMnemonic('
fontMenuItem.setText("
字体(F)"
fontMenuItem.addActionListener(newjava.awt.event.ActionListener(){
fontMenuItemActionPerformed(evt);
formatMenu.add(fontMenuItem);
jMenuBar1.add(formatMenu);
viewMenu.setMnemonic('
V'
viewMenu.setText("
查看(V)"
stateMenuItem.setMnemonic('
stateMenuItem.setText("
状态栏(S)"
stateMenuItem.setEnabled(false);
stateMenuItem.addActionListener(newjava.awt.event.ActionListener(){
stateMenuItemActionPerformed(evt);
viewMenu.add(stateMenuItem);
jMenuBar1.add(viewMenu);
helpMenu.setMnemonic('
H'
helpMenu.setText("
帮助(H)"
helpMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F1,0));
helpMenuItem.setMnemonic('
helpMenuItem.setText("
帮助主题(H)"
helpMenuItem.addActionListener(newjava.awt.event.ActionListener(){
helpMenuItemActionPerformed(evt);
helpMenu.add(helpMenuItem);
helpMenu.add(jSeparator6);
aboutMenuItem.setMnemonic('
aboutMenuItem.setText("
关于(A)"
aboutMenuItem.addActionListener(newjava.awt.event.ActionListener(){
aboutMenuItemActionPerformed(evt);
helpMenu.add(aboutMenuItem);
jMenuBar1.add(helpMenu);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayoutlayout=newjavax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1,javax.swing.GroupLayout.DEFAULT_SIZE,536,Short.MAX_VALUE)
);
pack();
}//<
/editor-fold>
privatevoidopenMenuItemActionPerformed(java.awt.event.ActionEventevt){
//TODOaddyourhandlingcodehere:
openText();
}
privatevoidnewText(){
intselection=JOptionPane.showConfirmDialog(this,
"
是否保存当前文本文档?
"
"
保存提示"
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.WARNING_MESSAGE);
if(selection==JOptionPane.OK_OPTION){
saveText();
mainTextArea.setText("
setTitle("
新建文本文档.txt"
privatevoidopenText(){
try{
Framef=newFrame();
FileDialogfd=newFileDialog(f,"
打开文件"
FileDialog.LOAD);
fd.setVisible(true);
Stringfpath=fd.getDirectory();
finalStringfname=fd.getFile();
BufferedReaderbr=newBufferedReader(newFileReader(fpath+fname));
setTitle(fname);
Strings=br.readLine();
while(s!
=null){
mainTextArea.append(s+"
\n"
s=br.readLine();
br.close();
}catch(Exceptionex){
privatevoidsaveText(){
Stringfns=null;
Framef=newFrame("
保存"
保存文件"
FileDialog.SAVE);
Stringsavepath=fd.getDirectory();
Stringsavename=fd.getFile();
fd.setFile("
*.txt"
if(savename!
PrintWriterpw=newPrintWriter(newBufferedWriter(newFileWriter(savepath+savename)));
pw.write(mainTextArea.getText(),0,mainTextArea.getText().length());
pw.flush();
}catch(Exceptionesave){
privatevoidrepeal(){
undo.undo();
//System.out.println(undo.canUndo());
}catch(Exceptioneundo){
publicvoidsearch(){
finalJDialogjd=newJDialog(this,"
查找"
true);
GridBagLayoutgbl=newGridBagLayout();
GridBagConstraintsgbc=newGridBagConstraints();
JLabeljlFind=newJLabel("
查找内容:
gbc.gridx=0;
gbc.gridy=0;
jd.getContentPane().add(jlFind);
JButtonjbFind=newJButton("
jbFind.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEventefind){
StringstrA=mainTextArea.getText();
StringstrB=jtf.getText();
if(a>
=0){
a=strA.indexOf(strB,StartFindPos);
b=strB.length();
StartFindPos=a+b;
if(a==-1){
JOptionPane.showMessageDialog(null,"
没有您要查找的信息"
查找结果"
1)
a=0;
StartFindPos=0;
mainTextArea.select(a,StartFindPos);
JButtonjbCancel=newJButton("
取消"
jbCancel.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEventejb){
jd.dispose();
privatevoidautodown(){
if(autodownCheckBoxMenuItem.getState()){
mainTextArea.setLineWrap(true);
mainTextArea.setWrapStyleWord(true);
}else{
mainTextArea.setLineWrap(false);
mainTextArea.setWrapStyleWord(false);
privatevoidsetFont(){
字体设置"
jd.setLocation(240,200);
.....{
jtf2.setText((String)jcb2.getSelectedItem());
finalJComboBoxjcb3=newJComboBox();
jcb3.addItem("
14"
)jcb3.addItem("
18"
22"
26"
30"
jcb3.addItem("
34"
jcb3.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvente){
jtf3.setText((String)jcb3.getSelectedItem());
if(jtf2.getText().equals("
PLAIN"
)){
privatevoidexitapp(){
System.exit(0);
publicstaticvoidmain(Stringargs[]){
java.awt.EventQueue.invokeLater(newRunnable(){
publicvoidrun(){
newMain().setVisible(true);
程序运行截图如下:
保存文件:
设置字体:
帮助栏:
新建目录栏;
编辑目录栏;
格式目录栏:
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 11计科 实验十二 记事本制作 11 实验 十二 记事本 制作
![提示](https://static.bdocx.com/images/bang_tan.gif)