I also can not figure out how to get jtable to print my dispbuttonlistener
thanks so much in advance
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);
}
}
}
is there something wrong with this line?
(sIDs)[i] = FIRSTSID + i;
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Final$FillButtonListener.actionPerformed(Final.java:141)
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.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
at java.awt.Component.processMouseEvent(Component.java:6504)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6269)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4860)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4686)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.window.dispatchEventImpl(window.java:2713)
at java.awt.Component.dispatchEvent(Component.java:4686)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java: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.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(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.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

New Topic/Question
Reply



MultiQuote







|