No initial paint of plot

Discussion in 'Software' started by Coder Ken, Jan 2, 2009.

  1. Coder Ken

    Coder Ken

    Joined:
    Jan 1, 2009
    Messages:
    2
    I am writing a java program to plot some data in java 2D. The program does not perform the initial paint(). If I change the size of the frame by pulling it, it plots and all the subsequent repaint()'s work. How do I perform the intial plot? Here is how the code looks now:

    Code:
    public class SoundEnvelope extends JPanel { 
    
       public void paintComponent(Graphics g) {
          clear(g);  // See clear method below
          Graphics2D g2d = (Graphics2D)g;  // Cast Graphics Object to Graphics2D
          int startData = dm.getStartPlotIndex();
    
    //     Then I set up the x and y values at each end of the line for the signal wave I am plotting. 
    //     The x/y values are called lastX, lastY and kurntX, kurntY.  Here is the plotting code:
    
          double lastX = 4.0;
          double ratio = dm.getCrtSizeY()/264; // Y values range from -128 to 127
                                                            //  plus pad to 132 to -132
          double lastY = computeY(wavFile[startData], ratio);
          double kurntX = 0.0;
          double kurntY = 0.0;
          Line2D.Double line;
    
          for( int i = (startData + 1); i < eof; i++)  {  // eof is the index to the last
                                                                     // byte in the .wav file
             kurntX+=incrementX;  // I have tried various values for this and not
                                           // sure what looks best.  Any suggestions?
            kurntY = computeY(wavFile[i], ratio);
    
             line = new Line2D.Double(lastX, lastY, kurntX, kurntY);  
             g2d.draw(line);
    
             lastX = kurntX;
             lastY = kurntY;
    
          }  // END OF:  for(int i = (startData + 1); i < eof; i++)
    
       }   // END OF: paintComponent(Graphics g)
    
    Here are the clear() and computeY() methods used in the above method:

    Code:
    
       protected void clear(Graphics g) {
          super.paintComponent(g);  // super.paintComponent clears offscreen
                                              //  pixmap,since double buffering is used 
                                              //  by default.
       }
    
    
       protected double computeY(byte val, double ratio)  {
          return (double)((150 - (val/3))*ratio);  // Just scaled to fit on JPanel
       }
    
    

    Any idea how to make the intial plot?

    Thanks for your help -
    Coder Ken
     
    Last edited: Jan 2, 2009
    Coder Ken, Jan 2, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Annette Kurten

    Have I lost the plot???

    Annette Kurten, Apr 5, 2004, in forum: Computer Support
    Replies:
    24
    Views:
    859
    Avenger©
    Apr 6, 2004
  2. Richard Owlett
    Replies:
    2
    Views:
    2,830
    Richard Owlett
    May 22, 2004
  3. Rutgar

    ALIENS - Major Plot Hole

    Rutgar, Dec 14, 2003, in forum: DVD Video
    Replies:
    22
    Views:
    1,882
    jayembee
    Dec 19, 2003
  4. Winfield

    The Plot ... Thickens

    Winfield, Sep 20, 2007, in forum: DVD Video
    Replies:
    0
    Views:
    445
    Winfield
    Sep 20, 2007
  5. impossible

    Have Free Software ideologues lost the plot?

    impossible, Jul 10, 2007, in forum: NZ Computing
    Replies:
    75
    Views:
    1,357
    -=rjh=-
    Jul 24, 2007
Loading...

Share This Page