-1

I have and array full of a random number of points, I want to draw them in my panel, how can I do it? there is some methods?? I searched around the internet but nothing.... Can I do it with the graphics2d class?

Hope my question is clear enough.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
  • Your question is clear but appears far too broad and shows none of your own code attempts. If you still need help after reading the duplicate and after going through the basic Java Swing Graphics Tutorial: [Lesson: Performing Custom Painting](http://docs.oracle.com/javase/tutorial/uiswing/painting/index.html), then [edit] the question, include your code attempt and tell us your most *specific* problem with *your code*. – Hovercraft Full Of Eels Aug 20 '23 at 15:51
  • But to answer your direct question, yes of course you can do it with the Graphics and Graphics2D class. As the tutorial will show you, draw the points in your JPanel's paintComponent method. This is all very well explained in the tutorial linked to above, and you would do well to study it. – Hovercraft Full Of Eels Aug 20 '23 at 15:53
  • Also, regarding "*I searched around the internet but nothing...*" which suggests that your searching technique is off. You're probably trying too specific a search, and instead should search on more general topics, such as drawing on JPanels, and such. – Hovercraft Full Of Eels Aug 20 '23 at 15:54
  • If you have questions, please feel free to comment below. Also, I suggest your checking out the [ask] and [tour] links to help you get a handle on best uses of the site. Good luck. – Hovercraft Full Of Eels Aug 20 '23 at 15:55
  • Also, as a side note, if you're drawing an *array* of points, then of course you will need to iterate through them using a for loop, again within the JPanel's `protected void paintComponent(Graphics g)` method. If you want to draw *outside* of this method, then consider drawing onto a BufferedImage, and then displaying the image either in your JPanel's paintComponent method or in a JLabel as an ImageIcon. Lot's of options here. – Hovercraft Full Of Eels Aug 20 '23 at 15:59

0 Answers0