public class pan extends JPanel
    {
        public void paintComponent(Graphics g)
               {
            super.paintComponent(g);
            Color col1=jc.getColor();
            g.setColor(col1);
            g.drawRect( 30,30,800,600);//600 = width 400 = height
            for(int i=30;i<=620; i=i+20)
            {   
            g.drawLine(30,i,830,i);       //for Horizontal lines change only y value (both shud be same) and x shud be 0
            }
            g.setColor(Color.white);

            for( Integer i=10;i<=620; i=i+20)
            {
                k=Integer.toString(i);
            g.drawString(k,5,i+27);

            }
            for(Integer i=10;i<=820; i=i+20)
            {
                k=Integer.toString(i);
            g.drawString(k,i+5,650);

            }
            g.setColor(col1);
            for(int i =0;i<=800;i=i+20)
            g.drawLine(i+30,30,i+30,630);                                                 //or vertical line keep y1 n y2 constant (both shud be same)
            /*public void draw()
                {
                g.setColor(Color.BLUE);
                try {
                    for(int i =0;i<=800;i=i+20)
                    {

                        //t.sleep(120);
                    g.drawLine(120+i,90+i,87+i,88+i);   
                    }
                      }
                    catch(InterruptedException e)
                    {
                    System.out.println("KK");
                    }
                                    }*/

have drawn a horizontal n vertical grids...so my requirement is when i press a button on my interface ...a line graph shud be drawn on the panel....The graph shud be dynamic graph... ...plz help,,,also how can i use drawLine method for float values to drwa a graph....

            }

          }

It's much easier to use a GeneralPath for drawing arbitrary shapes such as a graph. It is basically just a series of connected points. Here is the tutorial link for it: http://java.sun.com/docs/books/tutorial/2d/geometry/index.html

It accomplishes the same thing as many drawLine() calls between all of the points.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.