Page 2 of 2 FirstFirst 12
Results 21 to 29 of 29
  1. #21
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,618
    Rep Power
    25

    Default Re: Help with 2 classes on this project plzzz

    a box saying data entry is done after fillarray is excuted
    Sorry, I do not see a method called fillarray?
    Can you explain what method you are talking about.

    As before, if you are referring to parts of your program it is important that you spell it correctly. I use the browser's Find to look for what you are talking about and the Find does not find what you are talking about.

  2. #22
    stan989 is offline Member
    Join Date
    Dec 2011
    Posts
    20
    Rep Power
    0

    Default Re: Help with 2 classes on this project plzzz

    Quote Originally Posted by Norm View Post
    Sorry, I do not see a method called fillarray?
    Can you explain what method you are talking about.

    As before, if you are referring to parts of your program it is important that you spell it correctly. I use the browser's Find to look for what you are talking about and the Find does not find what you are talking about.
    The below code is the part where fillarray action is.. my program is now written in gui. 'FillButtonListener'

    Java Code:
    // PROGRAMMING FOR WHEN THE "FILL ARRAY BUTTON" IS PRESSED
        private class FillButtonListener implements ActionListener 
         {
          public void actionPerformed(ActionEvent e) 
            {
                int i;
                int j;
                int FIRSTSID = 75678;
     
                for (i = 0; i < nS; i++) 
                {
                    (sIDs)[i] = FIRSTSID + i;
                    for (j = 0; j < nQ; j++)
                    (sQScores)[i][j] = (int) (((float) rand()) / 324.5);
                }
     
            }
     
            private float rand() 
            {
                Random rand = new Random();
                int number = 0;
                {
                    for (int counter = +1; counter <= 1; counter++) 
                    {
                    number = rand.nextInt(100);
                    System.out.println(number);
                    String output = "\n DATA INPUT COMPLETE FOR QUIZ ";
                    JOptionPane.showMessageDialog(null, output);
                    }
                }
                return number;          
            }
        }

  3. #23
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,618
    Rep Power
    25

    Default Re: Help with 2 classes on this project plzzz

    Is the message you want to show in the rand() method?
    It looks like it will show the message EVERY time you go around the loop in the rand() method.
    Is that what you want to code to do?

    When do you want the message to show? Where in your code would be the best place to show the message?

  4. #24
    stan989 is offline Member
    Join Date
    Dec 2011
    Posts
    20
    Rep Power
    0

    Default Re: Help with 2 classes on this project plzzz

    Quote Originally Posted by Norm View Post
    Is the message you want to show in the rand() method?
    It looks like it will show the message EVERY time you go around the loop in the rand() method.
    Is that what you want to code to do?

    When do you want the message to show? Where in your code would be the best place to show the message?
    :/ i want the message box to be shown at the end of FillButtonListener class. FillButtonListener class takes 'numberOfStudents' and then generates their student IDs by adding 1 to 75678 per students. then it will take 'quizesPerStudent' and generate quiz grade for how ever many times the users inputed in the SetPButtonListener class

    Java Code:
     // 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);
    					 nS = numberOfStudents;
                }
     
                String numString = JOptionPane
                        .showInputDialog("Enter number of quizzes for each student (up to 5)");
                if (numString != null) 
                {
                    quizesPerStudent = Integer.parseInt(numString);
    					 nQ = quizesPerStudent;
                }
            }
        }
        // PROGRAMMING FOR WHEN THE "FILL ARRAY BUTTON" IS PRESSED
        private class FillButtonListener implements ActionListener 
    	 {
          public void actionPerformed(ActionEvent e) 
    		{
    			int i;
    			int j;
    			int FIRSTSID = 75678;
    
    			for (i = 0; i < nS; i++) 
    			{
    				(sIDs)[i] = FIRSTSID + i;
    				for (j = 0; j < nQ; j++)
    				(sQScores)[i][j] = (int) (((float) rand()) / 324.5);
    			}
    
    		}
    
    		private float rand() 
    		{
    			Random rand = new Random();
    			int number = 0;
    			{
    				for (int counter = +1; counter <= 1; counter++) 
    				{
    				number = rand.nextInt(100);
    				System.out.println(number);
    				String output = "\n DATA INPUT COMPLETE FOR QUIZ ";
                    JOptionPane.showMessageDialog(null, output);
    				}
    			}
    			return number;
    			
    		}
    	}
    Last edited by stan989; 12-08-2011 at 06:31 PM.

  5. #25
    stan989 is offline Member
    Join Date
    Dec 2011
    Posts
    20
    Rep Power
    0

    Default Re: Help with 2 classes on this project plzzz

    this is the whole thing i have so far with the latest edits:

    Java Code:
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import java.util.Scanner;
    import java.awt.event.*;
    import javax.swing.JOptionPane;
    import java.util.Random;
    
    public class Final extends JFrame
     
    {
        private int nS;
        private int nQ;
        private int[][] data = new int[nS][nQ];
        private int data1[];
        private int data2[];
    	 int FIRSTSID = 75678;
    	 int longID;
    	 long[] sIDs;
    	 int[][] sQScores;
     
        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) 
                {
                    nS = Integer.parseInt(studentString);
    					 //nS = numberOfStudents;
                }
     
                String numString = JOptionPane
                        .showInputDialog("Enter number of quizzes for each student (up to 5)");
                if (numString != null) 
                {
                    nQ = Integer.parseInt(numString);
    					 //nQ = quizesPerStudent;
                }
            }
        }
        // PROGRAMMING FOR WHEN THE "FILL ARRAY BUTTON" IS PRESSED
        private class FillButtonListener implements ActionListener 
    	 {
          public void actionPerformed(ActionEvent e) 
    		{
    			int i;
    			int j;
    			int FIRSTSID = 75678;
    
    			for (i = 0; i < nS; i++) 
    			{
    				(sIDs)[i] = FIRSTSID + i;
    				for (j = 0; j < nQ; j++)
    				(sQScores)[i][j] = (int) (((float) rand()) / 324.5);
    			}
    
    		}
    
    		private float rand() 
    		{
    			Random rand = new Random();
    			int number = 0;
    			{
    				for (int counter = +1; counter <= 1; counter++) 
    				{
    				number = rand.nextInt(100);
    				System.out.println(number);
    				String output = "\n DATA INPUT COMPLETE FOR QUIZ ";
                    JOptionPane.showMessageDialog(null, output);
    				}
    			}
    			return number;
    			
    		}
    	}
    			
        // 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[nS][nQ];
                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 Bye";
                JOptionPane.showMessageDialog(null, output);
                System.exit(0);
            }
        }
    }

  6. #26
    stan989 is offline Member
    Join Date
    Dec 2011
    Posts
    20
    Rep Power
    0

    Default Re: Help with 2 classes on this project plzzz

    is there something wrong with this line?
    (sIDs)[i] = FIRSTSID + i;

    i am getting:
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at Final$FillButtonListener.actionPerformed(Final.jav a:141)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:2018)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2341)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:252)
    at java.awt.AWTEventMulticaster.mouseReleased(AWTEven tMulticaster.java:289)
    at java.awt.Component.processMouseEvent(Component.jav a:6504)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3321)
    at java.awt.Component.processEvent(Component.java:626 9)
    at java.awt.Container.processEvent(Container.java:222 9)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4860)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2287)
    at java.awt.Component.dispatchEvent(Component.java:46 86)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4832)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4492)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4422)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2273)
    at java.awt.Window.dispatchEventImpl(Window.java:2713 )
    at java.awt.Component.dispatchEvent(Component.java:46 86)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:707)
    at java.awt.EventQueue.access$000(EventQueue.java:101 )
    at java.awt.EventQueue$3.run(EventQueue.java:666)
    at java.awt.EventQueue$3.run(EventQueue.java:664)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:87)
    at java.awt.EventQueue$4.run(EventQueue.java:680)
    at java.awt.EventQueue$4.run(EventQueue.java:678)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 677)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:128)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:117)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:113)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:105)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:90)

  7. #27
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,618
    Rep Power
    25

    Default Re: Help with 2 classes on this project plzzz

    i want the message box to be shown at the end of FillButtonListener class.
    You need to study how java works. There is no execution "at the end of a class". A class can contain methods that can be called from other methods. You can have an end to the execution of a method.
    At the end of a class makes no sense.

    At the end of what method do you want to show the message?

    Your code still has the message you want to show in the middle of a loop inside of the rand() method.

    java.lang.NullPointerException
    at Final$FillButtonListener.actionPerformed(Final.jav a:141)
    What variable on line 141 is null?
    If you can not see which one, add a println just before line 141 to print out the values of all the variables on line 141.

    is there something wrong with this line?
    (sIDs)[i] = FIRSTSID + i;
    Does sIDs have a valid value or is it null?
    Print it out to see.

  8. #28
    stan989 is offline Member
    Join Date
    Dec 2011
    Posts
    20
    Rep Power
    0

    Default Re: Help with 2 classes on this project plzzz

    Quote Originally Posted by Norm View Post
    You need to study how java works. There is no execution "at the end of a class". A class can contain methods that can be called from other methods. You can have an end to the execution of a method.
    At the end of a class makes no sense.

    At the end of what method do you want to show the message?

    Your code still has the message you want to show in the middle of a loop inside of the rand() method.


    What variable on line 141 is null?
    If you can not see which one, add a println just before line 141 to print out the values of all the variables on line 141.


    Does sIDs have a valid value or is it null?
    Print it out to see.
    i mean to say i want to show the message at the end of rand() method.

    sIDs does not have any value and is null. I'm stuck on this part for making the IDs increment by 1. ex: starts 75678, 75679, 75680, etc


    I appreciate all the help i am receiving from you
    Last edited by stan989; 12-08-2011 at 07:36 PM.

  9. #29
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,618
    Rep Power
    25

    Default Re: Help with 2 classes on this project plzzz

    i want to show the message at the end of rand() method.
    The rand() method is called many times from inside of loops in the actionPerformed() method.
    Do you want the message displayed every time the rand() method is called?

    sIDs does not have any value and is null.
    You need to give it a value by using an assignment statement.


    I'm stuck on this part for making the IDs increment by 1. ex: starts
    This can very easily be done by using a for statement. You said: i understand the syntax
    but it seems you need to look at it again, because a for statement is what you need to use.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Java project with multiple classes
    By trakke in forum New To Java
    Replies: 1
    Last Post: 04-28-2011, 09:16 PM
  2. Replies: 23
    Last Post: 04-18-2011, 07:54 PM
  3. need help plzzz for my question
    By yasmin mohamed in forum New To Java
    Replies: 3
    Last Post: 05-20-2010, 03:12 AM
  4. Replies: 5
    Last Post: 12-05-2009, 11:45 PM
  5. Replies: 1
    Last Post: 07-29-2008, 04:08 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
  •