Swing draw points

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • KiddoGuy
    New Member
    • Nov 2008
    • 17

    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?
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by KiddoGuy
    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?
    A bar basically is just a rectangle; a Graphics object can draw rectangles.

    kind regards,

    Jos

    Comment

    • KiddoGuy
      New Member
      • Nov 2008
      • 17

      #3
      Ok, thanks. Can you give me a sample usage? Or is something like this correct?
      Code:
      java.awt.Panel panel = new java.awt.Panel();
      panel.getGraphics().drawRect(1,2,3,4);
      Would something like that work?

      Comment

      • KiddoGuy
        New Member
        • Nov 2008
        • 17

        #4
        Actually, now my problem is when I'm trying to draw on a Panel. When I call getGraphics() it returns null...

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by KiddoGuy
          Actually, now my problem is when I'm trying to draw on a Panel. When I call getGraphics() it returns null...
          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

          Comment

          Working...