471,887 Members | 1,304 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,887 software developers and data experts.

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 5328
11,448 Expert 8TB
A bar basically is just a rectangle; a Graphics object can draw rectangles.

kind regards,

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);
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
11,448 Expert 8TB
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,

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
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.