Results 1 to 6 of 6
  1. #1
    absoltrainer is offline Member
    Join Date
    Dec 2009
    Posts
    3
    Rep Power
    0

    Exclamation NEED HELP with project, uses GUI.

    Here's the coding first of all:

    Java Code:
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import java.util.Scanner;
    import java.awt.event.*;
    import javax.swing.JOptionPane;
    
    public class collegefinal extends JFrame
    
    {
    	public collegefinal()
           	{
    
    ////////////////////CREATES BUTTONS///////////////////////////////////////////////////////
             JPanel p1 = new JPanel(new FlowLayout(FlowLayout.CENTER, 15, 10));
             JButton Help = new JButton("HELP");
             JButton SetP = new JButton("SET PARAMETERS");
             JButton Fill = new JButton("FILL ARRAY");
             JButton Disp = new JButton("DISPLAY RESULTS");
             JButton Quit = new JButton("QUIT");
    
    ///////////////////CREATES DESCRIPTIONS FOR BUTTONS//////////////////////////////////////
             Help.setToolTipText("Displays Instructions on how to use this program.");
             SetP.setToolTipText("Promps user for number of students and quizzes.");
             Fill.setToolTipText("Inserts Values pre-set in SET PAREMETERS.");
             Disp.setToolTipText("Displays the Results");
             Quit.setToolTipText("Close Program");
    
    ////////////////////ADDS BUTTONS TO JFRAME/////////////////////////////////////////////////
             p1.add(Help);
             p1.add(SetP);
             p1.add(Fill);
             p1.add(Disp);
             p1.add(Quit);
             p1.setBorder(new TitledBorder( "Grade Compiling Program"));
    
    ////////////////////ADJUSTS THE FONT AND BORDER OPTIONS FOR JFRAME/////////////////////////
             Font largeFont = new Font("TimesRoman", Font.BOLD, 20);
             Border lineBorder = new LineBorder(Color.BLACK, 2);
    
    ////////////////////ADDS ALL OF THE ABOVE INTO GUI FIELD//////////////////////////////////
    		 add(p1);
    
    ///////////////////REGISTERS EVENT LISTENERS WITH ALL 5 BUTTONS///////////////////////////
          Help.addActionListener(new HelpButtonListener());
          SetP.addActionListener(new SetPButtonListener());
          Fill.addActionListener(new FillButtonListener());
          Disp.addActionListener(new DispButtonListener());
          Quit.addActionListener(new QuitButtonListener());
    
    
    
    
    
          }
    
    	public static void main(String[] args)
          {
    ///////////////////CREATES JFRAME AND PAREMETERS FOR JFRAME/////////////////////////////
             JFrame frame = new collegefinal();
             frame.setTitle("College Final Project");
             frame.setSize(750, 500);
             frame.setLocationRelativeTo(null); // Center the frame
             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             frame.setVisible(true);
    
    
           }
    
    ///////////////////PROGRAMMING FOR WHEN THE "HELP BUTTON" IS PRESSED////////////////////
         private class HelpButtonListener implements ActionListener
       {
          public void actionPerformed(ActionEvent e)
          {
    
          	 System.out.println();
    				String output = "\n______________________HELP MENU__________________________" +///This is the output that will be diplayed when the HELP button is pressed
    					"\n Welcome to the Help Menu, here you will find tips to using this program." +
    					"\n" +
    					"\n The first step is to click the 'SET PARAMETERS' button. Here you will   " +
    					"\n input the number of students (up to 50) and number of quizzes for each  " +
    					"\n student (up to 5.) " +
    					"\n " +
    					"\n Next you will select the 'FILL ARRAY' button. This button will open up" +
    			 		"\n the menu to select the ID numbers and quiz grades for each student and " +
    				 	"\n quiz, then store them within the paremeters set in 'SET PARAMETERS'." +
    				 	"\n " +
    					"\n Finally you will click the 'DISPLAY' button. This button will compile all" +
    					"\n the data you entered in the last two sections and display the results." +
    					"\n This program computes and displays the lowest, highest, average, and" +
    					"\n medium for each grade of each set of quizzes." +
    					"\n " +
    					"\n As an added note if you wish to quit this program at any time, simply" +
    					"\n press the 'QUIT' button and the program will close";
    
    				JOptionPane.showMessageDialog(null,output); //Dispays the above information for the user in a seperate window that closes when OK is pressed.
    
          }
       }
    
    
    ///////////////////PROGRAMMING FOR WHEN THE "SET PARAMETERS BUTTON" IS PRESSED////////////////////
       private class SetPButtonListener implements ActionListener
       {
          public void actionPerformed(ActionEvent e)
          {
    
    
          	String studentString = JOptionPane.showInputDialog("Enter number of students (up to 50)");
    		int student = Integer.parseInt(studentString);
    
    
    		String numString = JOptionPane.showInputDialog("Enter number of quizzes for each student (up to 5)");
    		int num = Integer.parseInt(numString);
    
    
          }
       }
    
    ///////////////////PROGRAMMING FOR WHEN THE "FILL ARRAY BUTTON" IS PRESSED//////////////
       private class FillButtonListener implements ActionListener
       {
          public void actionPerformed(ActionEvent e)
          {
    		int[][] quizzes = new int[student][num];
    
    
    
    	}
    
    
    
        }
    
    
    ///////////////////PROGRAMMING FOR WHEN THE "DISPLAY BUTTON" IS PRESSED//////////////////
       private class DispButtonListener implements ActionListener
       {
          public void actionPerformed(ActionEvent e)
          {
    
          }
       }
    
    ///////////////////PROGRAMMING FOR WHEN THE "QUIT BUTTON" IS PRESSED////////////////////
       private class QuitButtonListener implements ActionListener
       {
          public void actionPerformed(ActionEvent e)
          {
    
          }
    
    
    
    }
    }



    It's pretty simple, click a button to make parameters for an array, then press another to input data into that array based on the parameters. The issue I am having is getting the input variables from SetPButtonListener and keeping them while I execute the programming in FillButton Listener.

    I tried using "implements" and such, but that would cause the reptition of the SetP programming when I pressed the Fill Array button.

    I've spent all night trying to figure this out, I'm really lost.

    In case I'm being a little confusing in my requst (confusing myself at least)
    I need to take the parameters I input via dialogue box in SetPButtonListener and somehow be able to keep and use them in FillButtonListener

    If that makes any sense.

    Advice would be appreciate.
    Last edited by Fubarable; 12-09-2009 at 05:01 PM. Reason: Code tags added so that code will retain its formatting

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Hello and welcome to our forum! I hope you don't mind, but I added code tags to your code to help make it retain its formating and thus make it more easily read. To learn how to do this yourself, please check out my signature below and click on the link.

    One problem I see in your code is found here:

    Java Code:
       private class SetPButtonListener implements ActionListener
       {
          public void actionPerformed(ActionEvent e)
          {
    
    
          	String studentString = JOptionPane.showInputDialog("Enter number of students (up to 50)");
    		int student = Integer.parseInt(studentString);
    
    
    		String numString = JOptionPane.showInputDialog("Enter number of quizzes for each student (up to 5)");
    		int num = Integer.parseInt(numString);
    
    
          }
       }
    your numString and num int variables are declared within this method making them "local to this method". In English this means that outside this actionPerformed method, the variables don't exist. To fix this, give your class some class fields that are visible throughout the class. For instance:

    Java Code:
    // note that collegefinal per convention should be CollegeFinal
    public class collegefinal extends JFrame {
    
      private int numberOfStudents;  // *** here are the class fields ***
      private int quizesPerStudent;  // *** and here ***
      
      public collegefinal() {
        //....
      }
    
      public static void main(String[] args) {
        //....
      }
    
      private class SetPButtonListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
    
          String studentString = JOptionPane.showInputDialog("Enter number of students (up to 50)");
          //int student = Integer.parseInt(studentString);
    
          // first make sure that OK was pressed.  Else String returned is null 
          if (studentString != null) {
            // this should be in a try/catch NumberFormatException block
            numberOfStudents = Integer.parseInt(studentString);
          }
    
          String numString = JOptionPane.showInputDialog("Enter number of quizzes for each student (up to 5)");
          // int num = Integer.parseInt(numString);
          if (numString != null) {
            // again this should be in a try/catch block
            quizesPerStudent = Integer.parseInt(numString);
          }
    
        }
      }
    See if this helps, and please get back to us with your results!

  3. #3
    absoltrainer is offline Member
    Join Date
    Dec 2009
    Posts
    3
    Rep Power
    0

    Default

    That helped a ton, thanks for the help. I didn't expect it to be something so simple. I got the parameters to be inputed and made Fill Array input student IDs and randomely input quiz grades according to the parameters.

    My new problem is with displaying the array. I need to have it displayed in the "DispButtonListener" area, but I honestly have no idea how to do it. Everything I try is messing up. I'm trying to do it in a diologue box, but it's just not working. I'm not specifically getting errors, I'm just having issues getting it to diplay at all.

    Advice needed again

    Java Code:
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import java.util.Scanner;
    import java.awt.event.*;
    import javax.swing.JOptionPane;
    
    public class collegefinal extends JFrame
    
    {
    	private int numberOfStudents;
      	private int quizesPerStudent;
      	private int[][] data = new int[numberOfStudents][quizesPerStudent];
      	private int data1[];
      	private int data2[];
    
    	public collegefinal()
           	{
    
    
    ////////////////////CREATES BUTTONS///////////////////////////////////////////////////////
             JPanel p1 = new JPanel(new FlowLayout(FlowLayout.CENTER, 15, 10));
             JButton Help = new JButton("HELP");
             JButton SetP = new JButton("SET PARAMETERS");
             JButton Fill = new JButton("FILL ARRAY");
             JButton Disp = new JButton("DISPLAY RESULTS");
             JButton Quit = new JButton("QUIT");
    
    ///////////////////CREATES DESCRIPTIONS FOR BUTTONS//////////////////////////////////////
             Help.setToolTipText("Displays Instructions on how to use this program.");
             SetP.setToolTipText("Promps user for number of students and quizzes.");
             Fill.setToolTipText("Inserts Values pre-set in SET PAREMETERS.");
             Disp.setToolTipText("Displays the Results");
             Quit.setToolTipText("Close Program");
    
    ////////////////////ADDS BUTTONS TO JFRAME/////////////////////////////////////////////////
             p1.add(Help);
             p1.add(SetP);
             p1.add(Fill);
             p1.add(Disp);
             p1.add(Quit);
             p1.setBorder(new TitledBorder( "Grade Compiling Program"));
    
    ////////////////////ADJUSTS THE FONT AND BORDER OPTIONS FOR JFRAME/////////////////////////
             Font largeFont = new Font("TimesRoman", Font.BOLD, 20);
             Border lineBorder = new LineBorder(Color.BLACK, 2);
    
    ////////////////////ADDS ALL OF THE ABOVE INTO GUI FIELD//////////////////////////////////
    		 add(p1);
    
    ///////////////////REGISTERS EVENT LISTENERS WITH ALL 5 BUTTONS///////////////////////////
          Help.addActionListener(new HelpButtonListener());
          SetP.addActionListener(new SetPButtonListener());
          Fill.addActionListener(new FillButtonListener());
          Disp.addActionListener(new DispButtonListener());
          Quit.addActionListener(new QuitButtonListener());
    
    
    
    
    
          }
    
    	public static void main(String[] args)
          {
    ///////////////////CREATES JFRAME AND PAREMETERS FOR JFRAME/////////////////////////////
             JFrame frame = new collegefinal();
             frame.setTitle("College Final Project");
             frame.setSize(750, 500);
             frame.setLocationRelativeTo(null); // Center the frame
             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             frame.setVisible(true);
    
    
           }
    
    ///////////////////PROGRAMMING FOR WHEN THE "HELP BUTTON" IS PRESSED////////////////////
         private class HelpButtonListener implements ActionListener
       {
          public void actionPerformed(ActionEvent e)
          {
    
          	 System.out.println();
    				String output = "\n______________________HELP MENU__________________________" +///This is the output that will be diplayed when the HELP button is pressed
    					"\n Welcome to the Help Menu, here you will find tips to using this program." +
    					"\n" +
    					"\n The first step is to click the 'SET PARAMETERS' button. Here you will   " +
    					"\n input the number of students (up to 50) and number of quizzes for each  " +
    					"\n student (up to 5.) " +
    					"\n " +
    					"\n Next you will select the 'FILL ARRAY' button. This button will open up" +
    			 		"\n the menu to select the ID numbers and quiz grades for each student and " +
    				 	"\n quiz, then store them within the paremeters set in 'SET PARAMETERS'." +
    				 	"\n " +
    					"\n Finally you will click the 'DISPLAY' button. This button will compile all" +
    					"\n the data you entered in the last two sections and display the results." +
    					"\n This program computes and displays the lowest, highest, average, and" +
    					"\n medium for each grade of each set of quizzes." +
    					"\n " +
    					"\n As an added note if you wish to quit this program at any time, simply" +
    					"\n press the 'QUIT' button and the program will close";
    
    				JOptionPane.showMessageDialog(null,output); //Dispays the above information for the user in a seperate window that closes when OK is pressed.
    
          }
       }
    
    
    ///////////////////PROGRAMMING FOR WHEN THE "SET PARAMETERS BUTTON" IS PRESSED////////////////////
       private class SetPButtonListener implements ActionListener
       {
          public void actionPerformed(ActionEvent e)
          {
        String studentString = JOptionPane.showInputDialog("Enter number of students (up to 50)");
          //int student = Integer.parseInt(studentString);
    
          // first make sure that OK was pressed.  Else String returned is null
          if (studentString != null) {
            // this should be in a try/catch NumberFormatException block
            numberOfStudents = Integer.parseInt(studentString);
          }
    
          String numString = JOptionPane.showInputDialog("Enter number of quizzes for each student (up to 5)");
          // int num = Integer.parseInt(numString);
          if (numString != null)
          	{
            // again this should be in a try/catch block
            quizesPerStudent = Integer.parseInt(numString);
          }
    
        }
      }
    
    ///////////////////PROGRAMMING FOR WHEN THE "FILL ARRAY BUTTON" IS PRESSED//////////////
       private class FillButtonListener implements ActionListener
       {
          public void actionPerformed(ActionEvent e)
          {
    
    
    		int[] data1 = new int[numberOfStudents];
    
    		for(int x=0; x<data1.length; x++)
    			{
    		String idString = JOptionPane.showInputDialog("Enter ID number for student " + x);
          	data1[x] = Integer.parseInt(idString);
    			}
    
    
    		int[] data2 = new int[quizesPerStudent];
    
    		for(int y=0; y<data2.length; y++)
    		{
    			data2[y] = (int)(Math.random()*100);
    			if(y==data2.length)
    				System.out.println();
    				String output = "\n DATA INPUT COMPLETE FOR QUIZ " + y;
    				JOptionPane.showMessageDialog(null,output);
    
    	  	}
    
      	  }
       }
    
    
    
    ///////////////////PROGRAMMING FOR WHEN THE "DISPLAY BUTTON" IS PRESSED//////////////////
       private class DispButtonListener implements ActionListener
       {
          public void actionPerformed(ActionEvent e)
          {
    		
    
    
    
          }
       }
    
    ///////////////////PROGRAMMING FOR WHEN THE "QUIT BUTTON" IS PRESSED////////////////////
       private class QuitButtonListener implements ActionListener
       {
          public void actionPerformed(ActionEvent e)
          {
    
          }
    
    
    
    }
    }

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by absoltrainer View Post
    That helped a ton, thanks for the help. I didn't expect it to be something so simple. I got the parameters to be inputed and made Fill Array input student IDs and randomely input quiz grades according to the parameters.
    Great, I'm glad it helped.

    My new problem is with displaying the array. I need to have it displayed in the "DispButtonListener" area, but I honestly have no idea how to do it. Everything I try is messing up. I'm trying to do it in a diologue box, but it's just not working. I'm not specifically getting errors, I'm just having issues getting it to diplay at all.
    Please post code that shows your best attempt to display something. Otherwise we have no idea about what's messing you up.

  5. #5
    absoltrainer is offline Member
    Join Date
    Dec 2009
    Posts
    3
    Rep Power
    0

    Default

    No problem, this was last code I had tried before posting here. Now when I compile the code I get 0 errors. However when I actually execute it, it works fine until I get to the display part. Then instead of diplaying, the command prompt (black screen) completly spazzes out (I believe this is the right word lol). Basically the entire screen fills up with different things, of which I don't know what any of them mean. If that makes any sense.

    Java Code:
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import java.util.Scanner;
    import java.awt.event.*;
    import javax.swing.JOptionPane;
    
    public class collegefinal extends JFrame
    
    {
    	private int numberOfStudents;
      	private int quizesPerStudent;
      	private int[][] data = new int[numberOfStudents][quizesPerStudent];
      	private int data1[];
      	private int data2[];
    
    	public collegefinal()
           	{
    
    
    ////////////////////CREATES BUTTONS///////////////////////////////////////////////////////
             JPanel p1 = new JPanel(new FlowLayout(FlowLayout.CENTER, 15, 10));
             JButton Help = new JButton("HELP");
             JButton SetP = new JButton("SET PARAMETERS");
             JButton Fill = new JButton("FILL ARRAY");
             JButton Disp = new JButton("DISPLAY RESULTS");
             JButton Quit = new JButton("QUIT");
    
    ///////////////////CREATES DESCRIPTIONS FOR BUTTONS//////////////////////////////////////
             Help.setToolTipText("Displays Instructions on how to use this program.");
             SetP.setToolTipText("Promps user for number of students and quizzes.");
             Fill.setToolTipText("Inserts Values pre-set in SET PAREMETERS.");
             Disp.setToolTipText("Displays the Results");
             Quit.setToolTipText("Close Program");
    
    ////////////////////ADDS BUTTONS TO JFRAME/////////////////////////////////////////////////
             p1.add(Help);
             p1.add(SetP);
             p1.add(Fill);
             p1.add(Disp);
             p1.add(Quit);
             p1.setBorder(new TitledBorder( "Grade Compiling Program"));
    
    ////////////////////ADJUSTS THE FONT AND BORDER OPTIONS FOR JFRAME/////////////////////////
             Font largeFont = new Font("TimesRoman", Font.BOLD, 20);
             Border lineBorder = new LineBorder(Color.BLACK, 2);
    
    ////////////////////ADDS ALL OF THE ABOVE INTO GUI FIELD//////////////////////////////////
    		 add(p1);
    
    ///////////////////REGISTERS EVENT LISTENERS WITH ALL 5 BUTTONS///////////////////////////
          Help.addActionListener(new HelpButtonListener());
          SetP.addActionListener(new SetPButtonListener());
          Fill.addActionListener(new FillButtonListener());
          Disp.addActionListener(new DispButtonListener());
          Quit.addActionListener(new QuitButtonListener());
    
    
    
    
    
          }
    
    	public static void main(String[] args)
          {
    ///////////////////CREATES JFRAME AND PAREMETERS FOR JFRAME/////////////////////////////
             JFrame frame = new collegefinal();
             frame.setTitle("College Final Project");
             frame.setSize(750, 500);
             frame.setLocationRelativeTo(null); // Center the frame
             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             frame.setVisible(true);
    
    
           }
    
    ///////////////////PROGRAMMING FOR WHEN THE "HELP BUTTON" IS PRESSED////////////////////
         private class HelpButtonListener implements ActionListener
       {
          public void actionPerformed(ActionEvent e)
          {
    
          	 System.out.println();
    				String output = "\n______________________HELP MENU__________________________" +///This is the output that will be diplayed when the HELP button is pressed
    					"\n Welcome to the Help Menu, here you will find tips to using this program." +
    					"\n" +
    					"\n The first step is to click the 'SET PARAMETERS' button. Here you will   " +
    					"\n input the number of students (up to 50) and number of quizzes for each  " +
    					"\n student (up to 5.) " +
    					"\n " +
    					"\n Next you will select the 'FILL ARRAY' button. This button will open up" +
    			 		"\n the menu to select the ID numbers and quiz grades for each student and " +
    				 	"\n quiz, then store them within the paremeters set in 'SET PARAMETERS'." +
    				 	"\n " +
    					"\n Finally you will click the 'DISPLAY' button. This button will compile all" +
    					"\n the data you entered in the last two sections and display the results." +
    					"\n This program computes and displays the lowest, highest, average, and" +
    					"\n medium for each grade of each set of quizzes." +
    					"\n " +
    					"\n As an added note if you wish to quit this program at any time, simply" +
    					"\n press the 'QUIT' button and the program will close";
    
    				JOptionPane.showMessageDialog(null,output); //Dispays the above information for the user in a seperate window that closes when OK is pressed.
    
          }
       }
    
    
    ///////////////////PROGRAMMING FOR WHEN THE "SET PARAMETERS BUTTON" IS PRESSED////////////////////
       private class SetPButtonListener implements ActionListener
       {
          public void actionPerformed(ActionEvent e)
          {
        String studentString = JOptionPane.showInputDialog("Enter number of students (up to 50)");
          	  if (studentString != null) {
              numberOfStudents = Integer.parseInt(studentString);
          }
    
       String numString = JOptionPane.showInputDialog("Enter number of quizzes for each student (up to 5)");
          	  if (numString != null){
    
            quizesPerStudent = Integer.parseInt(numString);
          }
    
        }
      }
    
    ///////////////////PROGRAMMING FOR WHEN THE "FILL ARRAY BUTTON" IS PRESSED//////////////
       private class FillButtonListener implements ActionListener
       {
          public void actionPerformed(ActionEvent e)
          {
    
    
    		int[] data1 = new int[numberOfStudents];
    
    		for(int x=0; x<data1.length; x++)
    			{
    		String idString = JOptionPane.showInputDialog("Enter ID number for student " + x);
          	data1[x] = Integer.parseInt(idString);
    			}
    
    
    		int[] data2 = new int[quizesPerStudent];
    
    		for(int y=0; y<data2.length; y++)
    		{
    			data2[y] = (int)(Math.random()*100);
    			if(y==data2.length)
    				System.out.println();
    				String output = "\n DATA INPUT COMPLETE FOR QUIZ " + y;
    				JOptionPane.showMessageDialog(null,output);
    
    	  	}
    
      	  }
       }
    
    
    
    ///////////////////PROGRAMMING FOR WHEN THE "DISPLAY BUTTON" IS PRESSED//////////////////
       private class DispButtonListener implements ActionListener
       {
          public void actionPerformed(ActionEvent e)
          {
    
    				System.out.println();
    				String output = "\n Students and Grades\n " + data[numberOfStudents][quizesPerStudent];
    				JOptionPane.showMessageDialog(null,output);
    
          }
       }
    
    ///////////////////PROGRAMMING FOR WHEN THE "QUIT BUTTON" IS PRESSED////////////////////
       private class QuitButtonListener implements ActionListener
       {
          public void actionPerformed(ActionEvent e)
          {
          	 System.out.println();
    				String output = "\n GOODBYE";
    				JOptionPane.showMessageDialog(null,output);
    				System.exit(0);
    
    
    
          }
    
    
    
    }
    }

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    There are some problems with your code. Please look at the comments

    Java Code:
    public class collegefinal extends JFrame {
       private int numberOfStudents;  // right now this is 0
       private int quizesPerStudent;  // right now this is 0
    
       // you're constructing data before you know what the number of students and quizes per students will be.
       // this will create an 0 by 0 array... not very useful!
       private int[][] data = new int[numberOfStudents][quizesPerStudent];
       private int data1[];
       private int data2[];
    
       public collegefinal() {
    
          //...... etc....
    
       }
    
       public static void main(String[] args) {
          //..... etc ....
       }
    
       private class HelpButtonListener implements ActionListener {
          public void actionPerformed(ActionEvent e) {
             //... etc...
          }
       }
    
       private class SetPButtonListener implements ActionListener {
          public void actionPerformed(ActionEvent e) {
             String studentString = JOptionPane
                      .showInputDialog("Enter number of students (up to 50)");
    
             if (studentString != null) {
    
                numberOfStudents = Integer.parseInt(studentString);
             }
    
             String numString = JOptionPane
                      .showInputDialog("Enter number of quizzes for each student (up to 5)");
    
             if (numString != null) {
    
                quizesPerStudent = Integer.parseInt(numString);
             }
             // ****** now you know what numberOfStudents and quizesPerStudent will be. *****
             // ****** here is where you should initialize your data 2-D int array *****
    
          }
       }
    
       private class FillButtonListener implements ActionListener {
          public void actionPerformed(ActionEvent e) {
    
             //**** int[] data1 = new int[numberOfStudents]; // *** don't redeclare this variable as it will only be a local variable
    
             // instead do:
             data1 = new int[numberOfStudents]
    
             for (int x = 0; x < data1.length; x++) {
                String idString = JOptionPane
                         .showInputDialog("Enter ID number for student " + x);
                data1[x] = Integer.parseInt(idString);
             }
    
             // **** same deal here, don't redeclare this variable.  Instead use the
             // **** class variable
             // **** actually, better would be to fill the data int[][] array instead
             int[] data2 = new int[quizesPerStudent];
    
             for (int y = 0; y < data2.length; y++) {
                data2[y] = (int) (Math.random() * 100);
                if (y == data2.length) System.out.println();
                String output = "\n DATA INPUT COMPLETE FOR QUIZ " + y;
                JOptionPane.showMessageDialog(null, output);
    
             }
    
          }
       }
    For your display, I'd create a JTable and display it in a JOptionPane, but this may be just a little bit beyond you. Otherwise you could build a String showing the results by looping through your data array. You would need a set of nested for loops, the outer for loop for the data array's rows and the inner loop for the columns.

Similar Threads

  1. Big project
    By bubbless in forum Advanced Java
    Replies: 16
    Last Post: 08-11-2009, 05:02 AM
  2. project
    By bhadz202 in forum New To Java
    Replies: 13
    Last Post: 03-14-2009, 08:05 AM
  3. need help for a project
    By megironi in forum New To Java
    Replies: 4
    Last Post: 02-07-2009, 09:28 PM
  4. open existing project project ..
    By itaipee in forum Eclipse
    Replies: 1
    Last Post: 12-28-2008, 09:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •