469,332 Members | 6,612 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,332 developers. It's quick & easy.

Swing draw points

I want to loop through an array of numbers and use those to plot points. What method should I be thinking of? I know there's one that takes an X and Y coordinate and draws points. Is there one that draws bars, too?
Nov 24 '08 #1
4 5229
JosAH
11,448 Expert 8TB
@KiddoGuy
A bar basically is just a rectangle; a Graphics object can draw rectangles.

kind regards,

Jos
Nov 25 '08 #2
Ok, thanks. Can you give me a sample usage? Or is something like this correct?
Expand|Select|Wrap|Line Numbers
  1. java.awt.Panel panel = new java.awt.Panel();
  2. panel.getGraphics().drawRect(1,2,3,4);
  3.  
Would something like that work?
Nov 25 '08 #3
Actually, now my problem is when I'm trying to draw on a Panel. When I call getGraphics() it returns null...
Nov 25 '08 #4
JosAH
11,448 Expert 8TB
@KiddoGuy
Read Sun's Swing tutorial. The AWT event dispatch thread calls the paint() method which calls the paintComponent() method; that's the method you have to override (re-implement) if you want to draw your own stuff. Your approach is not going to work.

kind regards,

Jos
Nov 25 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Chris | last post: by
6 posts views Thread by Joseph | last post: by
2 posts views Thread by frank_ulbricht | last post: by
4 posts views Thread by thomasp | last post: by
1 post views Thread by balakrishnan.dinesh | last post: by
5 posts views Thread by lgeastwood | last post: by
3 posts views Thread by aleplgr | last post: by
6 posts views Thread by r035198x | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by haryvincent176 | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.