尝试statemet.executeUpdate()在我的代码中执行时,我收到以下错误:
Local variable statement defined in an enclosing scope must be final or effectively final.
Run Code Online (Sandbox Code Playgroud)
到目前为止这是我的代码:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;.
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class a1 {
protected Shell shell;
private Text text;
private Text text_1;
private Text text_2;
private Text text_3;
/**
* Launch the application.
* @param args
*/
public static void main(String[] args) {
try { …Run Code Online (Sandbox Code Playgroud) 问题是关于"int amount".我正在尝试创建一个系统,每隔几秒就会将一个数量添加到起始量.
public static void main(String[] args) {
final int WIDTH = 600;
final int HEIGHT = 600;
int amount = 0;
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
int amount = amount + 1;
}
}, 2*1000, 2*1000);
JFrame frame = new JFrame("TimerTest");
frame.setVisible(true);
frame.setSize(WIDTH, HEIGHT);
frame.setResizable(false);
frame.setLayout(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel label = new JLabel("");
label.setText(String.valueOf(amount));
frame.add(label);
}
}
Run Code Online (Sandbox Code Playgroud)