Results 1 to 2 of 2
  1. #1
    william979 is offline Member
    Join Date
    Apr 2011
    Location
    TX
    Posts
    8
    Rep Power
    0

    Default Need help with java program. Wont execute the fill array

    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 Final extends JFrame
    
    {
    	private int numberOfStudents;
    	private int quizesPerStudent;
    	private int[][] data = new int[numberOfStudents][quizesPerStudent];
    	private int data1[];
    	private int data2[];
    
    	public Final() 
    	{
    
    		// 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 Final();
    		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) 
    		{
    
    			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);
    			}
    
    			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 ADIOS";
    			JOptionPane.showMessageDialog(null, output);
    			System.exit(0);
    		}
    	}
    }
    Last edited by Fubarable; 04-26-2011 at 03:23 AM.

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

    Default

    Moderator Action: Duplicate thread removed, thread moved from Forum Lobby to the New to Java forum, and code tags added.

    Original poster, please only one thread per question, and please provide some details to your thread. The more information you can provide for us, the better we can help you. Much luck.

Similar Threads

  1. how to execute the Java program to 0 sec?
    By yanipra in forum New To Java
    Replies: 4
    Last Post: 03-01-2011, 10:33 AM
  2. Replies: 0
    Last Post: 04-04-2008, 03:40 PM
  3. Replies: 0
    Last Post: 10-04-2007, 10:33 PM
  4. Execute a new program in java
    By mathias in forum Advanced Java
    Replies: 1
    Last Post: 07-31-2007, 06:42 AM

Posting Permissions

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