1

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.

user1169775
  • 43
  • 2
  • 8
  • Take a look at `ShapeDrawable` in the Android API. http://developer.android.com/guide/topics/graphics/2d-graphics.html#shape-drawable – Danny Feb 06 '12 at 19:24
  • I have tried this but when I run it, it force closes, think I am using it wrong, do I have to do it through xml and if not do I have to use the ondraw method to print the shape into the emulator? – user1169775 Feb 06 '12 at 21:47
  • You have to add the custom view you create through xml. All of the drawing of shapes can be done in the onDraw method. – Danny Feb 07 '12 at 15:55

1 Answers1

0

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

triggs
  • 5,890
  • 3
  • 32
  • 31