一周Java开发问题记录
2017-03-29 22:26
393 查看
当remove 导入的jar包后,在jar文件上右键会没有build path选项
直接在项目包文件夹上右键–>配置build path、
一个JFrame中加入多个JButton时,最后一个JButton会存在现实异常
可以加一个空的JButton,不使用
将double或者float型数值转换为字符串
float dec = 0.12345f;
Java读取文件对话框,并读取.xlsx格式文件(输出)
项目检出JRE问题(Unbound classpath container: ‘JRE System Library [JavaSE-1.7]’ in project ‘idweb’)
Uncaught error fetching image
jdk版本不对应,可能过低
Operation not allowed after ResultSet closed的问题
数据库执行操作未关闭
java乱码的几个地方修改
windows - preferences - general - content types
windows - preferences - general - workspace
项目右键 - preferences
文件右键 - preferences
项目右键 - run configure - common
直接在项目包文件夹上右键–>配置build path、
一个JFrame中加入多个JButton时,最后一个JButton会存在现实异常
可以加一个空的JButton,不使用
将double或者float型数值转换为字符串
float dec = 0.12345f;
//读取文件 DecimalFormat df = new DecimalFormat("#%");//乘以100后以百分比形式输出,此处输出"12%" DecimalFormat df = new DecimalFormat("##.##");//输出"0.12" DecimalFormat df = new DecimalFormat("00.00");//输出"00.12" String s = df.format(dec); System.out.println(s);
Java读取文件对话框,并读取.xlsx格式文件(输出)
Student student = null; List<String> array = new ArrayList<>(); fd = new FileDialog(f, "Open", FileDialog.LOAD); fd.setVisible(true); try { file1 = new File(fd.getDirectory(), fd.getFile()); InputStream instream = new FileInputStream(file1); xssfWorkbook = new XSSFWorkbook(instream); XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0); for (int rowNum = 1; rowNum <= xssfSheet.getLastRowNum(); rowNum++) { xssfRow = xssfSheet.getRow(rowNum); student = new Student(); xssfRow.getCell(0).setCellType(Cell.CELL_TYPE_STRING); xssfRow.getCell(1).setCellType(Cell.CELL_TYPE_STRING); xssfRow.getCell(2).setCellType(Cell.CELL_TYPE_STRING); xssfRow.getCell(3).setCellType(Cell.CELL_TYPE_STRING); xssfRow.getCell(4).setCellType(Cell.CELL_TYPE_STRING); student.setStudentId(xssfRow.getCell(0).getStringCellValue()); student.setStudentName(xssfRow.getCell(1).getStringCellValue()); student.setStudentPic(xssfRow.getCell(2).getStringCellValue()); student.setCalledNumber(Integer.valueOf(xssfRow.getCell(3).getStringCellValue())); student.setLateNumber(Integer.valueOf(xssfRow.getCell(4).getStringCellValue())); pList.add(student); } instream.close(); flushWindow(pList); } catch (IOException ioe) { ioe.printStackTrace(); }
//输出文件 try { file2 = new File("学期报表.xlsx"); OutputStream outstream = new FileOutputStream(file2); xssfWorkbook = new XSSFWorkbook(); XSSFSheet xssfSheet = xssfWorkbook.createSheet(); XSSFRow xssfRow = xssfSheet.createRow(0); xssfRow.createCell(0).setCellValue("学号"); xssfRow.createCell(1).setCellValue("姓名"); xssfRow.createCell(2).setCellValue("图片地址"); xssfRow.createCell(3).setCellValue("被叫次数"); xssfRow.createCell(4).setCellValue("迟到次数"); xssfRow.createCell(5).setCellValue("总评成绩"); for (int rowNum = 0; rowNum < pList.size(); rowNum++) { xssfRow = xssfSheet.createRow(rowNum + 1); xssfRow.createCell(0).setCellValue(pList.get(rowNum).getStudentId()); xssfRow.createCell(1).setCellValue(pList.get(rowNum).getStudentName()); xssfRow.createCell(2).setCellValue(pList.get(rowNum).getStudentPic()); xssfRow.createCell(3).setCellValue(String.valueOf(pList.get(rowNum).getCalledNumber())); xssfRow.createCell(4).setCellValue(String.valueOf(pList.get(rowNum).getLateNumber())); if (pList.get(rowNum).getCalledNumber() == 0) { xssfRow.createCell(5).setCellValue("0"); } else { double result = (double) pList.get(rowNum).getLateNumber() / pList.get(rowNum).getCalledNumber(); DecimalFormat df = new DecimalFormat("#%");// 乘以100后以百分比形式输出,此处输出"12%" String str = df.format(result); xssfRow.createCell(5).setCellValue(str); } xssfRow.getCell(0).setCellType(Cell.CELL_TYPE_STRING); xssfRow.getCell(1).setCellType(Cell.CELL_TYPE_STRING); xssfRow.getCell(2).setCellType(Cell.CELL_TYPE_STRING); xssfRow.getCell(3).setCellType(Cell.CELL_TYPE_STRING); xssfRow.getCell(4).setCellType(Cell.CELL_TYPE_STRING); xssfRow.getCell(5).setCellType(Cell.CELL_TYPE_STRING); } xssfWorkbook.write(outstream); outstream.flush(); outstream.close(); PublicWindowSet.promptPopUp("输出报表文件成功!!!", "提示", frame); } catch (IOException ioe) { ioe.printStackTrace(); }
项目检出JRE问题(Unbound classpath container: ‘JRE System Library [JavaSE-1.7]’ in project ‘idweb’)
Uncaught error fetching image
jdk版本不对应,可能过低
Operation not allowed after ResultSet closed的问题
数据库执行操作未关闭
java乱码的几个地方修改
windows - preferences - general - content types
windows - preferences - general - workspace
项目右键 - preferences
文件右键 - preferences
项目右键 - run configure - common
相关文章推荐
- java开发中碰到的问题记录
- java开发中碰到的问题记录
- java开发连接Oracle 12c采用PDB遇到问题记录
- java开发日常问题记录
- java+ssh+eclipse开发过程问题记录
- 面试随笔——记录一些面试中碰到的问题(初级/中级Java开发)
- Java 开发 Unable to execute dex 问题解决记录
- java 开发问题记录
- java开发中遇到的问题记录
- Java 开发中遇到的乱码问题
- 使用Eclipse3.2.1+STP.0.4.0+Apache Tuscany开发SCA的Java组件(4)安装运行错误问题修正篇
- Apache、Tomcat、mysql与Java Web开发环境学习记录(20070410)
- Java+Oracle应用开发的几个经典问题
- Java 开发中遇到的乱码问题
- 解决方案:mysql的中文问题(开发语言:Java)
- 读javaWeb开发记录-类装载器
- Java+Oracle应用开发的几个经典问题
- Java 开发中遇到的乱码问题
- JBoss、Tomcat进行java web开发时8080端口被占用的问题!
- 解决了个JDK(Java Development Kit,Java开发工具包)配置的问题