- /*
- 书写一个打开与保存
- 思路:
- 1.确定主题
- 2.构造方法
- 步骤:
- 1.主题 Frame FileDialog MenuBar Menu MenuItem
- 2.构造方法
- */
- import java.awt.*;
- import java.awt.event.*;
- import java.io.*;
- class MyMenuTest
- {
- private Frame f;
- private TextArea ta;
- private MenuBar mb;
- private Menu m;
- private MenuItem closeItem,saveItem,loadItem;
- private FileDialog save,load;
- private File file;
- MyMenuTest()
- {
- init();
- }
- public void init()
- {
- f = new Frame("文本");
- ta = new TextArea();
- mb = new MenuBar();
- m = new Menu("菜单");
- loadItem = new MenuItem("打开");
- saveItem = new MenuItem("保存");
- closeItem = new MenuItem("退出");
- load = new FileDialog(f,"打开");
- save = new FileDialog(f,"保存",FileDialog.SAVE);
- f.setMenuBar(mb);
- f.add(ta);
- mb.add(m);
- m.add(loadItem);
- m.add(saveItem);
- m.add(closeItem);
- f.setBounds(400,50,600,600);
- 监听();
- f.setVisible(true);
- }
- private void 监听()
- {
- saveItem.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- if(file == null)
- {
- save.setVisible(true);
- String dir = save.getDirectory();
- String name = save.getFile();
- if(dir == null && name == null)
- return ;
- file = new File(dir,name);
- }
- try
- {
- PrintWriter pw = new PrintWriter(new FileWriter(file),true);
-
- pw.println(ta.getText());
-
- pw.close();
- }
- catch (Exception ex)
- {
- }
-
- }
- });
- loadItem.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- load.setVisible(true);
-
- ta.setText("");
- String dir = load.getDirectory();
- String name = load.getFile();
- try
- {
- file = new File(dir,name);
- BufferedReader br = new BufferedReader(new FileReader(file));
- String line = null;
- while ((line = br.readLine()) != null)
- {
- ta.append(line+"\r\n");
- }
- br.close();
- }
- catch (Exception ex)
- {
- }
-
- }
- });
- f.addWindowListener(new WindowAdapter()
- {
- public void windowClosing(WindowEvent e)
- {
- System.exit(0);
- }
- });
- closeItem.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- System.exit(0);
- }
- });
- }
- public static void main(String[] args)
- {
- new MyMenuTest();
- }
- }
复制代码 我将其编译成 jar包 但是给错误提示,不明白。
请问下这个错误提示是什么意思?
|
|