Hi I am trying to create simple shapes such as a rectangle and view it in the android emulator , I do not want to use android xml but java code as I will need to apply an accelerometer to it. I am using eclipse but I do not understand how I can use JPanel as eclipse doesn't recognise it, do I have to install a plugin to be able to import JPanel and is that the correct way to go about creating shapes for android?
Any help would be helpful thank you.
Using java and android in eclipse.
JPanel is a swing component and not part of the Android SDK. You need to extend a view and draw using a canvas by overriding onDraw() or look into OpenGL if you want go into 3D drawing
Related
Iam making a level editor for libgdx.but I want to use the java swing buttons. how can I put the libgdx display inside a JFrame
LibGDX really isn't meant to work with swing components, but LibGDX does provide its own button classes like ImageButton or TextButton that you can use for the same purpose. It does take a little bit more work to set them up because you need to provide the background image and font that the button uses.
See the accepted answer here for how to setup text buttons:
How to create a button in Libgdx?
I have a problem with libgdx. I want to use Screen from libgdx to draw game inside JPanel (from Swing, because my all app is written in Swing). I've tried, but I cannot do that.
Is it possible? Have you got any code examples?
Please for help and sorry for my english (just in case).
Here is a good solution:
https://stackoverflow.com/a/21258666
It uses LWJGLCanvas to embed libGDx inside a JPanel
I imported a libgdx project into Android Studio to create the UI for my app. I tried to open the designer to easily add items to the UI, however the design tab from View > Tool Windows > Designer is grayed out. I assume it's because it's an imported project, would be great if anyone knew of a way to open the designer, thanks!
Scene2D comes with LibGdx which is usually used to create everything related to UI. I wouldn't recommend to use default Android UI with LibGdx game.
Here is some documentation an tutorials how to use Scene2D in your LibGdx project:
https://github.com/libgdx/libgdx/wiki/Scene2d
It's also recommended to use Ninepatch for your UI elements such as buttons so it can scale the buttons and other elements correctly. There is also a documentation and tutorial for that here:
https://github.com/libgdx/libgdx/wiki/Ninepatches
I am trying to display some text in lwjgl in java but I dont want to use slick library, do you know if there is any other way to show some text in java using lwjgl ? If so, which external libraries I need to import ??
Unfortunately it's not possible. Either draw it pixel by pixel or use a library. You'll only need slick-util for drawing text, so it shouldn't be a problem. You can find the javadocs here.
Well, the only way I know is to create a java awt image and draw the text on it (using awt) and then pass it to opengl. So, just create a BufferedImage, get its graphics context and write on it using the methods in that. Shouldn't be too hard.
A simple question: Is it possible to view gui of java Swing library and lwjgl 3D scene in the same window without using any additional gui libraries? How?
You can use the method Display.setParent(java.awt.Canvas) to put the LWJGL display on a canvas. You can then incorporate this canvas into your Swing GUI. Please note that there may be slight performance issues with said approach.