Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Draw on JPanel
#1
Can someone explaine to me how to draw on JPanel?
I want to make the snake game a runnable jar.


Here is the Project archive.
https://www.dropbox.com/s/hp7ga6mce34uu1g/Snake0.jar

Thanks!
#2
My apologies for the delay. As far as drawing on a JPanel goes, you would need to follow the standard procedure of all Canvas-esque Java objects.

1) Get the graphics object of the JPanel
2) Create the object you want to draw
3) Have the graphics object draw that object

These pages may help you:
<!-- m --><a class="postlink" href="http://docs.oracle.com/javase/7/docs/api/javax/swing/JPanel.html">http://docs.oracle.com/javase/7/docs/ap ... Panel.html</a><!-- m -->

<!-- m --><a class="postlink" href="http://docs.oracle.com/javase/7/docs/api/javax/swing/JComponent.html#getGraphics(">http://docs.oracle.com/javase/7/docs/ap ... tGraphics(</a><!-- m -->)

<!-- m --><a class="postlink" href="http://docs.oracle.com/javase/7/docs/api/java/awt/Graphics.html">http://docs.oracle.com/javase/7/docs/ap ... phics.html</a><!-- m -->
My Blog | My Setup | My Videos | Have a wonderful day.


Forum Jump:


Users browsing this thread: 1 Guest(s)