473,461 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

non-static variable calcGrade cannot be referenced from a static context

I am working on a major project. I keep getting the error non-static variable calcGrade cannot be referenced from a static context calcGrade.studentList[s] = new Student();

Expand|Select|Wrap|Line Numbers
  1. import java.util.*;  
  2.    import java.io.*;
  3.    import javax.swing.*; 
  4.    import java.awt.*; 
  5.    import java.awt.event.*; 
  6.  
  7.     public class GradeCalculator extends JFrame 
  8.     { 
  9.       private static final int WIDTH = 550; 
  10.       private static final int HEIGHT = 430; 
  11.  
  12.       private static final int MAX_NUMBER_OF_STUDENTS = 20; 
  13.  
  14.                 // instance variables 
  15.       String Student[] = new String[MAX_NUMBER_OF_STUDENTS]; 
  16.       private int noOfStudents; 
  17.       private double score, tst1, tst2, tst3; 
  18.       private double  classAvg, stAvg, totalScore; 
  19.       private int displayedStudentIndex = 0; 
  20.       private char ltrGrade; 
  21.       private String stName; 
  22.  
  23.                 // This area is for the GUI components 
  24.                 // Each item that will be displayed will 
  25.                 // have a label and a textfield, (L) and (TF),  
  26.                 // respectively. 
  27.       private JLabel stNameL, tst1L, tst2L, tst3L, 
  28.                                         classAvgL, stAvgL, headingL; 
  29.       private JTextField stNameTF, tst1TF, tst2TF, tst3TF; 
  30.       private JTextArea classAvgTA, stAvgTA; 
  31.       private JButton exitB, nextB, prevB, calcGrade; 
  32.  
  33.       private ButtonHandler bHandler; 
  34.  
  35.        public GradeCalculator() 
  36.        { 
  37.          setTitle("Grade Calculator");           // set's the title 
  38.          setSize(WIDTH, HEIGHT);                 // set the window size 
  39.          Container pane = getContentPane();      // get the container 
  40.          pane.setLayout(null);                   // set the container's layout to null 
  41.  
  42.          bHandler = new ButtonHandler();         // instantiate the button event handler 
  43.  
  44.                 // instantiate the labels 
  45.          headingL = new JLabel("STUDENT RECORD"); 
  46.          stNameL = new JLabel("Studen Name", SwingConstants.RIGHT); 
  47.          tst1L = new JLabel("Test 1", SwingConstants.LEFT); 
  48.          tst2L = new JLabel("Test 2", SwingConstants.LEFT); 
  49.          tst3L = new JLabel("Test 3", SwingConstants.LEFT); 
  50.          stAvgL = new JLabel("Student Average     " 
  51.                                                 + "\n"   + "Class Average"); 
  52.                 //instantiate the text fields 
  53.          stNameTF = new JTextField(65); 
  54.          tst1TF = new JTextField(10); 
  55.          tst2TF = new JTextField(10); 
  56.          tst3TF = new JTextField(10); 
  57.  
  58.                 // instantiate the text area 
  59.          classAvgTA = new JTextArea(6, 20); 
  60.          classAvgTA.setAutoscrolls(true); 
  61.  
  62.                 // instantiate the buttons and register the listener 
  63.          exitB = new JButton("Exit"); 
  64.          exitB.addActionListener(bHandler); 
  65.  
  66.          nextB = new JButton("Next"); 
  67.          nextB.addActionListener(bHandler); 
  68.  
  69.          prevB = new JButton("Previous"); 
  70.          prevB.addActionListener(bHandler); 
  71.  
  72.          calcGrade = new JButton("Calc Grade"); 
  73.          calcGrade.addActionListener(bHandler); 
  74.  
  75.                 // set the size of the labels, text fields, and buttons 
  76.  
  77.          headingL.setSize(200, 30); 
  78.          stNameL.setSize(100, 30); 
  79.          stNameTF.setSize(100, 30); 
  80.          tst1L.setSize(100, 30); 
  81.          tst1TF.setSize(100, 30); 
  82.          tst2L.setSize(120, 30); 
  83.          tst2TF.setSize(100, 30); 
  84.          tst3L.setSize(100, 30); 
  85.          tst3TF.setSize(100, 30); 
  86.          classAvgTA.setSize(370, 120); 
  87.          calcGrade.setSize(100, 30); 
  88.          prevB.setSize(100, 30);
  89.          nextB.setSize(100, 30); 
  90.          exitB.setSize(100, 30); 
  91.  
  92.                 //set the location of the labels, text fields, 
  93.                 //and buttons 
  94.          headingL.setLocation(220, 10); 
  95.          stNameL.setLocation(20, 50); 
  96.          stNameTF.setLocation(120, 50); 
  97.          tst1L.setLocation(20, 100); 
  98.          tst1TF.setLocation(120, 100); 
  99.          tst2L.setLocation(300, 50); 
  100.          tst2TF.setLocation(420, 50); 
  101.          tst3L.setLocation(300, 100); 
  102.          tst3TF.setLocation(420, 100); 
  103.          classAvgTA.setLocation(70, 230); 
  104.          prevB.setLocation(120, 370); 
  105.          exitB.setLocation(220, 370); 
  106.          nextB.setLocation(320, 370); 
  107.          calcGrade.setLocation(420, 370); 
  108.  
  109.                 //add the labels, text fields, and buttons to the pane 
  110.          pane.add(headingL); 
  111.          pane.add(stNameL); 
  112.          pane.add(stNameTF); 
  113.          pane.add(tst1L); 
  114.          pane.add(tst1TF); 
  115.          pane.add(tst2L); 
  116.          pane.add(tst2TF); 
  117.          pane.add(tst3L); 
  118.          pane.add(classAvgTA); 
  119.          pane.add(calcGrade); 
  120.          pane.add(prevB); 
  121.          pane.add(exitB); 
  122.          pane.add(nextB); 
  123.  
  124.          setVisible(true);         //show the window 
  125.          setDefaultCloseOperation(EXIT_ON_CLOSE); 
  126.          System.exit(0); 
  127.       } 
  128.  
  129.  
  130.  
  131.       public static void main (String [] args)
  132.       { 
  133.  
  134.             File file = new File("AcademicGrades.txt");
  135.             Scanner keyboard = new Scanner(System.in);
  136.             Scanner inputFile = new Scanner(file); 
  137.  
  138.  
  139.          for (int s = 0; s < MAX_NUMBER_OF_STUDENTS; s++) 
  140.             {
  141.             calcGrade.studentList[s] = new Student(); 
  142.  
  143.              gradeCalc.noOfStudents = 
  144.                         inputFile.nextInt();       // get the number of students 
  145.              gradeCalc.score = 
  146.                         inputFile.nextDouble();    // get the student's scores 
  147.  
  148.                gradeCalc.getStudentData(inputFile); 
  149.              gradeCalc.displayGradeAverage(0); 
  150.          }
  151.        }
  152.                         // get the student data from file 
  153.  
  154.  
  155.        public void getStudentData(Scanner inputFile) 
  156.        { 
  157.          System.out.println("Grade Calculator is getting information..."); 
  158.          System.out.println("One Moment Please"); 
  159.        } 
  160.        private class ButtonHandler implements ActionListener 
  161.        { 
  162.           public void actionPerformed (ActionEvent e) 
  163.           { 
  164.             if (e.getActionCommand().equals("Previous")) 
  165.                if (displayedStudentIndex > 0) 
  166.                   displayGradeAverage(displayedStudentIndex - 1); 
  167.                else 
  168.                   displayGradeAverage(displayedStudentIndex); 
  169.             else if (e.getActionCommand().equals("Next")) 
  170.                if (displayedStudentIndex + 1 < noOfStudents) 
  171.                   displayGradeAverage(displayedStudentIndex + 1); 
  172.                else 
  173.                   displayGradeAverage(displayedStudentIndex); 
  174.             else if (e.getActionCommand().equals("Calc Grade")) 
  175.                displayGradeAverage(0); 
  176.             else 
  177.                System.exit(0); 
  178.          } 
  179.        } 
  180.  
  181.        public void displayGradeAverage(int stName) 
  182.        { 
  183.              int studentList;
  184.          displayedStudentIndex = stName; 
  185.          String strName = ""; 
  186.          boolean classAvg = studentList[(int) (totalScore / noOfStudents)].getClassAverage(); 
  187.          stNameTF.setText(studentList[stName].getFirstName() + " " 
  188.                                                             + studentList[stName].getLastName());
  189.          stAvgTA.setText(""+studentList[(int) (totalScore / 5.0)].getStudentAverage());
  190.          classAvgTA.setText(""+studentList[(int) (totalScore / noOfStudents)].getClassAverage()); 
  191.        }
  192.      }
  193.  
Sep 16 '10 #1
8 5476
Oralloy
988 Expert 512MB
The reason its giving you troubles is that your student loop is in the main method at line 131:
Expand|Select|Wrap|Line Numbers
  1. public static void main (String [] args)
Main, you will notice, is a static method, and thus is not associated with any specific object. Whereas the attribute calcGrade is an attribute of the GradeCalculator class.

The problem being that you never actually instantiate a GradeCalculator object in your code. You just start banging on object attributes in main without creating any object at all.

What I think you need to do is move all the code from main into getStudentData, and insert code in main to instantiate a GradeCalculator and run the awt event loop.

First, though, you have to get through your compilation problems. Work those out, then the rest should be easy.

If you're in doubt, comment out sections of code until you can display a minimal, working window, then re-enable code from there.
Sep 16 '10 #2
Static methods cannot access non-static variables. Static fields, methods are initialized before non-static fields.
Sep 16 '10 #3
No Im gettn this cannot find symbols:
Expand|Select|Wrap|Line Numbers
  1.    import javax.swing.*;         //needed for swing classes
  2.    import java.awt.event.*;     // needed for the action listener
  3.    import java.awt.*;            //needed for the boader layout class
  4.    import java.io.*;             //need for the file and IOException
  5.    import java.util.Scanner;    // needed for the scanner class
  6.    import java.util.List;      // needed for the  arraylist
  7.    import java.util.Arrays;      //needed for the arraylict class
  8.  
  9.     /**
  10.         Constructor
  11.     */
  12.  
  13.  
  14.    public class project3 extends JFrame 
  15.    {
  16.  
  17.       public gradeTypePanel gradeType; //to reference the the grade Type Panel with the radio buttons
  18.       public namePanel name; // to reference the name panel with the name text field
  19.       public testPanel test;// to reference the test panel with the 3 test grade fields
  20.       public resultPanel result;// to reference the result panel with the result text field
  21.       private JPanel panel; // to reference the a  panel
  22.       private JButton calcButton; // creats the Button named calcButton
  23.       private JButton prevButton; // creats the Button named prevButton
  24.       private JButton nextButton; // creats the Button named nextButton
  25.       private JButton saveButton; // creats the Button named saveButton
  26.       private JPanel buttonPanel; // to  reference the panel where all the buttons go
  27.       public openFile open;// to reference the open file class
  28.       public int masterIndex = -1; // this controls all the of the indexes of all 4 arrays
  29.  
  30.        // constructs the window
  31.       public project3()
  32.       {
  33.          // sets the title
  34.          setTitle("Grade Program");
  35.          // set what happens when the exit button is clicked
  36.          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  37.          // sets the border layout
  38.          setLayout(new BorderLayout());
  39.          //calls the resultPanel class and names it result
  40.          result = new resultPanel();
  41.          //calls the gradeTypePanel and names it gradeType
  42.          gradeType = new gradeTypePanel();
  43.          //calls the namePanel and names it name
  44.          name = new namePanel();
  45.          //calls the testPanel and names it test
  46.          test = new testPanel();
  47.  
  48.           //builds the button panel
  49.          buildButtonPanel();
  50.  
  51.           //adds all of the panels to the north, south, east, west, and center panels
  52.          add(name, BorderLayout.NORTH);  
  53.          add(gradeType, BorderLayout.WEST);
  54.          add(test, BorderLayout.CENTER);
  55.          add(buttonPanel, BorderLayout.EAST);
  56.          add(result, BorderLayout.SOUTH);
  57.  
  58.           // packs all the panels togather
  59.          pack();
  60.  
  61.           //makes the window visable
  62.          setVisible(true);
  63.       }
  64.  
  65.       //builds the panel for the buttons
  66.       private void buildButtonPanel()
  67.       {
  68.  
  69.          buttonPanel = new JPanel();
  70.  
  71.  
  72.          prevButton = new JButton("Prev");// adds the text prev to the prevButton
  73.          calcButton = new JButton("Calc Grade");// adds the text Calc Grade to the calcButton
  74.          nextButton = new JButton("Next");// adds the text Next to the nextButton 
  75.          saveButton = new JButton("Save");// adds the text Save to the saveButton
  76.  
  77.  
  78.          calcButton.addActionListener(new CalcButtonListener());// calls the  ActionListener for the calcButton
  79.          prevButton.addActionListener(new PrevButtonListener());// calls the  ActionListener for the prevButto
  80.          nextButton.addActionListener(new NextButtonListener());// calls the  ActionListener for the nextButton
  81.          saveButton.addActionListener(new SaveButtonListener());// calls the  ActionListener for the addButton
  82.  
  83.  
  84.          buttonPanel.add(prevButton);// adds the prevButton to the panel
  85.          buttonPanel.add(saveButton);// adds the saveButton to the panel
  86.          buttonPanel.add(nextButton);// adds the nextButton to the panel
  87.          buttonPanel.add(calcButton);// adds the calcButton to the panel
  88.  
  89.  
  90.       }
  91.        //creats actionlistener for the Calc Grade button
  92.       private class CalcButtonListener implements ActionListener
  93.       {
  94.           // executes when the button is clickd 
  95.          public void actionPerformed(ActionEvent e)
  96.          {
  97.            //if masterIndex = -1 then you are not at index 0 of the arrays so you cant calculate
  98.             if(masterIndex != -1)
  99.             {
  100.                String nameText;// to save the text in the name text field
  101.                nameText = name.txtname.getText();//gets the text form name text field
  102.                String grade1;// to save the text in the test1 text field
  103.                grade1 = test.test1TextFild.getText();//gets the text form test1 text field
  104.                String grade2;// to save the text in the test2 text field
  105.                grade2 = test.test2TextFild.getText();//gets the text form test2 text field
  106.                String grade3;// to save the text in the test3 text field
  107.                grade3 = test.test3TextFild.getText();//gets the text form test3 text field
  108.  
  109.                //if the text in all 3 text field are  <= 100 calculate
  110.                if(Double.parseDouble(grade1) <= 100 && Double.parseDouble(grade2) <= 100 && Double.parseDouble(grade3) <= 100)
  111.                {
  112.                   //convert and add all 3 grades together
  113.                   double totalGrade = Double.parseDouble(grade1) + Double.parseDouble(grade2) + Double.parseDouble(grade3); 
  114.                    //get the the avarage
  115.                   double NumberGrade = (totalGrade / 300) * 100;
  116.                    //to hold the letter grade
  117.                   String letterGrade;
  118.                   //if the alphabetical radio button is Selected get the letter grade
  119.                   if(gradeType.alphabetical.isSelected())
  120.  
  121.                   {
  122.  
  123.  
  124.                      if(NumberGrade >= 90)
  125.                      {
  126.                         //sets letter grade to A
  127.                         letterGrade = "A";
  128.                          //display the result in the result text field
  129.                         result.textResult.setText(letterGrade);
  130.  
  131.                      }
  132.                      else if(NumberGrade >= 80)
  133.                      {
  134.                         //sets letter grade to B
  135.                         letterGrade = "B";
  136.                          //display the result in the result text field
  137.                         result.textResult.setText(letterGrade);
  138.                      }
  139.                      else if(NumberGrade >= 70)
  140.                      {
  141.                         //sets letter grade to C
  142.                         letterGrade = "C";
  143.                          //display the result in the result text field
  144.                         result.textResult.setText(letterGrade);
  145.                      }
  146.                      else if(NumberGrade >= 60)
  147.                      {
  148.                         //sets letter grade to D
  149.                         letterGrade = "D";
  150.                          //display the result in the result text field
  151.                         result.textResult.setText(letterGrade);
  152.                      }
  153.                      else if(NumberGrade < 60)
  154.                      {
  155.                         //sets letter grade to F
  156.                         letterGrade = "F";
  157.                          //display the result in the result text field
  158.                         result.textResult.setText(letterGrade);
  159.                      }
  160.  
  161.  
  162.                   }
  163.                    //if numerical is Selected get the number grade
  164.                   if(gradeType.numerical.isSelected())
  165.                   {
  166.                      //display the result in the result text field
  167.                      result.textResult.setText(Double.toString(NumberGrade));
  168.                   }
  169.                }
  170.                else
  171.                {
  172.                   //displays error message when all grades are not <= 100
  173.                   JOptionPane.showMessageDialog(null, "All Grades must be less than or equal to (100)");
  174.                }
  175.             }
  176.             else
  177.             {
  178.                 //shows error message when masterIndex == -1
  179.                JOptionPane.showMessageDialog(null, "Please click (Next) first");
  180.             }
  181.  
  182.          }                                        
  183.       }
  184.       //creats actionlistener for the Calc prev button
  185.       private class PrevButtonListener implements ActionListener
  186.       {
  187.           // executes when the button is clickd gets the input and calcilates it
  188.          public void actionPerformed(ActionEvent e)
  189.          {
  190.             //if masterIndex is > 0 
  191.             if(masterIndex > 0)
  192.             { 
  193.                //decrament masterIndex by 1
  194.                masterIndex--;
  195.  
  196.                String[] nameList;//to store the array
  197.                String[] test1;//to store the array
  198.                String[] test2;//to store the array
  199.                String[] test3;//to store the array
  200.  
  201.  
  202.                try 
  203.                {
  204.  
  205.                   nameList = open.getArrayName();//get the nameList array from the class
  206.                   test1 = open.getArrayTest1();//get the test1 array from the class
  207.                   test2 = open.getArrayTest2();//get the test2 array from the class
  208.                   test3 = open.getArrayTest3();//get the test3 array from the class
  209.                   name.txtname.setText(nameList[masterIndex]);//populate the txtname text field with the array
  210.                   test.test1TextFild.setText(test1[masterIndex]);//populate the test1 text field with the array
  211.                   test.test2TextFild.setText(test2[masterIndex]);//populate the test2 text field with the array
  212.                   test.test3TextFild.setText(test3[masterIndex]);//populate the test3 text field with the array
  213.  
  214.                } 
  215.                   catch (IOException x)
  216.                   { 
  217.                      //displays an error message
  218.                      System.out.println("Error");
  219.                   } 
  220.             }
  221.  
  222.             else
  223.             {
  224.                JOptionPane.showMessageDialog(null, "There are no previous students");
  225.             }
  226.  
  227.          }                                
  228.       }
  229.       //creats actionlistener for the next button
  230.       private class NextButtonListener implements ActionListener
  231.       {
  232.           // executes when the button is clickd 
  233.          public void actionPerformed(ActionEvent e)
  234.          {
  235.             //incrament masterIndex by 1
  236.             masterIndex++;
  237.  
  238.             String[] nameList;//to store the array
  239.             String[] test1;//to store the array
  240.             String[] test2;//to store the array
  241.             String[] test3;//to store the array
  242.  
  243.  
  244.             try 
  245.             {
  246.  
  247.                nameList = open.getArrayName();//get the nameList array from the class
  248.                test1 = open.getArrayTest1();//get the test1 array from the class
  249.                test2 = open.getArrayTest2();//get the test2 array from the class
  250.                test3 = open.getArrayTest3();//get the test3 array from the class
  251.                name.txtname.setText(nameList[masterIndex]);//populate the txtname text field with the array
  252.                test.test1TextFild.setText(test1[masterIndex]);//populate the test1 text field with the array
  253.                test.test2TextFild.setText(test2[masterIndex]);//populate the test2 text field with the array
  254.                test.test3TextFild.setText(test3[masterIndex]);//populate the test3 text field with the array
  255.  
  256.  
  257.             } 
  258.                catch (IOException x)
  259.                { 
  260.                    //displays an error message
  261.                   System.out.println("Error");
  262.                } 
  263.          }
  264.  
  265.       }
  266.       //creats actionlistener for the save button
  267.       private class SaveButtonListener implements ActionListener
  268.       {
  269.           // executes when the button is clickd 
  270.          public void actionPerformed(ActionEvent e)
  271.          {
  272.              //if masterIndex = -1 then you are not at index 0 of the arrays so you cant calculate
  273.             if(masterIndex != -1)
  274.             {
  275.  
  276.                try 
  277.                {
  278.  
  279.                   String[] nameList;//to store the array
  280.                   String[] test1;//to store the array
  281.                   String[] test2;//to store the array
  282.                   String[] test3;//to store the array
  283.  
  284.                   nameList = open.getArrayName();//get the nameList array from the class
  285.                   test1 = open.getArrayTest1();//get the test1 array from the class
  286.                   test2 = open.getArrayTest2();//get the test2 array from the class
  287.                   test3 = open.getArrayTest3();//get the test3 array from the class
  288.  
  289.                   String saveName;// to save the text in the name text field
  290.                   saveName = name.txtname.getText();//gets the text form name text field
  291.                   String saveGrade1;// to save the text in the test1 text field
  292.                   saveGrade1 = test.test1TextFild.getText();//gets the text form test1 text field
  293.                   String saveGrade2;// to save the text in the test2 text field
  294.                   saveGrade2 = test.test2TextFild.getText();//gets the text form test2 text field
  295.                   String saveGrade3;// to save the text in the test3 text field
  296.                   saveGrade3 = test.test3TextFild.getText();//gets the text form test3 text field
  297.  
  298.                   List<String> name1List = Arrays.asList(nameList); //treats the array as an arrayList 
  299.                   List<String> test1List = Arrays.asList(test1);//treats the array as an arrayList
  300.                   List<String> test2List = Arrays.asList(test2);//treats the array as an arrayList
  301.                   List<String> test3List = Arrays.asList(test3);//treats the array as an arrayList
  302.  
  303.                   name1List.set(masterIndex, saveName);//changes of sets the value at the masterIndex to saveName
  304.                   test1List.set(masterIndex, saveGrade1);//changes of sets the value at the masterIndex to saveGrade1
  305.                   test2List.set(masterIndex, saveGrade2);//changes of sets the value at the masterIndex to saveGrade2
  306.                   test3List.set(masterIndex, saveGrade3);//changes of sets the value at the masterIndex to saveGrade3
  307.  
  308.                //opens the file for writing
  309.                   PrintWriter outputFile = new PrintWriter("name.txt");
  310.                //writes the array to a text file
  311.                   for(int index = 0; index < nameList.length; index++)
  312.                   {
  313.                      outputFile.println(nameList[index]);
  314.                   }
  315.                //closes the file    
  316.                   outputFile.close();
  317.  
  318.                //opens the file for writing
  319.                   PrintWriter outputFile1 = new PrintWriter("grade1.txt");
  320.                //writes the array to a text file
  321.                   for(int index1 = 0; index1 < test1.length; index1++)
  322.                   {
  323.                      outputFile1.println(test1[index1]);
  324.                   }
  325.                //closes the file
  326.                   outputFile1.close();
  327.  
  328.                //opens the file for writing
  329.                   PrintWriter outputFile2 = new PrintWriter("grade2.txt");
  330.                //writes the array to a text file
  331.                   for(int index2 = 0; index2 < test2.length; index2++)
  332.                   {
  333.                      outputFile2.println(test2[index2]);
  334.                   }
  335.                //closes the file
  336.                   outputFile2.close();
  337.  
  338.                //opens the file for writing
  339.                   PrintWriter outputFile3 = new PrintWriter("grade3.txt");
  340.                //writes the array to a text file
  341.                   for(int index3 = 0; index3 < test3.length; index3++)
  342.                   {
  343.                      outputFile3.println(test3[index3]);
  344.                   }
  345.                //closes the file
  346.                   outputFile3.close();
  347.  
  348.  
  349.                }  
  350.                   catch (IOException x)
  351.                   { 
  352.                   //displays an error message
  353.                      System.out.println("Error!");
  354.                   }  
  355.             }
  356.             else
  357.             {
  358.                 //shows error message when masterIndex == -1
  359.                JOptionPane.showMessageDialog(null, "Please click (Next) first");
  360.  
  361.             }      
  362.          }                                        
  363.       }
  364.  
  365.       public static void main(String[] a)
  366.       {
  367.          // calls the project2 class
  368.          new project2();
  369.  
  370.       }
  371.    }
  372.  
ERRORS
----jGRASP exec: javac -g project3.java

project3.java:17: cannot find symbol
symbol : class gradeTypePanel
location: class project3
public gradeTypePanel gradeType; //to reference the the grade Type Panel with the radio buttons
^
project3.java:18: cannot find symbol
symbol : class namePanel
location: class project3
public namePanel name; // to reference the name panel with the name text field
^
project3.java:19: cannot find symbol
symbol : class testPanel
location: class project3
public testPanel test;// to reference the test panel with the 3 test grade fields
^
project3.java:20: cannot find symbol
symbol : class resultPanel
location: class project3
public resultPanel result;// to reference the result panel with the result text field
^
project3.java:27: cannot find symbol
symbol : class openFile
location: class project3
public openFile open;// to reference the open file class
^
project3.java:40: cannot find symbol
symbol : class resultPanel
location: class project3
result = new resultPanel();
^
project3.java:42: cannot find symbol
symbol : class gradeTypePanel
location: class project3
gradeType = new gradeTypePanel();
^
project3.java:44: cannot find symbol
symbol : class namePanel
location: class project3
name = new namePanel();
^
project3.java:46: cannot find symbol
symbol : class testPanel
location: class project3
test = new testPanel();
^
project2.java:17: cannot find symbol
symbol : class gradeTypeLabel
location: class project2
public gradeTypeLabel gradeType; // to reference the the grade Type Label with the radio buttons
^
project2.java:18: cannot find symbol
symbol : class namePanel
location: class project2
public namePanel name; // to reference the name panel with the name text field
^
project2.java:19: cannot find symbol
symbol : class testPanel
location: class project2
public testPanel test; // to reference the test panel with the 3 test grade fields
^
project2.java:20: cannot find symbol
symbol : class resultPanel
location: class project2
public resultPanel result; // to reference the result panel with the result text field
^
project2.java:27: cannot find symbol
symbol : class openFile
location: class project2
public openFile open; // to reference the open file class
^
project2.java:40: cannot find symbol
symbol : class resultPanel
location: class project2
result = new resultPanel();
^
project2.java:42: cannot find symbol
symbol : class gradeTypeLabel
location: class project2
gradeType = new gradeTypeLabel();
^
project2.java:44: cannot find symbol
symbol : class namePanel
location: class project2
name = new namePanel();
^
project2.java:46: cannot find symbol
symbol : class testPanel
location: class project2
test = new testPanel();
^
project2.java:76: cannot find symbol
symbol : class CalcButtonListener
location: class project2
calcButton.addActionListener(new CalcButtonListener());// calls the ActionListener for the calcButton
^
project2.java:77: cannot find symbol
symbol : class PrevButtonListener
location: class project2
prevButton.addActionListener(new PrevButtonListener());// calls the ActionListener for the prevButto
^
project2.java:78: cannot find symbol
symbol : class NextButtonListener
location: class project2
nextButton.addActionListener(new NextButtonListener());// calls the ActionListener for the nextButton
^
project2.java:79: cannot find symbol
symbol : class SaveButtonListener
location: class project2
saveButton.addActionListener(new SaveButtonListener());// calls the ActionListener for the addButton
^
22 errors
Sep 16 '10 #4
Oralloy
988 Expert 512MB
Let's start with the first error.

Where is gradeTypePanel even defined? It looks like one of your classes, and I don't see it.

It's referenced in your code, but there's no import for it.

Also, in main(), you call out project2. I think it should be project3.
Sep 16 '10 #5
Good morning, Having all kinds of compilation errors with my program. Started a new one and here it is and the errors.

Expand|Select|Wrap|Line Numbers
  1.    import java.util.*; 
  2.    import java.io.*; 
  3.    import javax.swing.*; 
  4.    import java.awt.*; 
  5.    import java.awt.event.*; 
  6.  
  7.    public class SuperProject extends JFrame 
  8.    { 
  9.       private static final int WIDTH = 550; 
  10.       private static final int HEIGHT = 430; 
  11.       int gradeCalc; 
  12.       int Student; 
  13.       private StudentList[] sList = new StudentList[20]; 
  14.       private static final int MAX_NUMBER_OF_STUDENTS = 20; 
  15.  
  16.    // instance variables 
  17.       private int noOfStudents; 
  18.       private double score, tst1, tst2, tst3; 
  19.       private double classAvg, stAvg, totalScore; 
  20.       private int displayedStudentIndex = 0; 
  21.       private char ltrGrade; 
  22.       private String stName; 
  23.  
  24.    // This area is for the GUI components 
  25.    // Each item that will be displayed will 
  26.    // have a label and a textfield, (L) and (TF), 
  27.    // respectively. 
  28.       private JLabel stNameL, tst1L, tst2L, tst3L, 
  29.       classAvgL, stAvgL, headingL; 
  30.       private JTextField stNameTF, tst1TF, tst2TF, tst3TF; 
  31.       private JTextArea classAvgTA, stAvgTA; 
  32.       private JButton exitB, nextB, prevB, calcGrade; 
  33.       private ButtonHandler bHandler; 
  34.  
  35.       public SuperProject() 
  36.       { 
  37.          setTitle("Grade Calculator");       // set's the title 
  38.          setSize(WIDTH, HEIGHT);               // set the window size 
  39.          Container pane = getContentPane(); // get the container 
  40.          pane.setLayout(null);                   // set the container's layout to null 
  41.          bHandler = new ButtonHandler();    // instantiate the button event handler 
  42.  
  43.       // instantiate the labels 
  44.          headingL = new JLabel("STUDENT RECORD"); 
  45.          stNameL = new JLabel("Student Name", SwingConstants.RIGHT); 
  46.          tst1L = new JLabel("Test 1", SwingConstants.LEFT); 
  47.          tst2L = new JLabel("Test 2", SwingConstants.LEFT); 
  48.          tst3L = new JLabel("Test 3", SwingConstants.LEFT); 
  49.          stAvgL = new JLabel("Student Average " 
  50.             + "\n" + "Class Average"); 
  51.  
  52.       //instantiate the text fields 
  53.          stNameTF = new JTextField(65); 
  54.          tst1TF = new JTextField(10); 
  55.          tst2TF = new JTextField(10); 
  56.          tst3TF = new JTextField(10); 
  57.  
  58.       // instantiate the text area 
  59.          classAvgTA = new JTextArea(6, 20); 
  60.          classAvgTA.setAutoscrolls(true); 
  61.       // instantiate the buttons and register the listener 
  62.          exitB = new JButton("Exit"); 
  63.          exitB.addActionListener(bHandler); 
  64.          nextB = new JButton("Next"); 
  65.          nextB.addActionListener(bHandler); 
  66.          prevB = new JButton("Previous"); 
  67.          prevB.addActionListener(bHandler); 
  68.          calcGrade = new JButton("Calc Grade"); 
  69.          calcGrade.addActionListener(bHandler); 
  70.       // set the size of the labels, text fields, and buttons 
  71.          headingL.setSize(200, 30); 
  72.          stNameL.setSize(100, 30); 
  73.          stNameTF.setSize(100, 30); 
  74.          tst1L.setSize(100, 30); 
  75.          tst1TF.setSize(100, 30); 
  76.          tst2L.setSize(120, 30); 
  77.          tst2TF.setSize(100, 30); 
  78.          tst3L.setSize(100, 30); 
  79.          tst3TF.setSize(100, 30); 
  80.          classAvgTA.setSize(370, 120); 
  81.          calcGrade.setSize(100, 30); 
  82.          prevB.setSize(100, 30); 
  83.          nextB.setSize(100, 30); 
  84.          exitB.setSize(100, 30); 
  85.  
  86.       //set the location of the labels, text fields, 
  87.       //and buttons 
  88.          headingL.setLocation(220, 10); 
  89.          stNameL.setLocation(20, 50); 
  90.          stNameTF.setLocation(120, 50); 
  91.          tst1L.setLocation(20, 100); 
  92.          tst1TF.setLocation(120, 100); 
  93.          tst2L.setLocation(300, 50); 
  94.          tst2TF.setLocation(420, 50); 
  95.          tst3L.setLocation(300, 100); 
  96.          tst3TF.setLocation(420, 100); 
  97.          classAvgTA.setLocation(70, 230); 
  98.          prevB.setLocation(120, 370); 
  99.          exitB.setLocation(220, 370); 
  100.          nextB.setLocation(320, 370); 
  101.          calcGrade.setLocation(420, 370);
  102.  
  103.       //add the labels, text fields, and buttons to the pane 
  104.          pane.add(headingL); 
  105.          pane.add(stNameL); 
  106.          pane.add(stNameTF); 
  107.          pane.add(tst1L); 
  108.          pane.add(tst1TF); 
  109.          pane.add(tst2L); 
  110.          pane.add(tst2TF); 
  111.          pane.add(tst3L); 
  112.          pane.add(classAvgTA); 
  113.          pane.add(calcGrade); 
  114.          pane.add(prevB); 
  115.          pane.add(exitB); 
  116.          pane.add(nextB); 
  117.          setVisible(true); //show the window 
  118.          setDefaultCloseOperation(EXIT_ON_CLOSE); 
  119.          System.exit(0); 
  120.       } 
  121.  
  122.          private class ButtonHandler implements ActionListener 
  123.       { 
  124.               public void actionPerformed (ActionEvent e)  
  125.              {  
  126.                 if (e.getActionCommand().equals("Previous"))  
  127.                    if (displayedStudentIndex > 0)  
  128.                       displayGradeAverage(displayedStudentIndex - 1);  
  129.                    else  
  130.                       displayGradeAverage(displayedStudentIndex);  
  131.                 else if (e.getActionCommand().equals("Next"))  
  132.                    if (displayedStudentIndex + 1 < noOfStudents)  
  133.                       displayGradeAverage(displayedStudentIndex + 1);  
  134.                    else  
  135.                       displayGradeAverage(displayedStudentIndex);  
  136.                 else if (e.getActionCommand().equals("Calc Grade"))  
  137.                    displayGradeAverage(0);  
  138.                 else  
  139.                    System.exit(0);  
  140.              }  
  141.  
  142.       public static void main (String [] args) 
  143.       { 
  144.          new SuperProject(); 
  145.       } 
  146.  
  147.       Scanner inFile = 
  148.       new Scanner(new FileReader("AcademicGrades.txt")); 
  149.       { 
  150.          for (int s = 0; s < MAX_NUMBER_OF_STUDENTS; s++) 
  151.             gradeCalc.StudentList[s] = new Student(); 
  152.          gradeCalc.noOfStudents = 
  153.             inFile.nextInt();     // get the number of students 
  154.          gradeCalc.score = 
  155.             inFile.nextDouble(); // get the student's scores 
  156.          gradeCalc.getStudentData(inFile); 
  157.          gradeCalc.displayGradeAverage(0); 
  158.       } 
  159.  
  160.    // get the student data from file 
  161.       public void getStudentData(Scanner inFile) 
  162.       { 
  163.          System.out.println("Grade Calculator is getting information..."); 
  164.          System.out.println("One Moment Please"); 
  165.       } 
  166.  
  167.  
  168.            public void displayGradeAverage(int stName)  
  169.           {  
  170.              displayedStudentIndex = stName;  
  171.              String strName = "";  
  172.              boolean classAvg = studentList[(int) (totalScore / noOfStudents)].getClassAverage();  
  173.              stNameTF.setText(StudentList[stName].getFirstName() + " "  
  174.                                                                 + studentList[stName].getLastName()); 
  175.              stAvgTA.setText(""+StudentList[(int) (totalScore / 3.0)].getStudentAverage()); 
  176.              classAvgTA.setText(""+StudentList[(int) (totalScore / noOfStudents)].getClassAverage()); } 
  177.            } 
  178.         }
  179.  
Then it goes to StudentList.java and gives the following:
ERRORS
----jGRASP exec: javac -g SuperProject.java

StudentList.java:5: class GradeCalculator3 is public, should be declared in a file named GradeCalculator3.java
public class GradeCalculator3 extends JFrame
^
SuperProject.java:13: cannot access StudentList
bad class file: .\StudentList.java
file does not contain class StudentList
Please remove or make sure it appears in the correct subdirectory of the classpath.
private StudentList[] sList = new StudentList[20];
^

----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
Sep 19 '10 #6
Oralloy
988 Expert 512MB
Sorry, just got in.

First, the error "StudentList.java:5..." is about your "StudentList.java" class failing to compile. Since its failing compile, the error at line 13 just continues the problem.

So. First thing you need to do is clean up StudentList.java. It looks like the main class there is actually declared as "GradeCalculator3". You need to fix that, and any other errors that might result.
Sep 20 '10 #7
I will try that Orally but I had to turn the project in this morning! I really do want to get it working. I appreciate all your help and I definitely will be back to the site when my Last class start in Oct.

Once again Thank!
Sep 20 '10 #8
Oralloy
988 Expert 512MB
@blknmld69,

No worries! Good luck with your schooling.
Sep 20 '10 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: Doug Fort | last post by:
This is an excerpt from a much longer post on the python-dev mailing list. I'm responding here, to avoid cluttering up python-dev. <snip> >Some English readers might not really imagine, but it...
12
by: lothar | last post by:
re: 4.2.1 Regular Expression Syntax http://docs.python.org/lib/re-syntax.html *?, +?, ?? Adding "?" after the qualifier makes it perform the match in non-greedy or minimal fashion; as few...
17
by: cheeser | last post by:
Hello all, Please see the question in the code below... Thanks! Dave #include <iostream>
1
by: gary b | last post by:
Hello When I use a PreparedStatement (in jdbc) with the following query: SELECT store_groups_id FROM store_groups WHERE store_groups_id IS NOT NULL AND type = ? ORDER BY group_name
5
by: Lars | last post by:
Why doesn't the W3C's HTML Validator recognize &euro; and what do I have to do to make my html-file valid?
5
by: klaus triendl | last post by:
hi, recently i discovered a memory leak in our code; after some investigation i could reduce it to the following problem: return objects of functions are handled as temporary objects, hence...
3
by: Mario | last post by:
Hello, I couldn't find a solution to the following problem (tried google and dejanews), maybe I'm using the wrong keywords? Is there a way to open a file (a linux fifo pipe actually) in...
2
by: Mark Stijnman | last post by:
I would like to be able to have an object accessible as a vector using the operator, but able to track modifications to its data, so that it can update other internal data as needed. I figured...
15
by: Sander Tekelenburg | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 The HTML specs speak of "replaced" and "non-replaced" elements, yet for the life of me I can't find an explanation of what "replaced" is supposed...
399
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.