《Java》課程設(shè)計(jì)記事本_第1頁(yè)
《Java》課程設(shè)計(jì)記事本_第2頁(yè)
《Java》課程設(shè)計(jì)記事本_第3頁(yè)
《Java》課程設(shè)計(jì)記事本_第4頁(yè)
《Java》課程設(shè)計(jì)記事本_第5頁(yè)
已閱讀5頁(yè),還剩23頁(yè)未讀 繼續(xù)免費(fèi)閱讀

付費(fèi)下載

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

《Java課程設(shè)計(jì)》記事本

課程設(shè)計(jì)報(bào)告書目錄

一、設(shè)計(jì)課題

二、設(shè)計(jì)目的

三、操作環(huán)境

四、設(shè)計(jì)場(chǎng)所(機(jī)房號(hào)、機(jī)器號(hào)或自己機(jī)器)

五、設(shè)計(jì)過(guò)程(設(shè)計(jì)內(nèi)容及主要程序模塊)

六、本次設(shè)計(jì)中用到的課程知識(shí)點(diǎn)(列出主要知識(shí)點(diǎn))

七、設(shè)計(jì)過(guò)程中遇到的問(wèn)題及解決辦法

八、程序清單

一、設(shè)計(jì)課題及內(nèi)容

課題名稱:記事本

(1)內(nèi)容:文件菜單中包括新建、打開、保存、另存為、退出等菜單

項(xiàng),其中新建菜單項(xiàng)可以新建一個(gè)記事本程序;打開菜單項(xiàng)可以

打開一個(gè)用戶指定的文本文件,并將其內(nèi)容顯示在記事本的文本

區(qū)域;保存和另存為菜單項(xiàng)可分別實(shí)現(xiàn)文件的保存和另存為

(2)編輯菜單主要包括復(fù)制、剪切和粘貼等菜單項(xiàng),可分別實(shí)現(xiàn)編輯

區(qū)文本內(nèi)容的編輯操作

(3)幫助菜單主要是現(xiàn)實(shí)軟件版本等信息

(4)記事本還實(shí)現(xiàn)了點(diǎn)右鍵彈出快捷菜單功能,加快文檔的編輯效率

(5)記事本文本區(qū)引入滾動(dòng)窗格,實(shí)現(xiàn)編輯區(qū)的滾動(dòng)查看

(6)可自行擴(kuò)充其功能:比如加入格式菜單設(shè)置文本的字體等、編輯

菜單中加入查找、替換等菜單項(xiàng)

二、設(shè)計(jì)目的

熟悉java,awt,java,math,java,swing等包中的組件。

掌握?qǐng)D形界面設(shè)計(jì)方法。

掌握窗體按鈕和文本控件對(duì)事件的響應(yīng)。

/解java自帶的函數(shù)方法。

三、操作環(huán)境

操作系統(tǒng):MicrosoftWindows10

CPU:IntelCorei5-8300H2.30GHz

內(nèi)存:8.00GB

四、設(shè)計(jì)場(chǎng)所

教室b403

五、設(shè)計(jì)過(guò)程(設(shè)計(jì)內(nèi)容及主要模塊,不少于3000字)

1.設(shè)計(jì)要求

1)界面設(shè)計(jì)

2)功能實(shí)現(xiàn)

(1)文件菜單:新建、打開、保存、另存為、退出等。

(2)其中新建菜單項(xiàng)可以新建一個(gè)記事本程序;打訐菜單項(xiàng)可以打開一個(gè)用戶

指定的文本文件,并將其內(nèi)容顯示在記事本的文本區(qū)域;保存和另存為菜單項(xiàng)可分

別實(shí)現(xiàn)文件的保存和另存為

3)編輯菜單:復(fù)制、剪切和粘貼等

4)幫助菜單:軟件版本信

5)右鍵彈出快捷菜單

2.總體設(shè)計(jì)

1)功能模塊圖:

記事本右鍵快捷

幫助

關(guān)

2)功能描述

1、打開記事本。首先是標(biāo)準(zhǔn)型的記事本,擁有文件、編輯。格式和幫助。

如圖1所示:

囹記事本程序□x

文信繳他餐式wm

圖1標(biāo)準(zhǔn)型記事本界面

2、在標(biāo)準(zhǔn)型的記事本界面中,進(jìn)行的新建一個(gè)本件名字叫新記事本。如圖2

閨記事本程序□X

文件ffili格式技購(gòu)

圖2新建記事本功能

3、用打開文件打開剛剛新建的新記事本。如圖三所示。

閨記郭搐序□x

文件ffili格式技購(gòu)

圖3一打開文件

4、點(diǎn)擊退出即可退出,如圖4所示:

1*1記卡本程序-□X

文件靖《修式加助

打開9)

ttft(S)

另存為。

退比(W)S1W

圖4一退出記事本

5、點(diǎn)擊幫助可以看到有關(guān)記事本的相關(guān)信息,其中有作者名、版本、許可條款、

隱私聲明等必要信息。如圖5所示:

圖5一幫助相關(guān)信息

6、右鍵可實(shí)現(xiàn)復(fù)制、粘貼、剪切、清除等常用功能,方便用戶可以快捷方便的

使用記事本。如圖6所示:

⑷記?本卷序□x

文件wa格式&際

?M(a

魂靜網(wǎng)

全咕聞

8W)

?a(m

圖6一右鍵功能

7、編輯也可實(shí)現(xiàn)制、把貼、剪切、清除等常用功能,方便用戶選擇自己適合的

方式,自由選擇方使的快捷方式使用。如圖7:

匕,記事本程中-□X

文件峭偏格式器助

HM(C)J

站財(cái)(V)V

Mffl(X)”x

清除(D)WO

全話網(wǎng)

tttt(R)

圖7一編輯

3.詳細(xì)設(shè)計(jì)

1)流程圖如下:

打開程序

新建記事本

相應(yīng)的Java類有:

Notebook類:主類,添加一些記事本需要的的一些方法,對(duì)繼承類的一些組件進(jìn)行實(shí)

體化,為每個(gè)按鈕創(chuàng)建“這是什么”的幫助信息,按右鍵的時(shí)候觸發(fā)什么,輸出相應(yīng)

的幫助信息,每件事件進(jìn)行監(jiān)聽(tīng),引用的的軟件包和部分代碼如下:

importjava.io.*;

importjava.awt.event.*;

importjava.awt.

importjavax.swing.*;

importjava,swing.*;

〃功能:提供一組“輕量級(jí)”(所有Java語(yǔ)言)組件,盡可能最大程度地在所有平臺(tái)

上工作。

importjavax.swing.JFrame;

〃功能:構(gòu)造一個(gè)初始時(shí)不可見(jiàn)的新窗體。

importjavax.swing.JPanel;

〃功能:創(chuàng)建具有雙緩沖和流右局的新JPanel。

importjavax.swing.JLabel;

〃功能:用于短文本字符串或圖像或二者的顯示區(qū)。

importjavax.swing.JButton;

//功能:創(chuàng)建不帶有設(shè)置文本或圖標(biāo)的按鈕。

importjavax.swing.JTcxtField;

//功能:是一個(gè)輕量級(jí)組件,它允許編輯單行文本。

publicclassNotebook

(

JButtonb_save,b_close;〃按鈕

JTextAreatextArea;〃文本框

FiletempFile;〃文件

JPaneljp;〃面板

JLabelstateBar;〃標(biāo)簽

3Labeljl,jj;

textArea=new3TextArea();

Filef=jfc.getSelectedFileO;

FileReaderfr=newFileReader(f);

fr.read(ch);

Stringstr=newString(ch);

textArea.setText(str);

tempFile=f;

Filef=jfc.getSelectedFileO;〃如果沒(méi)有選取文件,下面的

jfc.getName(f)將會(huì)返回輸入的文件名

fname=jfc.getName(f);

)

importjava.awt.event.*;

〃功能:提供處理由AWT組件所激發(fā)的各類事件的接口和類。

importjava.awt.event.ActionListener;

〃功能:用于接收操作事件的偵聽(tīng)器接口。

importjava.awt.event.KeyListener;

〃功能:〃功能:用于接收鍵盤事件(擊鍵)的偵聽(tīng)器接口

importjava.awt.event.MouseMotionListener;

〃功能:用于接收組件上的鼠標(biāo)移動(dòng)事件的偵聽(tīng)器接口。

importjava.awt.event.WindowListener;

〃功能:用于接收窗口事件的偵聽(tīng)器接口。

importjava.awt.event.TextListcner;

〃功能:用于接收文本事件的偵聽(tīng)器接口。

importjava.awt.event.ItemListener

〃功能:接收項(xiàng)事件的偵聽(tīng)器接=1。

〃編輯區(qū)鼠標(biāo)事件,點(diǎn)擊右鍵彈出“編輯”菜單

textArea.addMouseListener(newMouseAdapter()

{

publicvoidmouseReleased(MouseEvente){

if(e.getButton()==MouseEvent.BUTTONS')

popUpMenu.show(e.getComponent(),e.getX(),e.getY());

)〃e.getComponent。和textArea具有同等效果

publicvoidmouseClicked(MouseEvente){

if(e.getButton()==MouseEvent.BUTTON1)

popUpMenu.setvisible(false);

)

//為窗口添加“關(guān)閉”事件的響應(yīng)

this.addWindowListener(newWindowAdapter()

{

publicvoidwindowclosing(WindowEvente)

{

whenExit();

)

});

〃響應(yīng)菜單項(xiàng)"新建”的事件

publicvoidactionPerformed(ActionEvente)

{

if(e.getSource()==f_new)

{

saveFileDialog();

return;

)

〃響應(yīng)菜單項(xiàng)"打開”的事件

if(e.getSource()==f_open){

openFileDialog();}

〃響應(yīng)菜單項(xiàng)“保存”和“按鈕”保存”的事件

if((e.getSource()==b_save)||(e.getSource()==f_save))

{

try(

Stringstr=textArea.getText();

FileWriter-fw=newFileWriter(tempFile);

fw.write(str);

fw.close();

//isCurrentFileExists=true;

tempFile=tempFile;}

catch(Exceptionex){

ex.printStackTrace();

})

〃響應(yīng)菜單"另存為"的事件

if(e.getSource()==f_saveas){

intoption=jfc.showDialog(this,"另存為”);

Stringfname=null;

if(option==3Fi.leChooser.APPROVE_OPTION)

{

Filef=jfc.getSelectedFile();〃如果沒(méi)有選取文件,下面的

jfc.getName(f)將會(huì)返回輸入的文件名

fname=jfc.getName(f);

if(fname!=null&&fname.trim().length()>0){

if(fname.endsWith(".txt"))

J

else(

fname=fname.concat(".txt");

})

if(f.isFile())

fname=f.getName();

f=jfc,getCurrentDirectory();

f=new

File(f.getPath().concat(File.separator).concat(fname));

try(

f.createNewFile();

Stringstr=textArea.getText();

FileWriterfw=newFileWriter(f);

fw.write(str);

fw.close();

)

catch(Exceptionex){

ex.printStackTrace();

}}}

〃響應(yīng)"退出"菜單和"退出"按鈕的事件

if((e.getSource()==f_close)||(e.getSource()==b_close)){

whenExit();

)

if(e.getSource()==ecopy||e.getSource()==jecopy){

copy。;

)

if(e.getSource()==e_paste||e.getSource()==je_paste){

paste。;

)

if(e.getSource()==e_cut||e.getSource()==je_cut){

cut();

)

if(e.getSource()==e_clear||e.getSource()==je_clear){

clear();

)

if(e.getSource()==e_selectAll||e.getSource()==je_selectAll){

selectAll();

)

importjava.awt.*;

〃功能:包含用于創(chuàng)建用戶界面和繪制圖形圖像的所有類。

publicinterfaceActiveEvent

〃功能:知道如何對(duì)自身進(jìn)行指派的事件的接口。

pub1icclassChoice

//功能:Choice類表示一個(gè)獨(dú)出式選擇菜單。

publicclassColor

〃功能:用于封裝默認(rèn)sRGB顏色空間中的顏色,或者用于封裝由C。功rSpac。標(biāo)識(shí)的任意

顏色空間中的顏色。

publicclassMenu

〃功能:對(duì)象是從菜單欄部署的下拉式菜單組件。

publicNotebook()

(

jfc.addChoosableFileFiIter(newFileNameExtensionFilter("文本文件

jmb=newJMenuBar();

textArea=newJTextArea();

jsp=new3ScrollPane(textArea);

file=newJMenu("文件”);

edit=newJMenu("編輯”);

style=newJMenu("格式");

help=newJMenu("幫助”);

je_copy=newJMenuItem("復(fù)制(C)");

je_paste=newJMenuItem("粘貼(P)");

je_cut=newJMenuItem("翦切(X)");

je_clear=newJMenuItem("清除(D)");

je_selectAll=newJMenuItem("全選(A)");

je_find=newJMenu1tem("查找(F)");

je_replace=newJMenuItem("替換(R)");

jecopy.addActionListener(this);〃給彈窗式的各組件添加監(jiān)聽(tīng)器

je_paste.addActionListener(this);

je_cut.addActionListener(this);

je_clear.addActionListener(this);

je_selectAll.addActionListener(this);

je_find.addActionListener(this);

je_replace.addActionListener(this);

〃給界面上方的菜單條添加監(jiān)聽(tīng)器

f_new=newJMenuItem("新建(N)”);

f_new.setAccelerator(KeyStroke.getKeyStroke('^',InputEvent.CTRLJMSK,false))

;〃設(shè)置帶修飾符快捷鍵

f_new.addActionListener(this);

f_open=newJMenuItem("打開(0)”);

f_open.setAccelerator(Keystroke.getKeyStroke('O',InputEvent.CTRL_MASK,false)

);

f_open.addActionListener(this);

f_save=newJMenuItem("保存(S)");

f_save.setAccelerator(Keystroke.getKeyStroke('S',InputEvent.CTRL_MASK,false)

f_save.addActionListener(this);

f_saveas=newJMenuItem("另存為");

f_saveas.setAccelerator(Keystroke.get/CeyStro/?e(KeyEvent.InputEvent.CTRL

|InputEvent.SHIF7^M4SK));

f_saveas.addActionListener(this);

f_close=newJMenuItem("退出(W)");

f_close.setAccelerator(Keystroke.getKeyStroke('W,InputEvent.CTRL_MASKtfalse

));

f_close.addActionListener(this);

e_copy=newJMenuItem("復(fù)制(C)”);

e_copy.setAccelerator(Keystroke.getKeyStroke('C',InputEvent.C77?L_AMSK,false)

);

e_copy.addActionListener(this);

e_paste=newJMenu二tem("粘貼(V)");

e_paste.setAccelerator(Keystroke.getKeyStroke('VInputEvent.CTRL_MASK}false));

e_paste.addActionListener(this);

e_cut=newJMenuItem("剪切(X)”);

e_cut.setAccelerator(Keystroke.getKeyStroke('X'?InputEvent.CTRL_MASKfalse))

e_cut.addActionListener(this);

e_clear=newJMenu二tem("清除(D)”);

e_clear.setAccelerator(KeyStroke.getKeyStroke('D,,InputEvent.CTRL_MASK,false));

e_clean.addActionListener(this);

eselectAll=newJMenuItem("全選(A)");

e_selectAll.setAccelerator(KeyStroke.getKeyStroke("A.',InputEvent.CTRL_MASK,fals

e));

e_selectAll.addActionListener(this);

e_find=newJMenu工tem("查找(F)”);

e_find.setAccelerator(Keystroke.get/CeyStro/?e('FInputEventfalse)

);

e_copy.addActionListener(this);

e_replace=newJMenuItem("替換(R)");

e_replace.setAccelerator(KeyStroke.getKeyStroke('R,InputEvent.CTRL_MASKf-fal

se));

e_replace.addActionListener(this);

s_font=newJMenu工tem("字體(T)");

s_font.setAccelerator(Keystroke.getKeyStroke{'T',InputEvent.CTRL_MASK,false));

s_font.addActionListener(this);

s_color=newJMenu二tem("顏色(C)...;

s_color.setAccelerator(KeyStroke.get/<eyStro/?e(KeyEvent.l/K^C,InputEvent

K|InputEvent.SHIFTIAWSK-));

s_color.addActionListener(this);

h_editor=newJMenuItem("關(guān)于記事本”);

h_editor.setAccelerator(Keystroke.get/Cey5t/'o/?e(KeyEvent.InputEvent.CTRL_MA

SK));

h_editor.addActionListener(this);

h_help=newJMenuItem("幫助信息(H)”);

h_help.setAccelerator(KeyStroke.get/CeyStro/?e(KeyEventInputEvent.CTRL_MASK

));

h_help.addActionListener(this);

〃添加右鍵彈出式菜單

popUpMenu.add(je_copy);

popUpMenu.add(je_paste);

popUpMenu.add(je_cut);

popUpMenu.add(je_clear);

popUpMenu.addSeparator();

popUpMenu.add(je_selectAll);

popUpMenu.add(je_find);

popUpMenu.add(je_replace);

)

〃創(chuàng)建顏色選擇對(duì)話框

if(e.getSource()==s_color){

Colorc=JColorChooser.sbowDiaLog(this,"請(qǐng)?jiān)枔裎淖诸伾?,Color.cyan);

if(c!=null){

textArea.setForeground(c);

)

else

textArea.setForeground(textArea.getForeground());

}

JFrame類:被繼承類的父類,對(duì)代碼所用到的所以按鍵、菜單、文本進(jìn)行定義。

publicclassNotebookextendsJFrameimplementsActionListener^ItemListenerf

〃組件創(chuàng)建

^Buttonb_save,b_close;〃按鈕

JTextAreatextArea;〃文本框

FiletempFile;〃文件

JPaneljp;〃面板

JMenufile,edit,style,help;〃菜單

JMenuitem

f_new,f_open,f_save,f_close,f_saveas,e_copy,e_paste,e_cut>e_clear>e_selectAllJe

_find,e_replace,s_font,s_color,h_editor,h_help;〃菜單條

JMenuBarjmb;

DScrollPanejsp;〃滾動(dòng)面板

DPopupMenupopUpMenu=newJPopupMenu();〃右,犍彈出式菜單

JLabelstateBar;〃標(biāo)簽

3Labeljljj;

DFileChooserjfc=newJFileChooser();〃文件選擇

JMenuitemje_copy,je_paste,je_cut,je_clear,je_selectAll,je_find,je_replace;

〃彈出式菜單條

2)所用的部分圖形組件的定義:

JMenuBarmcnuRar;〃菜單條

MenueditMenu,viewMenu,helpMenu,timesys;〃菜單:編輯、查看、幫助

JMenuItemeditMenucopy,editMenupaste;〃“編轉(zhuǎn)”的菜單項(xiàng)

JRadioButtonMenuTtemviewMenu_standarT}rpe://“查看”的菜單項(xiàng)

JMenuItemhelpMenuhelpTopic,helpMenuaboutCal;〃〃幫助”的菜單項(xiàng)

JTextFielddisplayField;〃文本框

JButtonhtnBackspace;〃按鈕

JLabelIblSystemType;〃用作邊框的標(biāo)簽

JPopupMenupopupMenu;〃彈出菜單及菜單項(xiàng)

Containerdlgtipscon;〃用于顯示幫助提示信息的對(duì)話框(無(wú)邊框)

3.定義了組件的初始化以及對(duì)界面的排版

1)對(duì)總框架的總體布局對(duì)主框架的初始化操作(僅給出標(biāo)準(zhǔn)型的)

this.textArea("文本框");

〃設(shè)置部分菜單項(xiàng)的可見(jiàn)性

jp.setVisible(false);

file.setVisible(false);

edit.setVisible(false);

styIP.setVisihlp(fqlSP);

help.setVisible(false);

fnew.setVisible(false);

fopen.setVisible(false);

f_save.setVisible(false);

fclose.setVisible(false);

fsavcas.sctVisible(false);

ecopy.setVisible(false);

epaste.setVisible(false);

e_cut.setVisible(false);

〃設(shè)置一些組件的可見(jiàn)性

eclear.setVisible(false);

e_selectAl1.setVisible(false);

e_find.setVisible(false);

ereplace.setVisible(false);

s_font.setVisible(false):

scolor.setVisible(false);

heditor.setVisible(false);

h_help.setVisible(false);

jmb.setVisible(false);

stateBar.setVisible(false);

jl.setVisible(false);

jj.setVisible(false);

jecopy.setVisible(false);

je_paste.setVisible(false);

jecut.setVisible(false);

jeclear.setVisible(false);

je_selectAl1.setVisible(false);

je_find.setVisible(false);

jereplace.setVisible(false);

〃設(shè)置窗口大小和可見(jiàn)性

this.setSize(260,245);

this.setVisible(true);

)

3)記事本運(yùn)算部分程序的執(zhí)行過(guò)程:

在該類中,創(chuàng)建監(jiān)聽(tīng),響應(yīng)相應(yīng)的事件。

publicvoidmouseReleased(MouseEvente){

if(e.getButtonO==MouseEvent.BUTT0N3)

popUpMenu.show(e.getComponent(),e.getX(),e.getY());

publicvoidmousedickcd(MouseEventc){

if(c.gctButton()==MouseEvent.BUTTON1)

popUpMenu.setVisible(false);

if(stateBar.getText().equals("已保存")||stateBar.gctText().equals("新

文檔〃)){

returntrue;

)

else{

returnfalse;

)

if(m==JFileChooser.APPROVE_OPTTON){

Filef=jfc.getSelectedFileO;

for(inti=0;i<=f.length();i++){

char[]ch一newchar[i];

try(

File-Readerfr=newFi1eReader(f);

fr.read(ch);

Stringstr=newString(ch);

textArea.setText(str);

tcmpFile=f;

)

catch(lOExceptione){

e.printStackTraceO;

}))

else

return;

)

if(options==JFileChooser.APPROVE_OPTTON)

(

Filef=jfc.gctSelectcdFileO;//如果沒(méi)有選取文件,下面

的jfc.gctNamc(f)將會(huì)返回輸入的文件名

fname=jfc.gctName(f);

if(fname!=nul1&&fname.trim().length()>0)

(

if(fname.cndsWithtxt"));

else

fname=fname.concatC.txt");

)

if(e.gctSource()==fnew)

(

savcFiIcDiclog();

return;

)

if(e.gctSource()==fopen)

(

openFilcDialogO;

}

if(e.getSource()==f_saveas)

(

intoption=jfc.showDialog(this,“另存為”);

Stringfname=null;

if(option==JFileChooser.APPROVE_OPTION)

(

Filef=Jfc.getSelectedFileO;//如果沒(méi)有選取文件,下面的

jfc.gctNamc(f)將會(huì)返回輸入的文件名

fname=jfc.getName(f);

if(fname!=nul1&&fname.trim(),length()>0)

(

if(fname.endsWithC.txt"))

?

else

(

fname=fname.concatC.txt");

)

if(c!=null)

(

textArca.setForeground(c);

1

else

textArca.setForeground(textArca.getForeground());

1

if((e.gctSourccO==fclose)(e.getSourceO==b_close)){

whenExit();

)

if(e.getSourceO==e_copy||e.getSourceO==je_copy){

copy();

)

if(e.getSourceO==e_paste||e.getSourceO==je_paste){

paste();

)

if(e.getSourceO==e_cut||e.getSource()==je_cut){

cut();

)

if(e.getSourceO==c_clcar||e.getSourceO==je_clcar){

clear();

)

if(e.getSourceO==e_sclcctAll||e.getSourceO

je_sclcctAll){{

selcctAl1();

)

實(shí)現(xiàn)的接口:ActionListener>KeyListener和MouseMotionListenero

textArca.addMousel.istener(newMouscAdapter()(

publicvoidmouseRoleased(MouseEvcnte){

if(e.getButton()==MouseEvent.BUTTONS)

popUpMenu.show(e.getComponcnt(),e.getX(),e.getY());

}//e.getComponcnt()和textArea具有同等效果

publicvoidmousedieked(MouseEvcnte)(

if(e.getButton()==MouseEvent.BUTTON1)

popUpMcnu.sctVisiblc(falsc);

}});

(

je_copy.addActionListener(this);〃給彈窗式的各組件添加監(jiān)聽(tīng)器

je_paste.addActionListener(this);

je_cut.addActionListoner(this);

je_clear.addActionListener(this);

je_selectAll.addActionListener(this);

je_find.addActionListener(this);

je_rcplace.addActionListener(this);

)

六、設(shè)計(jì)中用到的課程知識(shí)點(diǎn)

Java語(yǔ)言程序設(shè)計(jì):

布局管理器:BorderLayout>GridLayout

窗體類:JFrame,JButton,JMenubar,JMenultem,JMenu,JLabel,

JCheckBox,JPopupMenu,JTextField,

七、設(shè)計(jì)中遇到的問(wèn)題及解決方法

1.忘記一些老師上課講的細(xì)節(jié)知識(shí)點(diǎn)。

翻書找回記憶。

2.右鍵功能不知道怎么實(shí)現(xiàn),上課老師視乎沒(méi)有講過(guò)3

旁觸類通,查找網(wǎng)上資料,右鍵類似與左鍵。

3.復(fù)制、剪切、粘貼等功能?起使用時(shí)不熟悉不順暢、

翻書查資料,上網(wǎng)搜資料。

八、程序清單

packagetest;

file=newJMenu("文件");

importjava.io.Filc;edit=newJMenu("編輯");

importjava.io.*;style=newJMenu("格式");

importjava.awt.event.*;help=newJMenu("幫助)

importjava.awt.Toolkit;

importjava.awt.*;ie_copy=newJMenuItem("復(fù)制(C)

importjavax.swing.*;”);

importjavax.swing.filcchooscr.^;jc_pasic=newJMenuItem("粘貼(P)

");

publicclassNotebookextendsJFrameje_cut=newJMenuIlem("剪切(X)

implementsAc(ionListcncr,ItcmLis(cncr{");

〃組件創(chuàng)建je_clear=newJMenuIlem("清除(D)

JButtonb_save,b_close;〃按鈕”);

JTcxtArca(cxlArca;〃文本框jc_sclcctAII=newJMenuItem("全

FiletempFile;〃文件選(A)");

JPancljp;〃面板jc_find=newJMenuItem("查找(F)

JMenufile.cdit,s(ylc.hclp;,菜單");

JMenuItemje_replace=newJMenuIlem("替換

f_new,Lopen,fLsave,f_close,Lsaveas,e_copy,(R)”);

e_paste,e_cut.e_clear,e_se!ectAll,e_find,e_rep

lace,s_fbnt,s_color,h_editor,h_help;〃菜單條je_copy.addActionListener(this);//

JMenuBarjmb;給彈窗式的各組件添加監(jiān)聽(tīng)器

JScrollPanejsp:〃滾動(dòng)面板jc_pastc.addAc(ionListcncr(this);

JPopupMenupopUpMenu=newje_cutaddActionListener(this);

JPopupMenu。;〃右鍵彈出式菜單je_clear.addActionListeiier(this);

JLabclstateBarW標(biāo)簽

JLabeljl,jj;je_selectAll.addActionListener(this);

JFileChooserjfc=newJFileChooser();Hje_find.addActionListener(this);

文件選擇je_rcplace.addActionListcner(this);

JMenuItem

je_copy,je_paste,je_cut,je_clear,je_selectAll,je〃給界面上方的菜單條添加監(jiān)聽(tīng)器

_find.je_rcplacc:〃彈出式菜單條f_ncw=newJMcnuItcm("新建

publicNotebook()(N)");

(

jfc.addChoosableFilcFiltcrfncwLnew.setAccclera(or(KeyS(roke.gc(KcyS

FileNameExtensionFilter("文本文件troke('N',InputEvent.CTRL_MASK,false));//

設(shè)置帶修飾符快捷鍵

jmb=newJMenuBarO;f_new.addAc(ionListener(this);

textArea=newJTextArea();

jsp=newJScrollPane(textArea);Copen=newJMenuItem("打開

(or);

e_cut.setAccelerator(KeyStroke.getKeyStroke

f_opcn.sctAccclcrator(KeyStrokc.gciKey('X',Inpu(Evcnt.CTRL_MASK,false));

Stroke('O,,InputEvent.CTRL_MASK.false));e_cut.addActionListener(this);

Copen.addActionListener(this);

e_clear=newJMenuItem(w清除

f_save=newJMenuItem("保存(D)");

c_clcar.sctAccclcrator(KcyStrokc.gc[KcyS(rok

f_save.setAccelerator(Keystroke.getKeye('D',InputEvenl.CTRL_MASK.false));

StrokeCS\InputEvent.CTRL_MASK,false));e_clear.addActionListener(this);

f_savc.addActionListcncr((his);

e_selectAIl=newJMenuItem("全

Lsaveas=newJMenuItem("另存為選(A)”);

");

e_selectAll.selAccelerator(Keystroke.getKey

f_saveas.setAccelerator(KeyStroke.getKeStroke('A,,InputEvent.CTRL_MASK,false));

ySlrokc(KcyEvcnt.VK_S,InpuiEvcnt.CTRL_c_sclcc(All.addActionListcncr(this);

MASK|InputEvent.SHIFT_MASK));

Csavcas.addActionListcncr(this);c_find=newJMcnuItcm("查找

(F)”);

f_close=newJMenuItem("退出

(W)");e_find.setAccelerator(KeyStroke.getKeyStrok

e(,F,InputEvent.CTRL_MASK,false));

f_close.setAccelerator(KeyStroke.getKeye_copy.addActionListener(this);

Stroke('W'JnputEvent.CTRL_MASK,false));

f_close.addActionLis(encr(this);e_rcplacc=newJMcnuIlcm("替換

(R)”);

e_copy=newJMenuItem("復(fù)制

。");e_replace.setAccclerator(KeyStrokc.gc(K

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論