} filedialog_load.getFile()); file_reader=new FileReader(file); in=new BufferedReader(file_reader); while((s=in.readLine())!=null) area.append(s+'\\n'); in.close(); file_reader.close(); } catch(IOException e1) {} } } 文本编辑器的保存和打开功能的实现用文件对话框及输入输出流来完成。先建立打开和保存对话框,在public void actionPerformed(ActionEvent e)里分别用FileWriter()和FileReader()方法实现保存和打开。 2) 调用颜色对话框 else if(e.getSource()==item5) { Color newColor=JColorChooser.showDialog(this,\调色板\ if(newColor!=null) area.setBackground(newColor); } 文本编辑器要实现背景功能可以用javax.swing包中的JColorChooser类的静态方法。Pubic static Color showDialog(Component,String title,Color initialColor),其中参数Component指定对话框所依赖的组件,即文本编辑器中的文本区area,title指定对话框的标题“调色板”,initialColor指定对话框返回的初始颜色,即对话框消失后,返回默认值。 3) 建立Choice下拉列表实现对字体的设置 Choice list; GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment(); String fontName[]=ge.getAvailableFontFamilyNames(); public void itemStateChanged(ItemEvent e) { String name=list.getSelectedItem(); Font f=new Font(name,Font.PLAIN,15); area.setFont(f); } 文本编辑器要实现对字体的设置,我选用了GraphicsEnvironment对象调用String [] getAvailableFontFamilyNames()方法,该方法可以获取计算机上所有可用的字体名称,并存放到字符串数组中。 4)字形,字体大小部分 else if(e.getSource()==item8) //设置字形(常规,倾斜,加粗) { Font font=area.getFont(); int style=font.getStyle(); style=style^0; area.setFont(new Font(\ } else if(e.getSource()==item9) { Font font=area.getFont(); int style=font.getStyle(); style=style^2; area.setFont(new Font(\ } else if(e.getSource()==item10) { Font font=area.getFont(); int style=font.getStyle(); style=st