日期:2014-05-20  浏览次数:21023 次

不知道如何让打开的文件采用unicode的编码方式编码,求解答
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FileDialog;
import java.awt.GridLayout;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.MenuShortcut;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedInputStream;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.text.JTextComponent;

public class MyNotepad 
{
static JFrame frame;
static JScrollPane textScroll = null;
static JTextArea textArea = null;
  public static final int FRAME_WIDTH = 300;
public static final int FRAME_HEIGHT = 300;

public static final void init()
{
frame = new JFrame("记事本");
// ImageIcon image = new ImageIcon("src/myPicture.jpg");
// frame.setIconImage(image.getImage());
// 1、菜单条
MenuBar menuBar = new MenuBar();
frame.setMenuBar(menuBar);

// 2、创建菜单
Menu fileMenu = new Menu("文件(F)");
Menu editMenu = new Menu("编辑(E)");
Menu formatMenu = new Menu("格式(O)");
menuBar.add(fileMenu);
menuBar.add(editMenu);
menuBar.add(formatMenu);

// 3、文件子菜单项
MenuItem openFile = new MenuItem("打开文件", new MenuShortcut(0x4F, true));
MenuItem newFile = new MenuItem("新建", new MenuShortcut(0x4E, true));
MenuItem save = new MenuItem("保存", new MenuShortcut(0x53, false));
MenuItem saveAs = new MenuItem("另存为", new MenuShortcut(0x53, true));
MenuItem close = new MenuItem("关闭", new MenuShortcut(0x57, false));
MenuItem exit = new MenuItem("退出");
fileMenu.add(newFile);
fileMenu.add(openFile);
fileMenu.insertSeparator(2);
fileMenu.add(close);
fileMenu.insertSeparator(4);
fileMenu.add(save);
fileMenu.add(saveAs);
fileMenu.add(exit);

// 创建文本域
textArea = new JTextArea(300,300);
// 创建滚动条
textScroll = new JScrollPane(textArea);
frame.add(textScroll, BorderLayout.CENTER);
// 创建标签
 
final JTextField textfield = new JTextField(3);
final JTextField textfield1 = new JTextField(3);
final JTextField textfield2 = new JTextField(3);
final JTextField textfield3 = new JTextField(3);
final JTextField textfield4 = new JTextField(3);
final JTextField textfield5 = new JTextField(3);
final JTextField textfield6 = new JTextField(3);
final JTextField textfield7 = new JTextField(3);  
 

JPanel northpanel = new JPanel();
JPanel southpanel = new JPanel();
northpanel. setLayout(new GridLayout(4,4));

 

northpanel.add(new JLabel("User name:")); 
northpanel.add(textfield);
northpanel.add(new JLabel("User name1:")); 
northpanel.add(textfield1);
northpanel.add(new JLabel("User name2:")); 
northpanel.add(textfield2);
northpanel.add(new JLabel("User name3:")); 
northpanel.add(textfield3);
northpanel.add(new JLabel("User name4:"));