问题:我eclipce 里面的workspace 和这个类文件的编码都是utf-8,咋编出的窗体还是乱码呢,求解 谢谢- public class GUITest {
- /**
- *
- *
- *
- */
- private Frame f;
- private MenuBar bar ;
- private TextArea ta;
- private MenuItem openItem, saveItem,closeItem;
- private File file;
- private FileDialog openDia ,saveDia;
- private Menu fileMenu;
- GUITest (){
- init();
- }
- public void init (){
- f=new Frame("my window");
- f.setBounds(300, 200, 400, 300);
- bar=new MenuBar();
- ta=new TextArea();
- fileMenu= new Menu("文件");
- openItem=new MenuItem("打开");
- saveItem=new MenuItem("保存");
- closeItem=new MenuItem("退出");
- fileMenu.add(openItem);
- fileMenu.add(saveItem);
- fileMenu.add(closeItem);
- bar.add(fileMenu);
- f.setMenuBar(bar);
- f.add(ta);
- f.setVisible(true);
- openDia= new FileDialog(f,"打开",FileDialog.LOAD);
- saveDia=new FileDialog(f,"保存",FileDialog.SAVE);
- }
- public void myEvent(){
- closeItem.addActionListener(new ActionListener(){
- @Override
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
-
- }});
- openItem.addActionListener(new ActionListener(){
- @Override
- public void actionPerformed(ActionEvent e) {
- openDia.setVisible(true);
- String path=openDia.getDirectory();
- String fileName=openDia.getName();
- if(path==null||fileName==null)
- return ;
- System.out.print(path+""+fileName);
- ta.setText("");
- file =new File(path,fileName);
- try {
- BufferedReader bw=new BufferedReader(new FileReader(file));
- String line=null;
- try {
- while((line=bw.readLine())!=null){
- ta.append(line);
- }
- bw.close();
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- } catch (FileNotFoundException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
-
- }
-
- });
- }
- public static void main(String[] args) {
- GUITest gt=new GUITest();
- gt.myEvent();
- }
- }
复制代码 |
|