Java 我的Greenfoot程序作为Greenfoot文件工作,但不是jar文件
我正在为学校制作一个充满词汇游戏的小游戏厅。当我在greenfoot窗口中运行程序时,它运行得非常完美。但是当我为它创建一个jar文件时,当它被Greenfoot.ask()提示时,它就会停止。代码如下:Java 我的Greenfoot程序作为Greenfoot文件工作,但不是jar文件,java,greenfoot,Java,Greenfoot,我正在为学校制作一个充满词汇游戏的小游戏厅。当我在greenfoot窗口中运行程序时,它运行得非常完美。但是当我为它创建一个jar文件时,当它被Greenfoot.ask()提示时,它就会停止。代码如下: import greenfoot.*; import java.util.*; import java.io.*; import java.lang.*; public class Vocabulary { static ArrayList<World> back = n
import greenfoot.*;
import java.util.*;
import java.io.*;
import java.lang.*;
public class Vocabulary
{
static ArrayList<World> back = new ArrayList<World>();
static String vocab_List;
static Scanner list = null;
static ArrayList<String> last = new ArrayList<String>();
static Scanner all;
static ArrayList<String> problems = new ArrayList<String>();
static Map<String, String> answers = new HashMap<String, String>();
static int x2 = 0;
static int y = 1;
static int count= 0;
static boolean an;
static World help;
static int right = 0;
public static boolean run() throws IOException
{
right = 0;
Collections.shuffle(problems);
for(int x = 0; x < 3; x++)
{
String[] def = answers.get(problems.get(x)).split(" ");
String answer = Greenfoot.ask("What does " + problems.get(x) + " mean?");
count = 0;
for(String temp: def)
{
if(answer.contains(temp))
count++;
}
if(count > def.length/2 && count > 1 || count == def.length)
{
help.showText("Correct",300,100);
Greenfoot.delay(50);
right++;
}
else
{
help.showText("Actually... it means " + answers.get(problems.get(x)), 300, 100);
Greenfoot.delay(50);
}
if(right >= 2)
{
an = true;
}
else
{
an = false;
}
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
help.showText("",300,100);
}
return an;
}
public static boolean run(int num) throws IOException
{
right = 0;
Collections.shuffle(problems);
for(int x = 0; x < num; x++)
{
String[] def = answers.get(problems.get(x)).split(" ");
String answer = Greenfoot.ask("What does " + problems.get(x) + " mean?");
count = 0;
for(String temp: def)
{
if(answer.contains(temp))
count++;
}
if(count > def.length/2 && count > 1 || count == def.length)
{
help.showText("Correct",300,100);
Greenfoot.delay(50);
right++;
}
else
{
help.showText("Actually... it means " + answers.get(problems.get(x)), 300, 100);
Greenfoot.delay(50);
}
if(right >= num/2)
{
an = true;
}
else
{
an = false;
}
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
help.showText("",300,200);
}
return an;
}
public static void setBack(World world)
{
back.add(world);
}
public static void setMode(ArrayList<Integer> lesson) throws IOException
{
problems.clear();
answers.clear();
x2 = 0;
all = new Scanner(new File("All_Vocab.in"));
for(int x : lesson)
{
list = new Scanner(new File("Vocab " + x + ".in"));
while(all.hasNextLine())
{
last.add(all.nextLine() + "\n");
}
FileWriter fw = new FileWriter("All_Vocab.in");
BufferedWriter bw = new BufferedWriter(fw);
for(int c = 0; c < last.size(); c++)
{
bw.write(last.get(c));
}
bw.write(vocab_List+".in");
bw.close();
while(list.hasNextLine())
{
problems.add(list.nextLine());
answers.put(problems.get(x2), list.nextLine());
x2++;
}
}
}
public static void setHelp(World hell)
{
help = hell;
}
}
导入绿足。*;
导入java.util.*;
导入java.io.*;
导入java.lang.*;
公共课词汇
{
静态ArrayList back=新建ArrayList();
静态字符串人声表;
静态扫描列表=空;
静态ArrayList last=新ArrayList();
静态扫描仪;
静态ArrayList问题=新建ArrayList();
静态映射应答=新的HashMap();
静态int x2=0;
静态int y=1;
静态整数计数=0;
静态布尔an;
静态世界帮助;
静态int右=0;
公共静态布尔运行()引发IOException
{
右=0;
收藏。洗牌(问题);
对于(int x=0;x<3;x++)
{
字符串[]def=answers.get(problems.get(x)).split(“”);
String-answer=Greenfoot.ask(“什么是“+问题.得到(x)+”的意思?”);
计数=0;
用于(字符串温度:def)
{
如果(答案包含(临时))
计数++;
}
如果(计数>定义长度/2&&计数>1 | |计数==定义长度)
{
帮助。showText(“更正”,300100);
绿足。延迟(50);
右++;
}
其他的
{
showText(“实际上……它的意思是”+answers.get(problems.get(x)),300100);
绿足。延迟(50);
}
如果(右>=2)
{
an=真;
}
其他的
{
an=假;
}
尝试
{
睡眠(1000);
}
捕捉(中断异常e)
{
e、 printStackTrace();
}
help.showText(“,300100);
}
返回一个;
}
公共静态布尔运行(int num)引发IOException
{
右=0;
收藏。洗牌(问题);
对于(int x=0;x定义长度/2&&计数>1 | |计数==定义长度)
{
帮助。showText(“更正”,300100);
绿足。延迟(50);
右++;
}
其他的
{
showText(“实际上……它的意思是”+answers.get(problems.get(x)),300100);
绿足。延迟(50);
}
如果(右>=num/2)
{
an=真;
}
其他的
{
an=假;
}
尝试
{
睡眠(1000);
}
捕捉(中断异常e)
{
e、 printStackTrace();
}
help.showText(“,300200);
}
返回一个;
}
公共静态无效挫折(世界)
{
返回。添加(世界);
}
公共静态void setMode(ArrayList课程)引发IOException
{
问题。清除();
答案:clear();
x2=0;
all=新扫描仪(新文件(“all_Vocab.in”);
用于(int x:课程)
{
列表=新扫描仪(新文件(“Vocab”+x+”.in”);
while(all.hasNextLine())
{
last.add(all.nextLine()+“\n”);
}
FileWriter fw=新的FileWriter(“All_Vocab.in”);
BufferedWriter bw=新的BufferedWriter(fw);
对于(int c=0;c
如果您需要整个项目,请告诉我,我将与您共享。无需担心,问题是扫描仪没有读取文件,因为它在jar中找不到路径。它在Greenfoot.ask处暂停,因为在读取文件时,它抛出了IOException,使文件继续,最终导致NullPointerException