if(mi==i22)
{editor.setForeground(Color.blue);}
if(mi==i23)
{editor.setForeground(Color.green);}
if(mi==about) //帮助菜单的关于 {
String message = \记事本----\
+ \由**老师指导,***、***、**共同完成\\n感谢您的使用!\JOptionPane.showMessageDialog(JM4.this, message,
\
于...\ }
/******弹出菜单********/
if(mi==item1) //复制 {editor.copy();}
if(mi==item2) //剪切 {editor.cut();}
if(mi==item3) //粘贴 {editor.paste();} }
/**********将文件读入到编辑区***********/ void loadFile() {
JFileChooser fc=new JFileChooser(); int r=fc.showOpenDialog(this);
if(r==JFileChooser.APPROVE_OPTION)
关
} }
{
File file=fc.getSelectedFile(); catch(IOException e){}
try{editor.read(new FileReader(file),null);}
/***********创建文件写入器*************/ void saveFile() {
JFileChooser fc=new JFileChooser(); int r=fc.showSaveDialog(this);
if(r==JFileChooser.APPROVE_OPTION) } }
/*********文件的关闭或退出************/ void close(){
try{ int option = JOptionPane.showConfirmDialog( null, \是否保存文件?\保存文件?\
JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE, null); switch(option) {
case JOptionPane.YES_OPTION:saveFile();break; case JOptionPane.NO_OPTION:System.exit(0);break; case JOptionPane.CANCEL_OPTION: return ; }}
catch(Exception e){e.printStackTrace();}} {
File file=fc.getSelectedFile(); catch(IOException e){}
try{editor.write(new FileWriter(file));}
void close2(){
try{int option = JOptionPane.showConfirmDialog( null, \是否保存已有文件?\保存文件?\
JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE, null); switch(option) {
case JOptionPane.YES_OPTION:saveFile();editor.setText(\ case JOptionPane.NO_OPTION:editor.setText(\
catch(Exception e){e.printStackTrace();}} /******编辑区的鼠标事件*********/ public void mouseReleased(MouseEvent e) {
if(e.isPopupTrigger())
pm.show(editor,e.getX(),e.getY());
}
public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mousePressed(MouseEvent e){}
public static void main (String[] args) { JM4 d=new JM4();} }