gpt4 book ai didi

java - 单击按钮时运行方法

转载 作者:行者123 更新时间:2023-12-01 09:44:45 24 4
gpt4 key购买 nike

我需要在单击按钮(重置按钮)时运行某个函数。我收到错误:“表达式非法开始”并需要帮助:

private void resetActionPerformed(java.awt.event.ActionEvent evt) {                                      

String sDay = day.getText();
String sName = name.getText();
String sCash = cash.getText();
String sReason = reason.getText();
String sCourse = courses.toString();

public static void main(String[] args) throws IOException, WriteException {

String fileName = "E:\\Java Workspace\\file" + day + ".xls";
WritableWorkbook workbook = Workbook.createWorkbook(new File(fileName));
WritableSheet sheet = workbook.createSheet(name, 0);

Label label1 = new Label(0, 0, "A label word record");
sheet.addCell(label1);

jxl.write.Number number = new jxl.write.Number(0, 1, 3.1459);
sheet.addCell(number);

workbook.write();
workbook.close();
}
// TODO add your handling code here:
}

最佳答案

这是您的代码的正确版本:

public class FooExample {

private void resetActionPerformed(java.awt.event.ActionEvent evt) {

String sDay = day.getText();
String sName = name.getText();
String sCash = cash.getText();
String sReason = reason.getText();
String sCourse = courses.toString();

} // this bracket was missing in the original code

public static void main(String[] args) throws IOException, WriteException {

try {
String fileName = "E:\\Java Workspace\\file" + day + ".xls";
WritableWorkbook workbook = Workbook.createWorkbook(new File(fileName));
WritableSheet sheet = workbook.createSheet(name, 0);

Label label1 = new Label(0, 0, "A label word record");
sheet.addCell(label1);

jxl.write.Number number = new jxl.write.Number(0, 1, 3.1459);
sheet.addCell(number);

workbook.write();
workbook.close();
} catch(Exception ex){ // the fix
System.out.println("Error " + ex.getMessage());
//TODO handle Exception as you need
}
}
}

您应该使用 try catch block 来处理已检查和未检查的异常。我将其添加到代码中。请注意应在其中添加异常处理代码的 TODO。

关于java - 单击按钮时运行方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38156936/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com