Java默认查找项目中的文件,例如.我创建了一个名为calculator的项目,想要一个背景图像,我会将所需的图像放在项目文件夹中.我想通过改变Java寻找图像的位置来更加整洁.
我创建了一个名为res的文件夹,并将其添加到构建路径中,但如果我将图像放入此res文件夹,则无法找到它.例如:
launcher.setIconImage(new ImageIcon("Logo.png").getImage());  
如果我把Logo.png放在res文件夹中,它就不会改变IconImage,如果我将它放在项目文件夹中.当我说项目文件夹时,我的意思是当你创建一个新的Java项目时eclipse创建的文件夹.
所以,我正在为我的游戏制作一个选项菜单,我有一个按钮,当按下它时,它将文本更改为数组中的下一个分辨率,所以基本上用户按下此按钮将其分辨率更改为下一个字符串数组.
我的问题是获得点击事件.
现在,当用户按下按钮时,它在鼠标按下时返回true,而不是在按下鼠标时返回true.我想只在按下鼠标时在鼠标事件中返回true.
我环顾四周,我发现的一切似乎与我所做的一样,或者正如我所说,在鼠标停止时返回true,而不是初始点击.
我的事件是在EventManager单例中处理的,以下是我认为必要的函数:
我的更新函数,这是轮询事件的地方,值得注意的是我正在使用名为"e"的私有SDL_Event.
void EventManager::update(){
    while(SDL_PollEvent(&e)){
        SDL_GetMouseState(&mouseX, &mouseY);
        switch(e.type){
            case SDL_QUIT:
                running = false;
        }
    }
}
我的mousePress功能,我想要鼠标按下返回.
int EventManager::mousePress(){
    if(e.type == SDL_MOUSEBUTTONDOWN){
        return e.button.button;
    }
    return 0;
}
我一直在寻找解决方案,老实说,我被困住了。
我正在尝试安装Box2D,如文件路径所示。
无论如何,此提示在出现以下内容之前会出现几次:
The CXX compiler identification is unknown
Check for working CXX compiler: C:/MinGW/bin/g++.exe
Check for working CXX compiler: C:/MinGW/bin/g++.exe -- broken
CMake Error at C:/Program Files/CMake/share/cmake-3.6/Modules/CMakeTestCXXCompiler.cmake:54 (message):
  The C++ compiler "C:/MinGW/bin/g++.exe" is not able to compile a simple
  test program.
  It fails with the following output:
   Change Dir: C:/Users/alexm/Documents/Box2D/Build/CMakeFiles/CMakeTmp
  Run Build Command:"C:/MinGW/bin/mingw32-make.exe" "cmTC_31089/fast"
  C:/MinGW/bin/mingw32-make.exe -f CMakeFiles\cmTC_31089.dir\build.make
  CMakeFiles/cmTC_31089.dir/build
  mingw32-make.exe[1]: Entering directory
  'C:/Users/alexm/Documents/Box2D/Build/CMakeFiles/CMakeTmp'
  Building CXX object CMakeFiles/cmTC_31089.dir/testCXXCompiler.cxx.obj
  C:\MinGW\bin\g++.exe -o CMakeFiles\cmTC_31089.dir\testCXXCompiler.cxx.obj
  -c
  C:\Users\alexm\Documents\Box2D\Build\CMakeFiles\CMakeTmp\testCXXCompiler.cxx
  CMakeFiles\cmTC_31089.dir\build.make:64: recipe for target
  'CMakeFiles/cmTC_31089.dir/testCXXCompiler.cxx.obj' failed
  mingw32-make.exe[1]: *** …我真的不明白发生了什么,如果有人可以向我解释这将是伟大的.
所以,这是我的代码:
public static ArrayList<Integer> numbers = new ArrayList<Integer>();
public static void main(String[] args){
    for(int i =0; i != 90; i++){
        System.out.println(generate());
    }
}
public static int generate(){
    Random random = new Random();
    int rand = random.nextInt(89)+1;
    while(numbers.contains(rand)){ //<---Here seems to be my problem
        rand = random.nextInt(89)+1;
        System.out.println("Number: " + rand + " already exists!");
    }
    numbers.add(rand);
    return rand;
}
我正在编写一个程序,它生成一个0-90的随机数,每个都与上一个不同.不幸的是,似乎while循环只返回true.