Netbeans Platform集成libgdx
通过LwjglAWTCanvas
package com.acuilab.bc.main.dapp;
import com.badlogic.gdx.backends.lwjgl.LwjglAWTCanvas;
import java.util.concurrent.atomic.AtomicInteger;
import static javax.swing.SwingConstants.CENTER;
import org.openide.util.NbBundle;
import org.openide.windows.TopComponent;
/**
* Top component which displays something.
*/
@TopComponent.Description(
preferredID = "DAppTopComponent",
//iconBase="SET/PATH/TO/ICON/HERE",
persistenceType = TopComponent.PERSISTENCE_NEVER
)
@TopComponent.Registration(mode = "editor", openAtStartup = false)
public class DAppTopComponent extends TopComponent {
private static final AtomicInteger ID = new AtomicInteger();
private final String PREFERRED_ID; // 20200802
final LwjglAWTCanvas lwjglAWTCanvas;
/**
* Creates new form DAppTopComponent
*/
public DAppTopComponent() {
initComponents();
lwjglAWTCanvas = new LwjglAWTCanvas(new MyGdxGame());
this.add("Center", lwjglAWTCanvas.getCanvas());
// 这是一个新打开的窗口,生成新的窗口id并保存
int id = ID.incrementAndGet();
PREFERRED_ID = NbBundle.getMessage(DAppTopComponent.class, "ID_DAppTopComponent", Integer.toString(id));
}
/**
* This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
setLayout(new java.awt.BorderLayout());
}// </editor-fold>
// 覆盖此方法,为TopComponent设置preferredID
// Subclasses are encouraged to override this method to provide preferred value for unique TopComponent ID returned
// by WindowManager.findTopComponentID(org.openide.windows.TopComponent). Returned value should be a String, preferably
// describing semantics of TopComponent subclass, such as "PieChartViewer" or "HtmlEditor" etc. Value is then used by window
// system as prefix value for creating unique TopComponent ID. Returned String value should be preferably unique, but need not be.
@Override
protected String preferredID() {
return PREFERRED_ID;
}
void writeProperties(java.util.Properties p) {
// better to version settings since initial version as advocated at
// http://wiki.apidesign.org/wiki/PropertyFiles
p.setProperty("version", "1.0");
// TODO store your settings
}
void readProperties(java.util.Properties p) {
String version = p.getProperty("version");
// TODO read your settings according to their version
}
// Variables declaration - do not modify
// End of variables declaration
}
package com.acuilab.bc.main.dapp;
/**
*
* @author admin
*/
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class MyGdxGame extends ApplicationAdapter {
SpriteBatch batch;
Texture img;
@Override
public void create() {
batch = new SpriteBatch();
img = new Texture("badlogic.jpg");
}
@Override
public void render() {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(img, 0, 0);
batch.end();
}
@Override
public void dispose() {
batch.dispose();
img.dispose();
}
}

