Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 输出二维数组的问题。。。?_Java_Arrays_List_Dimensional - Fatal编程技术网

Java 输出二维数组的问题。。。?

Java 输出二维数组的问题。。。?,java,arrays,list,dimensional,Java,Arrays,List,Dimensional,这是一个项目的开始,该项目组织来自四个不同班级的学生及其成绩。最后,我会加上平均值什么的。然而,目前我在“学生列表字段”中输出成绩时遇到了一个问题——请参见下面的“添加按钮”后面的内容。 我对java和我用来构建它的这个特定程序(netbeans)非常陌生,因此我请求指导和帮助** package studentgrades; import org.jdesktop.application.Action; import org.jdesktop.application.ResourceMap;

这是一个项目的开始,该项目组织来自四个不同班级的学生及其成绩。最后,我会加上平均值什么的。然而,目前我在“学生列表字段”中输出成绩时遇到了一个问题——请参见下面的“添加按钮”后面的内容。 我对java和我用来构建它的这个特定程序(netbeans)非常陌生,因此我请求指导和帮助**

package studentgrades;

import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;

/**
 * The application's main frame.
 */
public class StudentGradesView extends FrameView {

    **//This the all important array...you can list up to 5 students and list 4 test marks of each student.**
    int[][]aryStudent = new int [5][4];

    public StudentGradesView(SingleFrameApplication app) {

****// between here is just a bunch of stuff that was automatically added from when I built the GUI** 

}
    private void exitButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           
    System.exit(0);
    }                                          

    private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {                                          

        **// left "[]" is the student... right "[]" holds the grades...
        // test1Field (1-4) is a JTextField where you input the test grade...I hope that was clear with the name I gave it...**
        aryStudent[0][0] = Integer.parseInt(test1Field.getText());
        aryStudent[0][1] = Integer.parseInt(test2Field.getText());
        aryStudent[0][2] = Integer.parseInt(test3Field.getText());
        aryStudent[0][3] = Integer.parseInt(test4Field.getText());

        aryStudent[1][0] = Integer.parseInt(test1Field.getText());
        aryStudent[1][1] = Integer.parseInt(test2Field.getText());
        aryStudent[1][2] = Integer.parseInt(test3Field.getText());
        aryStudent[1][3] = Integer.parseInt(test4Field.getText());

        aryStudent[2][0] = Integer.parseInt(test1Field.getText());
        aryStudent[2][1] = Integer.parseInt(test2Field.getText());
        aryStudent[2][2] = Integer.parseInt(test3Field.getText());
        aryStudent[2][3] = Integer.parseInt(test4Field.getText());

        aryStudent[3][0] = Integer.parseInt(test1Field.getText());
        aryStudent[3][1] = Integer.parseInt(test2Field.getText());
        aryStudent[3][2] = Integer.parseInt(test3Field.getText());
        aryStudent[3][3] = Integer.parseInt(test4Field.getText());

        aryStudent[4][0] = Integer.parseInt(test1Field.getText());
        aryStudent[4][1] = Integer.parseInt(test2Field.getText());
        aryStudent[4][2] = Integer.parseInt(test3Field.getText());
        aryStudent[4][3] = Integer.parseInt(test4Field.getText());

        aryStudent[5][0] = Integer.parseInt(test1Field.getText());
        aryStudent[5][1] = Integer.parseInt(test2Field.getText());
        aryStudent[5][2] = Integer.parseInt(test3Field.getText());
        aryStudent[5][3] = Integer.parseInt(test4Field.getText());


        int student = 5;
        int marks = 4;

        for (int x=0; x < student ; x++) {
            for (int y=0; y < marks ; y++) {
                **//And if it did work it should output this along with the test scores...At least I hoped it would...**
                studentListField.setText(aryStudent[x][y] + "");
            }
            //System.out.println("");

            /**
             * This was the errors that came up...
             * 
             Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 5
             at studentgrades.StudentGradesView.addButtonActionPerformed(StudentGradesView.java:405)
             at studentgrades.StudentGradesView.access$800(StudentGradesView.java:22)
             at studentgrades.StudentGradesView$4.actionPerformed(StudentGradesView.java:182)
             at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
             at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
             at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
             at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
             at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
             at java.awt.Component.processMouseEvent(Component.java:6505)
             */
        }
    }                                         

    // Variables declaration - do not modify                     
    private javax.swing.JButton addButton;
    private javax.swing.JButton exitButton;
    private javax.swing.JTextField firstNameField;
    private javax.swing.JLabel firstNameLabel;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField lastNameField;
    private javax.swing.JLabel lastNameLabel;
    private javax.swing.JButton listButton;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    private javax.swing.JTextField studentListField;
    private javax.swing.JTextField test1Field;
    private javax.swing.JTextField test2Field;
    private javax.swing.JTextField test3Field;
    private javax.swing.JTextField test4Field;
    private javax.swing.JLabel titleLabel;
    // End of variables declaration                   

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;

    private JDialog aboutBox;
}
package学生成绩;
导入org.jdesktop.application.Action;
导入org.jdesktop.application.ResourceMap;
导入org.jdesktop.application.SingleFrameApplication;
导入org.jdesktop.application.FrameView;
导入org.jdesktop.application.TaskMonitor;
导入java.awt.event.ActionEvent;
导入java.awt.event.ActionListener;
导入javax.swing.Timer;
导入javax.swing.Icon;
导入javax.swing.JDialog;
导入javax.swing.JFrame;
/**
*应用程序的主框架。
*/
公共类学生成绩视图扩展框架视图{
**//这是一个非常重要的数组…您最多可以列出5名学生,并列出每个学生的4个考试分数**
int[][]学生=新int[5][4];
公共学生成绩视图(SingleFrameApplication应用程序){
****//这里只是我构建GUI时自动添加的一堆东西**
}
私有void exitButtonActionPerformed(java.awt.event.ActionEvent evt){
系统出口(0);
}                                          
私有void addButtonActionPerformed(java.awt.event.ActionEvent evt){
**//左“[]”是学生…右“[]”是分数。。。
//test1Field(1-4)是一个JTextField,您可以在其中输入考试成绩…我希望我给它起的名字是清楚的**
arystustudent[0][0]=Integer.parseInt(test1Field.getText());
AryStustudent[0][1]=Integer.parseInt(test2Field.getText());
arystustudent[0][2]=Integer.parseInt(test3Field.getText());
arystustudent[0][3]=Integer.parseInt(test4Field.getText());
aryStudent[1][0]=Integer.parseInt(test1Field.getText());
arystustudent[1][1]=Integer.parseInt(test2Field.getText());
arystustudent[1][2]=Integer.parseInt(test3Field.getText());
aryStudent[1][3]=Integer.parseInt(test4Field.getText());
arystustudent[2][0]=Integer.parseInt(test1Field.getText());
arystustudent[2][1]=Integer.parseInt(test2Field.getText());
arystustudent[2][2]=Integer.parseInt(test3Field.getText());
arystustudent[2][3]=Integer.parseInt(test4Field.getText());
aryStudent[3][0]=Integer.parseInt(test1Field.getText());
arystustudent[3][1]=Integer.parseInt(test2Field.getText());
arystustudent[3][2]=Integer.parseInt(test3Field.getText());
arystustudent[3][3]=Integer.parseInt(test4Field.getText());
aryStudent[4][0]=Integer.parseInt(test1Field.getText());
arystustudent[4][1]=Integer.parseInt(test2Field.getText());
arystustudent[4][2]=Integer.parseInt(test3Field.getText());
arystustudent[4][3]=Integer.parseInt(test4Field.getText());
aryStudent[5][0]=Integer.parseInt(test1Field.getText());
arystustudent[5][1]=Integer.parseInt(test2Field.getText());
arystustudent[5][2]=Integer.parseInt(test3Field.getText());
arystustudent[5][3]=Integer.parseInt(test4Field.getText());
int学生=5;
整数分=4分;
对于(int x=0;xaryStudent[5][0] = Integer.parseInt(test1Field.getText());
aryStudent[5][1] = Integer.parseInt(test2Field.getText());
aryStudent[5][2] = Integer.parseInt(test3Field.getText());
aryStudent[5][3] = Integer.parseInt(test4Field.getText());
HashMap<Integer, Integer> studentsMarks = new HashMap<Integer, Integer>();
//To insert
studentsMarks.put(//key, //value);
//To retrive
studentMarks.get(//key);