zoukankan      html  css  js  c++  java
  • 秒秒钟食言

      其实我该睡觉了,擦四点了。

      先发个打开文件的代码,布局就先不发吧。

      明天把保存按钮的代码写了。

      什么你说退出?

     1 class openListener implements ActionListener {
     2     MainFrame parent;
     3     
     4     openListener(MainFrame parent) {this.parent = parent;}
     5     
     6     @Override
     7     public void actionPerformed(ActionEvent e) {
     8         //选择文件。
     9         JFileChooser fileChooser = new JFileChooser();
    10         fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    11         fileChooser.setMultiSelectionEnabled(false);
    12         File file = null;
    13         if (fileChooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
    14             file = fileChooser.getSelectedFile();
    15         }
    16         
    17         //读取文件内容后向文本框一次性写入。
    18         try {
    19             InputStreamReader in = new InputStreamReader(new FileInputStream(file), "Unicode");
    20             BufferedReader reader = new BufferedReader(in);
    21             String s;
    22             StringBuffer sb = new StringBuffer("");
    23             while ((s = reader.readLine()) != null) {
    24                 sb.append(s + "
    ");
    25             }
    26             parent.content.setText(sb.toString());
    27             reader.close();
    28         } catch (FileNotFoundException ex) {
    29             ex.printStackTrace();
    30         } catch (IOException ioe) {
    31             ioe.printStackTrace();
    32         }
    33     }
    34 }
    一个按钮的监听内容
  • 相关阅读:
    gRPC .NET Core跨平台学习
    .NET Core性能测试组件BenchmarkDotNet 支持.NET Framework Mono
    ASP.NET Core中间件(Middleware)实现WCF SOAP服务端解析
    gRPC C#学习
    中标麒麟关闭防火墙
    linux安装python
    python matplotlib.pyplot保存jpg图片失败
    python正态分布
    数据健康管理总结
    python使用statsmodel
  • 原文地址:https://www.cnblogs.com/chihane/p/3500336.html
Copyright © 2011-2022 走看看