风机的数据的导入
2015-07-31 20:35
330 查看
JButton btnNewButton = new JButton("导入"); btnNewButton.addMouseListener(new MouseAdapter() { private FileOutputStream fos; private FileInputStream fis; private BufferedInputStream bis; private BufferedOutputStream bos; @Override public void mouseClicked(MouseEvent paramMouseEvent) { try { if (filePathText.getText() != null) { File file = new File(filePathText.getText()); // FileInputStream fis = new FileInputStream(file); String name = file.getName(); System.out.println("name " + name); String outfilename = IAppConstants.fanpath + name.substring(0, name.indexOf(".")) + ".dat"; System.out.println(outfilename); File outfile = new File(outfilename); if (outfile.exists()) { int con = JOptionPane.showConfirmDialog(null, "文件已存在,继续导入?", "导入错误", JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.INFORMATION_MESSAGE); if(con>0) return; } fos = new FileOutputStream(outfile); fis = new FileInputStream(file); bis = new BufferedInputStream(fis); bos = new BufferedOutputStream(fos); int i; byte[] buf = new byte[2048]; while ((i = bis.read(buf)) != -1) { fos.write(buf, 0, i); } chartParentPanel.removeAll(); double[][] dataArr = GetFanArr.getFanDataArr(file); chart = createChart(dataArr); chartParentPanel.setLayout(new BorderLayout(0, 0)); chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(400, 360)); chartPanel.setFillZoomRectangle(true); chartParentPanel.add(chartPanel, BorderLayout.CENTER); chartPanel.revalidate(); ; chartPanel.repaint(); ; Object[][] obDataArr = toObdata(dataArr); dtm = (DefaultTableModel) fanTable.getModel(); dtm.setDataVector(obDataArr, columnNames); fanTable.repaint(); JOptionPane.showMessageDialog(null, file + "导入成功,", "提示", JOptionPane.INFORMATION_MESSAGE); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); JOptionPane.showMessageDialog(null, "请检查excel表格", "错误", JOptionPane.ERROR_MESSAGE); } finally { try { fis.close(); fos.flush(); fos.close(); bis.close(); bos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } });
相关文章推荐
- hdoj-1069-Monkey and Banana【动态规划】
- 设计模式之策略模式
- 设计模式——设计模式总结
- 对css float 浮动的学习心得
- 九度oj 1137
- 仿Uber主界面布局,框架简单实现
- 培养狼一样的“团队”——从菜鸟管理者到追求成为优秀领导者
- poj 1328 区 间选点问题(贪心)
- 20150731
- 关于mybatis里面的Executor--转载
- hdu 3081 二分图最大匹配
- 矩阵快速幂 POJ 3070 Fibonacci
- Nim
- spring与hibernate整合(三种方式)
- 快速数论变换模板(NTT)
- 已知面积求周长
- Radar Installation(贪心,可以转化为今年暑假不ac类型)
- 【暑假集训】之被ACM金牌大神虐的第一天之dp篇(未完结)
- 数据挖掘工程师面试指南
- XMLHttpRequest Level 2的跨域功能(CORS) //另附JSONP的跨域实现