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(); -
import java.util.*;
-
import java.io.*;
-
import javax.swing.*;
-
import java.awt.*;
-
import java.awt.event.*;
-
-
public class GradeCalculator extends JFrame
-
{
-
private static final int WIDTH = 550;
-
private static final int HEIGHT = 430;
-
-
private static final int MAX_NUMBER_OF_STUDENTS = 20;
-
-
// instance variables
-
String Student[] = new String[MAX_NUMBER_OF_STUDENTS];
-
private int noOfStudents;
-
private double score, tst1, tst2, tst3;
-
private double classAvg, stAvg, totalScore;
-
private int displayedStudentIndex = 0;
-
private char ltrGrade;
-
private String stName;
-
-
// This area is for the GUI components
-
// Each item that will be displayed will
-
// have a label and a textfield, (L) and (TF),
-
// respectively.
-
private JLabel stNameL, tst1L, tst2L, tst3L,
-
classAvgL, stAvgL, headingL;
-
private JTextField stNameTF, tst1TF, tst2TF, tst3TF;
-
private JTextArea classAvgTA, stAvgTA;
-
private JButton exitB, nextB, prevB, calcGrade;
-
-
private ButtonHandler bHandler;
-
-
public GradeCalculator()
-
{
-
setTitle("Grade Calculator"); // set's the title
-
setSize(WIDTH, HEIGHT); // set the window size
-
Container pane = getContentPane(); // get the container
-
pane.setLayout(null); // set the container's layout to null
-
-
bHandler = new ButtonHandler(); // instantiate the button event handler
-
-
// instantiate the labels
-
headingL = new JLabel("STUDENT RECORD");
-
stNameL = new JLabel("Studen Name", SwingConstants.RIGHT);
-
tst1L = new JLabel("Test 1", SwingConstants.LEFT);
-
tst2L = new JLabel("Test 2", SwingConstants.LEFT);
-
tst3L = new JLabel("Test 3", SwingConstants.LEFT);
-
stAvgL = new JLabel("Student Average "
-
+ "\n" + "Class Average");
-
//instantiate the text fields
-
stNameTF = new JTextField(65);
-
tst1TF = new JTextField(10);
-
tst2TF = new JTextField(10);
-
tst3TF = new JTextField(10);
-
-
// instantiate the text area
-
classAvgTA = new JTextArea(6, 20);
-
classAvgTA.setAutoscrolls(true);
-
-
// instantiate the buttons and register the listener
-
exitB = new JButton("Exit");
-
exitB.addActionListener(bHandler);
-
-
nextB = new JButton("Next");
-
nextB.addActionListener(bHandler);
-
-
prevB = new JButton("Previous");
-
prevB.addActionListener(bHandler);
-
-
calcGrade = new JButton("Calc Grade");
-
calcGrade.addActionListener(bHandler);
-
-
// set the size of the labels, text fields, and buttons
-
-
headingL.setSize(200, 30);
-
stNameL.setSize(100, 30);
-
stNameTF.setSize(100, 30);
-
tst1L.setSize(100, 30);
-
tst1TF.setSize(100, 30);
-
tst2L.setSize(120, 30);
-
tst2TF.setSize(100, 30);
-
tst3L.setSize(100, 30);
-
tst3TF.setSize(100, 30);
-
classAvgTA.setSize(370, 120);
-
calcGrade.setSize(100, 30);
-
prevB.setSize(100, 30);
-
nextB.setSize(100, 30);
-
exitB.setSize(100, 30);
-
-
//set the location of the labels, text fields,
-
//and buttons
-
headingL.setLocation(220, 10);
-
stNameL.setLocation(20, 50);
-
stNameTF.setLocation(120, 50);
-
tst1L.setLocation(20, 100);
-
tst1TF.setLocation(120, 100);
-
tst2L.setLocation(300, 50);
-
tst2TF.setLocation(420, 50);
-
tst3L.setLocation(300, 100);
-
tst3TF.setLocation(420, 100);
-
classAvgTA.setLocation(70, 230);
-
prevB.setLocation(120, 370);
-
exitB.setLocation(220, 370);
-
nextB.setLocation(320, 370);
-
calcGrade.setLocation(420, 370);
-
-
//add the labels, text fields, and buttons to the pane
-
pane.add(headingL);
-
pane.add(stNameL);
-
pane.add(stNameTF);
-
pane.add(tst1L);
-
pane.add(tst1TF);
-
pane.add(tst2L);
-
pane.add(tst2TF);
-
pane.add(tst3L);
-
pane.add(classAvgTA);
-
pane.add(calcGrade);
-
pane.add(prevB);
-
pane.add(exitB);
-
pane.add(nextB);
-
-
setVisible(true); //show the window
-
setDefaultCloseOperation(EXIT_ON_CLOSE);
-
System.exit(0);
-
}
-
-
-
-
public static void main (String [] args)
-
{
-
-
File file = new File("AcademicGrades.txt");
-
Scanner keyboard = new Scanner(System.in);
-
Scanner inputFile = new Scanner(file);
-
-
-
for (int s = 0; s < MAX_NUMBER_OF_STUDENTS; s++)
-
{
-
calcGrade.studentList[s] = new Student();
-
-
gradeCalc.noOfStudents =
-
inputFile.nextInt(); // get the number of students
-
gradeCalc.score =
-
inputFile.nextDouble(); // get the student's scores
-
-
gradeCalc.getStudentData(inputFile);
-
gradeCalc.displayGradeAverage(0);
-
}
-
}
-
// get the student data from file
-
-
-
public void getStudentData(Scanner inputFile)
-
{
-
System.out.println("Grade Calculator is getting information...");
-
System.out.println("One Moment Please");
-
}
-
private class ButtonHandler implements ActionListener
-
{
-
public void actionPerformed (ActionEvent e)
-
{
-
if (e.getActionCommand().equals("Previous"))
-
if (displayedStudentIndex > 0)
-
displayGradeAverage(displayedStudentIndex - 1);
-
else
-
displayGradeAverage(displayedStudentIndex);
-
else if (e.getActionCommand().equals("Next"))
-
if (displayedStudentIndex + 1 < noOfStudents)
-
displayGradeAverage(displayedStudentIndex + 1);
-
else
-
displayGradeAverage(displayedStudentIndex);
-
else if (e.getActionCommand().equals("Calc Grade"))
-
displayGradeAverage(0);
-
else
-
System.exit(0);
-
}
-
}
-
-
public void displayGradeAverage(int stName)
-
{
-
int studentList;
-
displayedStudentIndex = stName;
-
String strName = "";
-
boolean classAvg = studentList[(int) (totalScore / noOfStudents)].getClassAverage();
-
stNameTF.setText(studentList[stName].getFirstName() + " "
-
+ studentList[stName].getLastName());
-
stAvgTA.setText(""+studentList[(int) (totalScore / 5.0)].getStudentAverage());
-
classAvgTA.setText(""+studentList[(int) (totalScore / noOfStudents)].getClassAverage());
-
}
-
}
-
8 5476
The reason its giving you troubles is that your student loop is in the main method at line 131: - 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.
Static methods cannot access non-static variables. Static fields, methods are initialized before non-static fields.
No Im gettn this cannot find symbols: -
import javax.swing.*; //needed for swing classes
-
import java.awt.event.*; // needed for the action listener
-
import java.awt.*; //needed for the boader layout class
-
import java.io.*; //need for the file and IOException
-
import java.util.Scanner; // needed for the scanner class
-
import java.util.List; // needed for the arraylist
-
import java.util.Arrays; //needed for the arraylict class
-
-
/**
-
Constructor
-
*/
-
-
-
public class project3 extends JFrame
-
{
-
-
public gradeTypePanel gradeType; //to reference the the grade Type Panel with the radio buttons
-
public namePanel name; // to reference the name panel with the name text field
-
public testPanel test;// to reference the test panel with the 3 test grade fields
-
public resultPanel result;// to reference the result panel with the result text field
-
private JPanel panel; // to reference the a panel
-
private JButton calcButton; // creats the Button named calcButton
-
private JButton prevButton; // creats the Button named prevButton
-
private JButton nextButton; // creats the Button named nextButton
-
private JButton saveButton; // creats the Button named saveButton
-
private JPanel buttonPanel; // to reference the panel where all the buttons go
-
public openFile open;// to reference the open file class
-
public int masterIndex = -1; // this controls all the of the indexes of all 4 arrays
-
-
// constructs the window
-
public project3()
-
{
-
// sets the title
-
setTitle("Grade Program");
-
// set what happens when the exit button is clicked
-
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
// sets the border layout
-
setLayout(new BorderLayout());
-
//calls the resultPanel class and names it result
-
result = new resultPanel();
-
//calls the gradeTypePanel and names it gradeType
-
gradeType = new gradeTypePanel();
-
//calls the namePanel and names it name
-
name = new namePanel();
-
//calls the testPanel and names it test
-
test = new testPanel();
-
-
//builds the button panel
-
buildButtonPanel();
-
-
//adds all of the panels to the north, south, east, west, and center panels
-
add(name, BorderLayout.NORTH);
-
add(gradeType, BorderLayout.WEST);
-
add(test, BorderLayout.CENTER);
-
add(buttonPanel, BorderLayout.EAST);
-
add(result, BorderLayout.SOUTH);
-
-
// packs all the panels togather
-
pack();
-
-
//makes the window visable
-
setVisible(true);
-
}
-
-
//builds the panel for the buttons
-
private void buildButtonPanel()
-
{
-
-
buttonPanel = new JPanel();
-
-
-
prevButton = new JButton("Prev");// adds the text prev to the prevButton
-
calcButton = new JButton("Calc Grade");// adds the text Calc Grade to the calcButton
-
nextButton = new JButton("Next");// adds the text Next to the nextButton
-
saveButton = new JButton("Save");// adds the text Save to the saveButton
-
-
-
calcButton.addActionListener(new CalcButtonListener());// calls the ActionListener for the calcButton
-
prevButton.addActionListener(new PrevButtonListener());// calls the ActionListener for the prevButto
-
nextButton.addActionListener(new NextButtonListener());// calls the ActionListener for the nextButton
-
saveButton.addActionListener(new SaveButtonListener());// calls the ActionListener for the addButton
-
-
-
buttonPanel.add(prevButton);// adds the prevButton to the panel
-
buttonPanel.add(saveButton);// adds the saveButton to the panel
-
buttonPanel.add(nextButton);// adds the nextButton to the panel
-
buttonPanel.add(calcButton);// adds the calcButton to the panel
-
-
-
}
-
//creats actionlistener for the Calc Grade button
-
private class CalcButtonListener implements ActionListener
-
{
-
// executes when the button is clickd
-
public void actionPerformed(ActionEvent e)
-
{
-
//if masterIndex = -1 then you are not at index 0 of the arrays so you cant calculate
-
if(masterIndex != -1)
-
{
-
String nameText;// to save the text in the name text field
-
nameText = name.txtname.getText();//gets the text form name text field
-
String grade1;// to save the text in the test1 text field
-
grade1 = test.test1TextFild.getText();//gets the text form test1 text field
-
String grade2;// to save the text in the test2 text field
-
grade2 = test.test2TextFild.getText();//gets the text form test2 text field
-
String grade3;// to save the text in the test3 text field
-
grade3 = test.test3TextFild.getText();//gets the text form test3 text field
-
-
//if the text in all 3 text field are <= 100 calculate
-
if(Double.parseDouble(grade1) <= 100 && Double.parseDouble(grade2) <= 100 && Double.parseDouble(grade3) <= 100)
-
{
-
//convert and add all 3 grades together
-
double totalGrade = Double.parseDouble(grade1) + Double.parseDouble(grade2) + Double.parseDouble(grade3);
-
//get the the avarage
-
double NumberGrade = (totalGrade / 300) * 100;
-
//to hold the letter grade
-
String letterGrade;
-
//if the alphabetical radio button is Selected get the letter grade
-
if(gradeType.alphabetical.isSelected())
-
-
{
-
-
-
if(NumberGrade >= 90)
-
{
-
//sets letter grade to A
-
letterGrade = "A";
-
//display the result in the result text field
-
result.textResult.setText(letterGrade);
-
-
}
-
else if(NumberGrade >= 80)
-
{
-
//sets letter grade to B
-
letterGrade = "B";
-
//display the result in the result text field
-
result.textResult.setText(letterGrade);
-
}
-
else if(NumberGrade >= 70)
-
{
-
//sets letter grade to C
-
letterGrade = "C";
-
//display the result in the result text field
-
result.textResult.setText(letterGrade);
-
}
-
else if(NumberGrade >= 60)
-
{
-
//sets letter grade to D
-
letterGrade = "D";
-
//display the result in the result text field
-
result.textResult.setText(letterGrade);
-
}
-
else if(NumberGrade < 60)
-
{
-
//sets letter grade to F
-
letterGrade = "F";
-
//display the result in the result text field
-
result.textResult.setText(letterGrade);
-
}
-
-
-
}
-
//if numerical is Selected get the number grade
-
if(gradeType.numerical.isSelected())
-
{
-
//display the result in the result text field
-
result.textResult.setText(Double.toString(NumberGrade));
-
}
-
}
-
else
-
{
-
//displays error message when all grades are not <= 100
-
JOptionPane.showMessageDialog(null, "All Grades must be less than or equal to (100)");
-
}
-
}
-
else
-
{
-
//shows error message when masterIndex == -1
-
JOptionPane.showMessageDialog(null, "Please click (Next) first");
-
}
-
-
}
-
}
-
//creats actionlistener for the Calc prev button
-
private class PrevButtonListener implements ActionListener
-
{
-
// executes when the button is clickd gets the input and calcilates it
-
public void actionPerformed(ActionEvent e)
-
{
-
//if masterIndex is > 0
-
if(masterIndex > 0)
-
{
-
//decrament masterIndex by 1
-
masterIndex--;
-
-
String[] nameList;//to store the array
-
String[] test1;//to store the array
-
String[] test2;//to store the array
-
String[] test3;//to store the array
-
-
-
try
-
{
-
-
nameList = open.getArrayName();//get the nameList array from the class
-
test1 = open.getArrayTest1();//get the test1 array from the class
-
test2 = open.getArrayTest2();//get the test2 array from the class
-
test3 = open.getArrayTest3();//get the test3 array from the class
-
name.txtname.setText(nameList[masterIndex]);//populate the txtname text field with the array
-
test.test1TextFild.setText(test1[masterIndex]);//populate the test1 text field with the array
-
test.test2TextFild.setText(test2[masterIndex]);//populate the test2 text field with the array
-
test.test3TextFild.setText(test3[masterIndex]);//populate the test3 text field with the array
-
-
}
-
catch (IOException x)
-
{
-
//displays an error message
-
System.out.println("Error");
-
}
-
}
-
-
else
-
{
-
JOptionPane.showMessageDialog(null, "There are no previous students");
-
}
-
-
}
-
}
-
//creats actionlistener for the next button
-
private class NextButtonListener implements ActionListener
-
{
-
// executes when the button is clickd
-
public void actionPerformed(ActionEvent e)
-
{
-
//incrament masterIndex by 1
-
masterIndex++;
-
-
String[] nameList;//to store the array
-
String[] test1;//to store the array
-
String[] test2;//to store the array
-
String[] test3;//to store the array
-
-
-
try
-
{
-
-
nameList = open.getArrayName();//get the nameList array from the class
-
test1 = open.getArrayTest1();//get the test1 array from the class
-
test2 = open.getArrayTest2();//get the test2 array from the class
-
test3 = open.getArrayTest3();//get the test3 array from the class
-
name.txtname.setText(nameList[masterIndex]);//populate the txtname text field with the array
-
test.test1TextFild.setText(test1[masterIndex]);//populate the test1 text field with the array
-
test.test2TextFild.setText(test2[masterIndex]);//populate the test2 text field with the array
-
test.test3TextFild.setText(test3[masterIndex]);//populate the test3 text field with the array
-
-
-
}
-
catch (IOException x)
-
{
-
//displays an error message
-
System.out.println("Error");
-
}
-
}
-
-
}
-
//creats actionlistener for the save button
-
private class SaveButtonListener implements ActionListener
-
{
-
// executes when the button is clickd
-
public void actionPerformed(ActionEvent e)
-
{
-
//if masterIndex = -1 then you are not at index 0 of the arrays so you cant calculate
-
if(masterIndex != -1)
-
{
-
-
try
-
{
-
-
String[] nameList;//to store the array
-
String[] test1;//to store the array
-
String[] test2;//to store the array
-
String[] test3;//to store the array
-
-
nameList = open.getArrayName();//get the nameList array from the class
-
test1 = open.getArrayTest1();//get the test1 array from the class
-
test2 = open.getArrayTest2();//get the test2 array from the class
-
test3 = open.getArrayTest3();//get the test3 array from the class
-
-
String saveName;// to save the text in the name text field
-
saveName = name.txtname.getText();//gets the text form name text field
-
String saveGrade1;// to save the text in the test1 text field
-
saveGrade1 = test.test1TextFild.getText();//gets the text form test1 text field
-
String saveGrade2;// to save the text in the test2 text field
-
saveGrade2 = test.test2TextFild.getText();//gets the text form test2 text field
-
String saveGrade3;// to save the text in the test3 text field
-
saveGrade3 = test.test3TextFild.getText();//gets the text form test3 text field
-
-
List<String> name1List = Arrays.asList(nameList); //treats the array as an arrayList
-
List<String> test1List = Arrays.asList(test1);//treats the array as an arrayList
-
List<String> test2List = Arrays.asList(test2);//treats the array as an arrayList
-
List<String> test3List = Arrays.asList(test3);//treats the array as an arrayList
-
-
name1List.set(masterIndex, saveName);//changes of sets the value at the masterIndex to saveName
-
test1List.set(masterIndex, saveGrade1);//changes of sets the value at the masterIndex to saveGrade1
-
test2List.set(masterIndex, saveGrade2);//changes of sets the value at the masterIndex to saveGrade2
-
test3List.set(masterIndex, saveGrade3);//changes of sets the value at the masterIndex to saveGrade3
-
-
//opens the file for writing
-
PrintWriter outputFile = new PrintWriter("name.txt");
-
//writes the array to a text file
-
for(int index = 0; index < nameList.length; index++)
-
{
-
outputFile.println(nameList[index]);
-
}
-
//closes the file
-
outputFile.close();
-
-
//opens the file for writing
-
PrintWriter outputFile1 = new PrintWriter("grade1.txt");
-
//writes the array to a text file
-
for(int index1 = 0; index1 < test1.length; index1++)
-
{
-
outputFile1.println(test1[index1]);
-
}
-
//closes the file
-
outputFile1.close();
-
-
//opens the file for writing
-
PrintWriter outputFile2 = new PrintWriter("grade2.txt");
-
//writes the array to a text file
-
for(int index2 = 0; index2 < test2.length; index2++)
-
{
-
outputFile2.println(test2[index2]);
-
}
-
//closes the file
-
outputFile2.close();
-
-
//opens the file for writing
-
PrintWriter outputFile3 = new PrintWriter("grade3.txt");
-
//writes the array to a text file
-
for(int index3 = 0; index3 < test3.length; index3++)
-
{
-
outputFile3.println(test3[index3]);
-
}
-
//closes the file
-
outputFile3.close();
-
-
-
}
-
catch (IOException x)
-
{
-
//displays an error message
-
System.out.println("Error!");
-
}
-
}
-
else
-
{
-
//shows error message when masterIndex == -1
-
JOptionPane.showMessageDialog(null, "Please click (Next) first");
-
-
}
-
}
-
}
-
-
public static void main(String[] a)
-
{
-
// calls the project2 class
-
new project2();
-
-
}
-
}
-
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
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.
Good morning, Having all kinds of compilation errors with my program. Started a new one and here it is and the errors. -
import java.util.*;
-
import java.io.*;
-
import javax.swing.*;
-
import java.awt.*;
-
import java.awt.event.*;
-
-
public class SuperProject extends JFrame
-
{
-
private static final int WIDTH = 550;
-
private static final int HEIGHT = 430;
-
int gradeCalc;
-
int Student;
-
private StudentList[] sList = new StudentList[20];
-
private static final int MAX_NUMBER_OF_STUDENTS = 20;
-
-
// instance variables
-
private int noOfStudents;
-
private double score, tst1, tst2, tst3;
-
private double classAvg, stAvg, totalScore;
-
private int displayedStudentIndex = 0;
-
private char ltrGrade;
-
private String stName;
-
-
// This area is for the GUI components
-
// Each item that will be displayed will
-
// have a label and a textfield, (L) and (TF),
-
// respectively.
-
private JLabel stNameL, tst1L, tst2L, tst3L,
-
classAvgL, stAvgL, headingL;
-
private JTextField stNameTF, tst1TF, tst2TF, tst3TF;
-
private JTextArea classAvgTA, stAvgTA;
-
private JButton exitB, nextB, prevB, calcGrade;
-
private ButtonHandler bHandler;
-
-
public SuperProject()
-
{
-
setTitle("Grade Calculator"); // set's the title
-
setSize(WIDTH, HEIGHT); // set the window size
-
Container pane = getContentPane(); // get the container
-
pane.setLayout(null); // set the container's layout to null
-
bHandler = new ButtonHandler(); // instantiate the button event handler
-
-
// instantiate the labels
-
headingL = new JLabel("STUDENT RECORD");
-
stNameL = new JLabel("Student Name", SwingConstants.RIGHT);
-
tst1L = new JLabel("Test 1", SwingConstants.LEFT);
-
tst2L = new JLabel("Test 2", SwingConstants.LEFT);
-
tst3L = new JLabel("Test 3", SwingConstants.LEFT);
-
stAvgL = new JLabel("Student Average "
-
+ "\n" + "Class Average");
-
-
//instantiate the text fields
-
stNameTF = new JTextField(65);
-
tst1TF = new JTextField(10);
-
tst2TF = new JTextField(10);
-
tst3TF = new JTextField(10);
-
-
// instantiate the text area
-
classAvgTA = new JTextArea(6, 20);
-
classAvgTA.setAutoscrolls(true);
-
// instantiate the buttons and register the listener
-
exitB = new JButton("Exit");
-
exitB.addActionListener(bHandler);
-
nextB = new JButton("Next");
-
nextB.addActionListener(bHandler);
-
prevB = new JButton("Previous");
-
prevB.addActionListener(bHandler);
-
calcGrade = new JButton("Calc Grade");
-
calcGrade.addActionListener(bHandler);
-
// set the size of the labels, text fields, and buttons
-
headingL.setSize(200, 30);
-
stNameL.setSize(100, 30);
-
stNameTF.setSize(100, 30);
-
tst1L.setSize(100, 30);
-
tst1TF.setSize(100, 30);
-
tst2L.setSize(120, 30);
-
tst2TF.setSize(100, 30);
-
tst3L.setSize(100, 30);
-
tst3TF.setSize(100, 30);
-
classAvgTA.setSize(370, 120);
-
calcGrade.setSize(100, 30);
-
prevB.setSize(100, 30);
-
nextB.setSize(100, 30);
-
exitB.setSize(100, 30);
-
-
//set the location of the labels, text fields,
-
//and buttons
-
headingL.setLocation(220, 10);
-
stNameL.setLocation(20, 50);
-
stNameTF.setLocation(120, 50);
-
tst1L.setLocation(20, 100);
-
tst1TF.setLocation(120, 100);
-
tst2L.setLocation(300, 50);
-
tst2TF.setLocation(420, 50);
-
tst3L.setLocation(300, 100);
-
tst3TF.setLocation(420, 100);
-
classAvgTA.setLocation(70, 230);
-
prevB.setLocation(120, 370);
-
exitB.setLocation(220, 370);
-
nextB.setLocation(320, 370);
-
calcGrade.setLocation(420, 370);
-
-
//add the labels, text fields, and buttons to the pane
-
pane.add(headingL);
-
pane.add(stNameL);
-
pane.add(stNameTF);
-
pane.add(tst1L);
-
pane.add(tst1TF);
-
pane.add(tst2L);
-
pane.add(tst2TF);
-
pane.add(tst3L);
-
pane.add(classAvgTA);
-
pane.add(calcGrade);
-
pane.add(prevB);
-
pane.add(exitB);
-
pane.add(nextB);
-
setVisible(true); //show the window
-
setDefaultCloseOperation(EXIT_ON_CLOSE);
-
System.exit(0);
-
}
-
-
private class ButtonHandler implements ActionListener
-
{
-
public void actionPerformed (ActionEvent e)
-
{
-
if (e.getActionCommand().equals("Previous"))
-
if (displayedStudentIndex > 0)
-
displayGradeAverage(displayedStudentIndex - 1);
-
else
-
displayGradeAverage(displayedStudentIndex);
-
else if (e.getActionCommand().equals("Next"))
-
if (displayedStudentIndex + 1 < noOfStudents)
-
displayGradeAverage(displayedStudentIndex + 1);
-
else
-
displayGradeAverage(displayedStudentIndex);
-
else if (e.getActionCommand().equals("Calc Grade"))
-
displayGradeAverage(0);
-
else
-
System.exit(0);
-
}
-
-
public static void main (String [] args)
-
{
-
new SuperProject();
-
}
-
-
Scanner inFile =
-
new Scanner(new FileReader("AcademicGrades.txt"));
-
{
-
for (int s = 0; s < MAX_NUMBER_OF_STUDENTS; s++)
-
gradeCalc.StudentList[s] = new Student();
-
gradeCalc.noOfStudents =
-
inFile.nextInt(); // get the number of students
-
gradeCalc.score =
-
inFile.nextDouble(); // get the student's scores
-
gradeCalc.getStudentData(inFile);
-
gradeCalc.displayGradeAverage(0);
-
}
-
-
// get the student data from file
-
public void getStudentData(Scanner inFile)
-
{
-
System.out.println("Grade Calculator is getting information...");
-
System.out.println("One Moment Please");
-
}
-
-
-
public void displayGradeAverage(int stName)
-
{
-
displayedStudentIndex = stName;
-
String strName = "";
-
boolean classAvg = studentList[(int) (totalScore / noOfStudents)].getClassAverage();
-
stNameTF.setText(StudentList[stName].getFirstName() + " "
-
+ studentList[stName].getLastName());
-
stAvgTA.setText(""+StudentList[(int) (totalScore / 3.0)].getStudentAverage());
-
classAvgTA.setText(""+StudentList[(int) (totalScore / noOfStudents)].getClassAverage()); }
-
}
-
}
-
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.
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.
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!
@blknmld69,
No worries! Good luck with your schooling.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
by: cheeser |
last post by:
Hello all,
Please see the question in the code below...
Thanks!
Dave
#include <iostream>
|
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
|
by: Lars |
last post by:
Why doesn't the W3C's HTML Validator recognize € and what do I have
to do to make my html-file valid?
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |