Java libsdl类使用所有JVM(阻止代码的执行)

Java libsdl类使用所有JVM(阻止代码的执行),java,agents-jade,Java,Agents Jade,我使用图形库libsdl(Java的CSDL绑定)和多代理库Jade 我有一个代理,它创建了一个用libsdl创建的GUI类,在创建之后,代理的代码不再执行。事实上,唯一运行的是GUI类 为什么? 有人知道如何解决这个问题吗?我希望GUI与我的程序的其他代理并行运行,但一旦启动,它就会占用所有JVM 以下是我的代码的相关部分(首先是代理): packagemain; 导入java.util.HashMap; 导入java.util.Map; 进口玉石、芯材、代理; 进口jade.core.beh

我使用图形库
libsdl
(Java的C
SDL
绑定)和多代理库Jade

我有一个代理,它创建了一个用
libsdl
创建的GUI类,在创建之后,代理的代码不再执行。事实上,唯一运行的是GUI类

为什么?

有人知道如何解决这个问题吗?我希望GUI与我的程序的其他代理并行运行,但一旦启动,它就会占用所有JVM

以下是我的代码的相关部分(首先是代理):

packagemain;
导入java.util.HashMap;
导入java.util.Map;
进口玉石、芯材、代理;
进口jade.core.behavious.TickerBehaviour;
导入sdljava.SDLException;
公共类显示扩展代理
{
私有静态最终长serialVersionUID=1L;
Map m_drones=新HashMap();
GUI m_GUI=null;
受保护的无效设置()
{   
对于(int i=0;i
和GUI:

    package main;

import java.util.HashMap;
import java.util.Map;

import sdljava.SDLException;
import sdljava.SDLMain;
import sdljava.event.SDLEvent;
import sdljava.video.SDLRect;
import sdljava.video.SDLSurface;
import sdljava.video.SDLVideo;

public class GUI
{
    SDLSurface m_screen = null; 
    Map<String, SDLSurface> m_surfaces = new HashMap<String, SDLSurface>();
    boolean m_running = true;

    void initSurfaces(Map<String, Position> drones) throws SDLException
    {
        for(Map.Entry<String, Position> entry : drones.entrySet())
        {
            SDLSurface surface = SDLVideo.createRGBSurface(SDLVideo.SDL_HWSURFACE, Constants.dotSize, Constants.dotSize, 32, 0, 0, 0, 0);
            SDLRect rect = new SDLRect(entry.getValue().getX(), entry.getValue().getY());
            surface.fillRect(surface.mapRGB(Constants.droneRed, Constants.droneGreen, Constants.droneBlue));
            surface.blitSurface(m_screen, rect);
            m_surfaces.put(entry.getKey(), surface);
        }
    }

    public GUI(Map<String, Position> drones) throws SDLException, InterruptedException 
    {
        SDLMain.init(SDLMain.SDL_INIT_VIDEO);
        m_screen = SDLVideo.setVideoMode(Constants.environmentWidth * Constants.dotSize, 
        Constants.environmentHeight * Constants.dotSize, 32, SDLVideo.SDL_DOUBLEBUF | SDLVideo.SDL_HWSURFACE);
        SDLVideo.wmSetCaption("Flotte de drones en 2D", null);

        initSurfaces(drones);

        while(m_running) 
        {
            SDLEvent event = SDLEvent.pollEvent();

            if(event instanceof SDLEvent) 
            {
                switch (event.getType()) 
                {
                    case SDLEvent.SDL_QUIT:     
                        m_running = false;    
                    break;
                }
            }

            m_screen.flip();
        }

        freeSurfaces();
        SDLMain.quit();
    }

    public void updateGUI(Map<String, Position> drones) throws SDLException
    {
        for(Map.Entry<String, Position> entry : drones.entrySet())
        {
            SDLRect rect = new SDLRect(entry.getValue().getX(), entry.getValue().getY());
            m_surfaces.get(entry.getKey()).updateRect(rect);
            m_surfaces.get(entry.getKey()).blitSurface(m_screen, rect);
        }
    }

    void freeSurfaces() throws SDLException
    {
        for(Map.Entry<String, SDLSurface> entry : m_surfaces.entrySet())
        {
            m_surfaces.get(entry.getKey()).freeSurface();
        }

        m_screen.freeSurface();
    }
}
packagemain;
导入java.util.HashMap;
导入java.util.Map;
导入sdljava.SDLException;
导入sdljava.SDLMain;
导入sdljava.event.SDLEvent;
导入sdljava.video.SDLRect;
导入sdljava.video.SDLSurface;
导入sdljava.video.SDLVideo;
公共类GUI
{
SDL表面m_屏幕=空;
Map m_surfaces=new HashMap();
布尔m_running=true;
void initSurfaces(地图无人机)引发SDLException
{
for(Map.Entry:drones.entrySet())
{
SDLSurface surface=SDLVideo.createRGBSurface(SDLVideo.SDL_HWSURFACE,Constants.dotSize,Constants.dotSize,32,0,0,0);
SDLRect rect=new SDLRect(entry.getValue().getX(),entry.getValue().getY());
surface.fillRect(surface.mapRGB(Constants.droneRed、Constants.droneGreen、Constants.droneBlue));
blitSurface(m_屏幕,矩形);
m_surfaces.put(entry.getKey(),surface);
}
}
公共GUI(映射无人机)抛出SDLException、InterruptedException
{
SDLMain.init(SDLMain.SDL_init_视频);
m_screen=SDLVideo.setVideoMode(Constants.environmentWidth*Constants.dotSize,
Constants.environment高度*Constants.dotSize,32,SDLVideo.SDL_doubuf | SDLVideo.SDL_表面);
SDLVideo.wmSetCaption(“Flotte de drones en 2D”,空);
无人机;
同时(m_运行)
{
SDLEvent event=SDLEvent.pollEvent();
if(SDLEvent的事件实例)
{
开关(event.getType())
{
案例SDLEvent.SDL_退出:
m_running=假;
打破
}
}
m_screen.flip();
}
自由曲面();
SDLMain.quit();
}
public void updateGUI(地图无人驾驶飞机)抛出SDLException
{
for(Map.Entry:drones.entrySet())
{
SDLRect rect=new SDLRect(entry.getValue().getX(),entry.getValue().getY());
m_surfaces.get(entry.getKey()).update(rect);
m_surfaces.get(entry.getKey()).blitSurface(m_屏幕,rect);
}
}
void freeSurfaces()引发SDLException
{
对于(Map.Entry:m_surfaces.entrySet())
{
m_surfaces.get(entry.getKey()).freeSurface();
}
m_screen.freeSurface();
}
}

我想我找到了答案。对于那些感兴趣的人:Jade中的每个代理都有自己的线索。因此,为了允许Display(创建GUI的代理)继续执行,我必须将GUI与他分离。我这样做的方法是让GUI也成为一个代理。因此,从我通过调用其构造函数创建GUI的那一刻起,它就启动一个新线程,并允许Display在该指令之后继续运行

所以答案是:让GUI成为代理

public class GUI extends Agent
{
    ...
}

我想我找到了答案。对于感兴趣的人:Jade中的每个代理都会运行
public class GUI extends Agent
{
    ...
}