Hello

I'm new to java and i'm facing some problem... First code refers to File_Chooser class which works perfectly fine for me...

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package statguis;

/**
 *
 * @author Umar Ali
 */
import java.awt.*;
import javax.swing.JFrame;
//import BreezyGUI.*;

public class lineonly extends Frame
{
   //Establish the placement of the fields for user entry

   //Establish a drop down menu for the drawing
   //Right now we only have one choice -- Line
   
  //Establish variables for this program
   int numberOfScores = 5;
   int Xleft = 100;
   int Xright = 300;
   int Ytop = 100;  // The y-value entries can be up to 250-100=150.
   int Ybottom = 250;

   int totalX, totalY;
   int[ ] scores;
   char graphChoice;

   //Constructor to establish the initial values in the program
   public lineonly ( )
   {
       scores = new int[numberOfScores];
       for (int i = 0; i < scores.length;  i++)
                 scores[ i ] = 0;
      totalX = Xright - Xleft + 1;
      totalY = Ybottom - Ytop + 1;
      graphChoice = 'L';
   }

   //Allow for the menu choices
   //Remember, we only have one choice right now
  //Establish the paint method
   public void paint (Graphics g)
   {
        getInputData();
        g.setColor (Color.red);   //set color of the graph
        drawLineGraph(g);
        g.drawString("Java Grades", 170, 290); // title
   }

  //Get input from user
   public void getInputData()
   {
       scores[0] = 5;
       scores[1] = 1;
       scores[2] = 5;
       scores[3] = 3;
       scores[4] = 5;
   }

    //Draw the line graph
   public void drawLineGraph(Graphics g)
   {
        drawAxes(g);
        int i, x1, y1, x2, y2, largestNumber, xIncrement, yIncrement;
       //Compute the x and y increments
       largestNumber = findLargest (scores);
       xIncrement = totalX / numberOfScores;
       if (largestNumber ==0)
               yIncrement = 0;
       else
               yIncrement = totalY / largestNumber;

      //Set the initial origin point
       x1 = Xleft;
       y1 = Ybottom;

      //Compute and plot the data points
       for(i=0; i < numberOfScores; i++)
      {
          x2 = getXCoordinate(i+1, xIncrement);
          y2 = getYCoordinate(scores[i], yIncrement);
          g.fillOval(x2, y2, 5, 5);
          g.drawLine(x1, y1, x2, y2);
          x1 = x2;
          y1 = y2;
       }
      //Label x - axes with grade choices
      String [ ] label = {"A", "B", "C", "D", "F"};
      for (i=1; i<=numberOfScores; i++)
          g.drawString(label[i-1], 100+ i*xIncrement, 270);

      //Label y - axes with quantity of each grade
      int topy;
      if(largestNumber%10==0)
           topy=largestNumber;
      else
           topy = (largestNumber/10+1)*10;

      // i = i+5 controls y value label -- adjust for size of data
      for (i = 0; i <= topy; i = i+5)
      {
          g.drawString(String.valueOf(i), 70, Ybottom-i*yIncrement+5);
      }
   }

  //Draw the axes for the graph
   public void drawAxes (Graphics g)
   {
        g.drawLine(Xleft, Ytop, Xleft, Ybottom);
        g.drawLine(Xleft, Ybottom, Xright, Ybottom);

   }

  //Determining x coordinate
   public int getXCoordinate(int i, int xIncrement)
   {
       return Xleft + xIncrement *i;
   }

   //Determining y coordinate
   public int getYCoordinate(int numStudents, int yIncrement)
   {
       return Ybottom - yIncrement * numStudents;
   }

   //Finding the largest value in the array
   public int findLargest(int [ ] a)
   {
       int location = 0;
      for( int i = 1; i < a.length; i++)
                 if(a[i] > a[location])
                       location = i;
     return a[location];
   }

  //Main
   public static void main(String[ ] args)
   {
       Frame frm = new lineonly();
       frm.setSize (400, 300);
       frm.setVisible (true);
   }
}

Here's another class lineonly - being used to plot graph.

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package statguis;

/**
 *
 * @author Umar Ali
 */
import java.awt.*;
import javax.swing.JFrame;
//import BreezyGUI.*;

public class lineonly extends Frame
{
   //Establish the placement of the fields for user entry

   //Establish a drop down menu for the drawing
   //Right now we only have one choice -- Line
   
  //Establish variables for this program
   int numberOfScores = 5;
   int Xleft = 100;
   int Xright = 300;
   int Ytop = 100;  // The y-value entries can be up to 250-100=150.
   int Ybottom = 250;

   int totalX, totalY;
   int[ ] scores;
   char graphChoice;

   //Constructor to establish the initial values in the program
   public lineonly ( )
   {
       scores = new int[numberOfScores];
       for (int i = 0; i < scores.length;  i++)
                 scores[ i ] = 0;
      totalX = Xright - Xleft + 1;
      totalY = Ybottom - Ytop + 1;
      graphChoice = 'L';
   }

   //Allow for the menu choices
   //Remember, we only have one choice right now
  //Establish the paint method
   public void paint (Graphics g)
   {
        getInputData();
        g.setColor (Color.red);   //set color of the graph
        drawLineGraph(g);
        g.drawString("Java Grades", 170, 290); // title
   }

  //Get input from user
   public void getInputData()
   {
       scores[0] = 5;
       scores[1] = 1;
       scores[2] = 5;
       scores[3] = 3;
       scores[4] = 5;
   }

    //Draw the line graph
   public void drawLineGraph(Graphics g)
   {
        drawAxes(g);
        int i, x1, y1, x2, y2, largestNumber, xIncrement, yIncrement;
       //Compute the x and y increments
       largestNumber = findLargest (scores);
       xIncrement = totalX / numberOfScores;
       if (largestNumber ==0)
               yIncrement = 0;
       else
               yIncrement = totalY / largestNumber;

      //Set the initial origin point
       x1 = Xleft;
       y1 = Ybottom;

      //Compute and plot the data points
       for(i=0; i < numberOfScores; i++)
      {
          x2 = getXCoordinate(i+1, xIncrement);
          y2 = getYCoordinate(scores[i], yIncrement);
          g.fillOval(x2, y2, 5, 5);
          g.drawLine(x1, y1, x2, y2);
          x1 = x2;
          y1 = y2;
       }
      //Label x - axes with grade choices
      String [ ] label = {"A", "B", "C", "D", "F"};
      for (i=1; i<=numberOfScores; i++)
          g.drawString(label[i-1], 100+ i*xIncrement, 270);

      //Label y - axes with quantity of each grade
      int topy;
      if(largestNumber%10==0)
           topy=largestNumber;
      else
           topy = (largestNumber/10+1)*10;

      // i = i+5 controls y value label -- adjust for size of data
      for (i = 0; i <= topy; i = i+5)
      {
          g.drawString(String.valueOf(i), 70, Ybottom-i*yIncrement+5);
      }
   }

  //Draw the axes for the graph
   public void drawAxes (Graphics g)
   {
        g.drawLine(Xleft, Ytop, Xleft, Ybottom);
        g.drawLine(Xleft, Ybottom, Xright, Ybottom);

   }

  //Determining x coordinate
   public int getXCoordinate(int i, int xIncrement)
   {
       return Xleft + xIncrement *i;
   }

   //Determining y coordinate
   public int getYCoordinate(int numStudents, int yIncrement)
   {
       return Ybottom - yIncrement * numStudents;
   }

   //Finding the largest value in the array
   public int findLargest(int [ ] a)
   {
       int location = 0;
      for( int i = 1; i < a.length; i++)
                 if(a[i] > a[location])
                       location = i;
     return a[location];
   }

  //Main
   public static void main(String[ ] args)
   {
       Frame frm = new lineonly();
       frm.setSize (400, 300);
       frm.setVisible (true);
   }
}

I want help with this issue - in File_Chooser class, after i select the file, it should switch to graph frame (class lineonly). I tried alot, but i'm not able to fix that.. :(
Please help!!

Thanks

You posted the same class twice.

But if you intend to graph whatever is chosen in your file chooser class, you will need to provide some method to pass that info into your graphing class. That could be in the constructor or a public method.

thanks man!! i was making an extreme blunder

Be a part of the DaniWeb community

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