我有2部分这样的代码
package populateDB;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Random;
public class PopulateDB {
public static void main(String[] args) {
int[] nums = new int[100000];
String[] ids = new String[100000];
// Fill array with numbers 0-99999
for(int i = 0; i < ids.length; i++) {
nums[i] = i;
}
// Fill array to give length
Arrays.fill(ids, "fill");
shuffleArray(nums);
// Changes numbers such as 235 to 00235
for(int i = 0; i < ids.length; i++) {
ids[i] = createString(nums[i]);
}
try
{
// Create a MySQL database connection
String myDriver = "org.gjt.mm.mysql.Driver";
String myUrl = "jdbc:mysql://localhost:3306/humansight_schema";
Class.forName(myDriver);
Connection conn = DriverManager.getConnection(myUrl, "root", "password");
// The MySQL insert statement
String query = " insert into user_data (company_id)"
+ " values (?)";
for(int i = 0; i < ids.length; i++) {
// Create the MySQL insert PreparedStatement
PreparedStatement preparedStmt = conn.prepareStatement(query);
preparedStmt.setString (1, ids[i]);
// Execute the PreparedStatement
preparedStmt.execute();
}
conn.close();
System.out.println("Done");
}
catch (Exception e)
{
System.err.println("Got an exception!");
System.err.println(e.getMessage());
}
}
private static void shuffleArray(int[] array)
{
int index;
Random random = new Random();
for (int i = array.length - 1; i > 0; i--)
{
index = random.nextInt(i + 1);
if (index != i)
{
array[index] ^= array[i];
array[i] ^= array[index];
array[index] ^= array[i];
}
}
}
private static String createString(int num) {
String numString = Integer.toString(num);
int zeroesToAdd = 5 - numString.length();
String zeroes = "";
for(int i = 0; i < zeroesToAdd; i++) {
zeroes = zeroes.concat("0");
}
return zeroes.concat(numString);
}
}
还有这个
import tkinter
import tkinter.messagebox
import turtle
from turtle import*
turtle.tracer(0,0)
wn = turtle.Screen()
wn.bgcolor("light blue")
wn.title("Turtle")
skk = turtle.Turtle()
skk.hideturtle()
skk.speed(800)
skk.pensize(3)
def Board():
for i in range(13):
skk.penup()
skk.goto(-650,-300+i*50)
skk.pendown()
skk.forward(1200)
skk.penup()
for i in range(25):
skk.penup()
skk.goto(-650+i*50,-300)
skk.pendown()
skk.left(90)
skk.forward(600)
skk.right(90)
skk.penup()
d=0
def click(x,y):
print(x,y)
if((x<-650 or x>550) or (y<-300 or y>300)):
tkinter.messagebox.showinfo("No!!","Wrong position !")
else:
if (x%100<=75 and x%100>=25):
if (x%100<=75 and x%100>50):
x=x-x%100+50
else: x=x+50-x%100;
else:
if(x%100<=25 and x%100>0):
x=x-x%100
else: x=x+100-x%100
`enter code here` if (y%100<=75 and y%100>=25):
if (y%100<=75 and x%100>50):
y=y-y%100+50
else: y=y+50-y%100;
else:
if(y%100<=25):
y=y-y%100
else: y=y+100-y%100
global d
if (d%2==0):
X(x,y)
else:
O(x,y)
d=d+1
def X(x,y):
skk.pensize(8)
skk.pencolor("blue")
skk.penup()
skk.goto(x-12.5,y-12.5)
skk.pendown()
skk.goto(x+12.5,y+12.5)
skk.penup()
skk.goto(x-12.5,y+12.5)
skk.pendown()
skk.goto(x+12.5,y-12.5)
skk.penup()
def O(x,y):
skk.pensize(8)
skk.pencolor("red")
skk.penup()
skk.goto(x,y-12.5)
skk.pendown()
skk.circle(12.5,360)
skk.penup()
x=0
y=0
Board2()
onscreenclick(click)
turtle.update()
turtle.done()
我试图编写一个函数,该函数可以将整个第一个代码传递给窗口。但是,当我用代码设置一个函数并将其传递给Board_Button时,它出现了2个窗口(一个来自海龟,一个来自tkinter) 我在代码中出了什么问题? 谢谢