BP Forums
Draw on JPanel - Printable Version

+- BP Forums (https://bpforums.info)
+-- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=55)
+--- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=56)
+---- Forum: Java (https://bpforums.info/forumdisplay.php?fid=19)
+----- Forum: Programming Help (https://bpforums.info/forumdisplay.php?fid=30)
+----- Thread: Draw on JPanel (/showthread.php?tid=829)



Draw on JPanel - yomarius95 - 04-10-2014

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!


Re: Draw on JPanel - brandonio21 - 06-17-2014

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 -->