n++){
menu3_3.add(menuItem3_3[n])。
menuItem3_3[n].addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvente){
JMenuItemmi3_3=(JMenuItem)e.getSource()。
if(mi3_3.getActionCommand().equals("red")){
textarea.setForeground(Color.red)。
}
elseif(mi3_3.getActionCommand().equals("black")){
textarea.setForeground(Color.black)。
}
elseif(mi3_3.getActionCommand().equals("blue")){
textarea.setForeground(Color.blue)。
}
elseif(mi3_3.getActionCommand().equals("orange")){
textarea.setForeground(Color.orange)。
}
elseif(mi3_3.getActionCommand().equals("cyan")){
textarea.setForeground(Color.cyan)。
}
elseif(mi3_3.getActionCommand().equals("green")){
textarea.setForeground(Color.green)。
}
}
})。
}
menu3.add(menu3_1)。
menu3.add(menu3_2)。
menu3.add(menu3_3)。
//°ïÖú
JMenumenu4=newJMenu("°ïÖú")。
finalJMenuItemmenuItem4=newJMenuItem("¹ØÓÚ")。
menuItem4.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvente){
JDialogdialog=newJDialog(notepad,"¹ØÓڸüÇʱ¾",true)。
dialog.setLayout(newGridLayout(2,1))。
dialog.setSize(300,200)。
dialog.setLocation(40+getX(),50+getY())。
dialog.setTitle("¹ØÓÚjdk")。
ImageIconimageIcon=newImageIcon("ma.gif")。
JLabellabel=newJLabel("jdk1.6.0_21",imageIcon,JLabel.CENTER)。
label.setHorizontalTextPosition(JLabel.CENTER)。
label.setVerticalTextPosition(JLabel.BOTTOM)。
label.setToolTipText("×÷Õß")。
dialog.add(label)。
dialog.setVisible(true)。
dialog.setResizable(false)。
}
})。
menu4.add(menuItem4)。
//****´´½¨Îı¾Óò
textarea=newJTextArea()。
JScrollPanescrollPane=newJScrollPane(textarea)。
this.add(scrollPane)。
//Ìí¼Ó×é¼þ
menuBar.add(menu1)。
menuBar.add(menu2)。
menuBar.add(menu3)。
menuBar.add(menu4)。
this.setVisible(true)。
}catch(Exceptione1){
e1.printStackTrace()。
}
}
publicvoidopenFile(){//´ò¿ª
fileload.setVisible(true)。
Stringdirect=fileload.getDirectory()。
Stringfilename=fileload.getFile()。
if((direct!
=null)&&(filename!
=null)){
file=direct+filename。
loadFile()。
}
}
publicvoidloadFile(){//´ò¿ª
textarea.setText("")。
super.setTitle(file+"-¼Çʱ¾")。
try{
BufferedReaderbr=newBufferedReader(newFileReader(file))。
Stringreader=br.readLine()。
while(reader!
=null){
textarea.append(reader+"\n")。
reader=br.readLine()。
}
br.close()。
}catch(FileNotFoundExceptione){
System.out.println("Ä¿±êÎļþ£º"+file+"ÕÒ²»µ½£¡")。
}catch(IOExceptione){
e.printStackTrace()。
}
}
publicvoidsaveFile(){//±£´æ
Stringdangqianwenjian=textarea.getText()。
try{
if(file.isEmpty()){
filesave.setVisible(true)。
Stringdirect=filesave.getDirectory()。
Stringfilename=filesave.getFile()。
if((direct!
=null)&&(filename!
=null)){
file=direct+filename。
PrintWriterpw=newPrintWriter(newFileWriter(file))。
pw.println(dangqianwenjian)。
pw.flush()。
pw.close()。
super.setTitle(file+"-¼Çʱ¾")。
}
}else{
PrintWriterpw=newPrintWriter(newFileWriter(file))。
pw.println(dangqianwenjian)。
pw.flush()。
pw.close()。
}
}catch(IOExceptione){
e.printStackTrace()。
}
}
publicvoidsaveAs(){//Áí´æΪ
filesave.setVisible(true)。
Stringdirect=filesave.getDirectory()。
Stringfilename=filesave.getFile()。
if((direct!
=null)&&(filename!
=null)){
file=direct+filename。
saveFile()。
super.setTitle(file+"-¼Çʱ¾")。
}
}
publicstaticvoidmain(String[]args){
Notepadnotepad=newNotepad()。
notepad.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)。
notepad.setResizable(true)。
}
}
classDengluextendsDialogimplementsActionListener{
/**
*
*/
privatestaticfinallongserialVersionUID=1L。
LabelLname,Lpassword。
//¶¨ÒåÓû§ÃûºÍÃÜÂëµÄ±êÇ©
TextFieldTname。
//¶¨ÒåÓû§ÃûµÄÎı¾¿ò
JPasswordFieldTpassword。
//¶¨ÒåÃÜÂëµÄÎı¾¿ò¡£×¢£ºÊ¹ÓÃJPasswordFieldµÄºÃ´¦¾ÍÊÇÊäÈëµÄÃÜÂëÊÇÒÔ****ÏÔʾ¸øÓû§µÄ
Panelpanel1=newPanel()。
//¶¨ÒåÃæ°å
ButtonLoad,login。
//¶¨ÒåµÇ½ºÍ×¢²áµÄ°´Å¥
booleanb=true。
Filefile1=newFile("Óû§Ãû")。
Filefile2=newFile("ÃÜÂë")。
//¶¨Òå¼Ç¼Óû§×¢²áµÄÓû§ÃûºÍÃÜÂëµÄÎļþ¼Ð
Denglu(Framef,Strings,booleanb){
super(f,s,b)。
Lname=newLabel("Óû§Ãû")。
Lname.setBackground(Color.lightGray)。
//ÉèÖñêÇ©µÄ±³¾°ÑÕÉ«
Lpassword=newLabel("ÃÜÂë")。
Lpassword.setBackground(Color.lightGray)。
//ÉèÖñêÇ©µÄ±³¾°ÑÕÉ«
Tname=newTextField(10)。
Tpassword=newJPasswordField(10)。
Load=newButton("µÇ½")。
Load.setBackground(Color.lightGray)。
login=newButton("×¢²á")。
login.setBackground(Color.lightGray)。
add(panel1,BorderLayout.CENTER)。
setLayout(newCardLayout(3,2))。
panel1.add(Lname)。
panel1.add(Tname)。
panel1.add(Lpassword)。
panel1.add(Tpassword)。
panel1.add(Load)。
Load.addActionListener(this)。
panel1.add(login)。
login.addActionListener(this)。
setSize(200,200)。
addWindowListener(newWindowAdapter(){
publicvoidwindowClosing(WindowEvente){
System.exit(0)。
}
})。
}
publicvoidactionPerformed(ActionEvente){
//Óû§µÇ¼Ê¼þ´¦Àí
if(e.getSource()==Load){
Stringname1=Tname.getText()。
Stringpassword1=newString(T