hey all help please

Thread Solved

Join Date: Apr 2008
Posts: 75
Reputation: mustafaneguib is an unknown quantity at this point 
Solved Threads: 3
mustafaneguib mustafaneguib is offline Offline
Junior Poster in Training

hey all help please

 
0
  #1
Jul 29th, 2009
hey all,
i am now making a gpa calculator.

i am using 4 classes which form into seperate linked lists. one linked list is for the custom gui, and the other linked list is for the data list.

i am using custom images for this program which i import using the LoadImageApp.java, so if you need the images to execute this program, just tell me.

there are a couple of problems that i have encountered.

firstly, when i use clean and build using netbeacs 6.7 it creates my jar file. when i try to execute the jar file it does not execute.

secondly, the menu bar gives me exceptions. the code for the
guiList.java. i would like to know how to fix these exceptions. the code for the menu bar can be found in the file guiNode.java.

thirdly, my cgpa does not calculate. actually there are two options that the user has when he enters the data. he can either submit and add a new course or submit and not add a new course.

when the user enters only one course and then selects the submit and do not enter a new course the correct cgpa is shown, however if the user decides to add more courses, and then finaly selects the submit and do not add a new course the value for cgpa comes as 0.0 which was set in the constructor in the file gpaList.java.

the data is entered into the linked list correctly as the list is printed and then the cgpa is supposed to print.

please help

following are the files,

guiList.java

  1.  
  2. /*
  3.  * To change this template, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. /**
  8.  *
  9.  * @author Mustafa Neguib
  10.  */
  11. public class guiList{
  12.  
  13. private guiNode rootGui;
  14.  
  15. public guiList()
  16. {
  17.  
  18. rootGui=null;
  19.  
  20. }//end constructor
  21.  
  22.  
  23. public void buildGui(int page)
  24. {
  25.  
  26. guiNode temp= new guiNode(page);
  27. guiNode ptr;
  28.  
  29. if(rootGui==null)
  30. {
  31. rootGui=temp;
  32. rootGui.rootGuiNode=rootGui;
  33.  
  34. }//end if
  35. else
  36. {
  37.  
  38. ptr=rootGui;
  39.  
  40. while(ptr.next!=null)
  41. {//execute the while statement as long as the next is not null
  42.  
  43. ptr=ptr.next;
  44.  
  45. }//end while
  46.  
  47.  
  48. ptr.next=temp; //point ptr to the new node
  49.  
  50. }//end else
  51.  
  52. }//end function buildGui
  53.  
  54.  
  55. public void run()
  56. {
  57.  
  58. rootGui.setVisible(true);
  59.  
  60. }//end function run
  61.  
  62.  
  63. public static void main(String [] args)
  64. {
  65.  
  66.  
  67. guiList listGui;
  68.  
  69.  
  70. listGui=new guiList();
  71.  
  72. int i=1;
  73.  
  74. while(i<5)
  75. {
  76.  
  77. listGui.buildGui(i);
  78.  
  79. i++;
  80.  
  81. }//end while
  82.  
  83. listGui.run();
  84.  
  85. }//end function main
  86.  
  87.  
  88. }//end class guiList

guiNode.java
  1.  
  2. /*
  3.  * To change this template, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. /**
  8.  *
  9.  * @author Mustafa Neguib
  10.  */
  11.  
  12.  
  13. import javax.swing.*;
  14. import java.awt.*;
  15. import java.awt.event.*;
  16.  
  17.  
  18. public class guiNode extends JFrame implements ActionListener {
  19.  
  20. /** Declaring variables for the gui. */
  21.  
  22. public int id;
  23.  
  24. public Container contentPane;
  25. public JPanel header;
  26. public JPanel back;
  27. public JPanel menu;
  28. public JPanel content;
  29. public JPanel footer;
  30. public JPanel textField;
  31.  
  32.  
  33. public JTextField nameOfCourse;
  34. public JTextField creditHoursOfCourse;
  35. public JTextField gpaOfCourse;
  36.  
  37. public JLabel name;
  38. public JLabel courseGpa;
  39. public JLabel hours;
  40. public JLabel coursesListLabel;
  41.  
  42.  
  43. public JButton startSoftware;
  44. public JButton exitSoftware;
  45. public JButton submit;
  46. public JButton addMore;
  47.  
  48. public JLabel contentLabel;
  49. public JLabel footerLabel;
  50.  
  51. public JMenu fileMenu;
  52. public JMenuItem item;
  53. public JMenuBar menuBar;
  54.  
  55.  
  56.  
  57. public guiNode next;
  58. public static gpaList nodeGpaList;
  59. public static guiNode rootGuiNode;
  60.  
  61.  
  62.  
  63.  
  64. public guiNode(int page)
  65. {
  66.  
  67. next=null;
  68.  
  69.  
  70. switch(page)
  71. {
  72.  
  73.  
  74.  
  75. case 1:
  76.  
  77. id=1;
  78. contentPane= getContentPane();
  79.  
  80. setSize(640,680);
  81. setResizable(false);
  82.  
  83. setTitle("MN Tech Solutions GPA Calculator");
  84. setLocation(0,0);
  85.  
  86. /** Creating JPanel objects */
  87.  
  88. back=new JPanel();
  89. header = new JPanel();
  90. menu=new JPanel();
  91. content=new JPanel();
  92. footer=new JPanel();
  93.  
  94.  
  95.  
  96.  
  97. //** Build the menu of the menu bar */
  98.  
  99. //** Build File Menu */
  100.  
  101. fileMenu= new JMenu("File");
  102. item= new JMenuItem("Main Page");
  103. item.addActionListener(this);
  104. fileMenu.add(item);
  105.  
  106. fileMenu.addSeparator();
  107. item= new JMenuItem("Exit Software");
  108. item.addActionListener(this);
  109. fileMenu.add(item);
  110.  
  111.  
  112.  
  113. menuBar= new JMenuBar();
  114. setJMenuBar(menuBar);
  115. menuBar.add(fileMenu);
  116.  
  117.  
  118.  
  119. back.setLayout(null); //i am using absolute positioning
  120.  
  121. /** Set the background color of each JPanel object to black. */
  122.  
  123. menu.setBackground(Color.BLACK);
  124. header.setBackground(Color.BLACK);
  125.  
  126. content.setBackground(Color.BLACK);
  127. footer.setBackground(Color.BLACK);
  128.  
  129. /** I am setting the bounds of the JPanel objects so that they can be displayed on the screen
  130.   and i am also inserting the data to be shown in the JPanel objects.
  131.   */
  132.  
  133. header.setBounds(0,0,640,80);
  134. header.add(new LoadImageApp("images/logo.gif"));
  135.  
  136. menu.setBounds(0,80,640,60);
  137. menu.add(new LoadImageApp("images/menu.gif"));
  138.  
  139. content.setBounds(0,140,640,400);
  140. content.add(new LoadImageApp("images/content.gif"));
  141.  
  142. contentLabel=new JLabel("MN Tech Solutions GPA Calculator");
  143. contentLabel.setBounds(40,180,200,20);
  144. contentPane.add(contentLabel);
  145.  
  146. contentLabel=new JLabel("Software House/Developer: MN Tech Solutions");
  147. contentLabel.setBounds(40,220,500,20);
  148. contentPane.add(contentLabel);
  149.  
  150. contentLabel=new JLabel("Programmer/Software Developer: Mustafa Neguib");
  151. contentLabel.setBounds(40,240,500,20);
  152. contentPane.add(contentLabel);
  153.  
  154. contentLabel=new JLabel("Programming Language: JAVA");
  155. contentLabel.setBounds(40,260,500,20);
  156. contentPane.add(contentLabel);
  157.  
  158. contentLabel=new JLabel("Website: www.mntechsolutions.net");
  159. contentLabel.setBounds(40,280,500,20);
  160. contentPane.add(contentLabel);
  161.  
  162. contentLabel=new JLabel("Software Name: MN Tech Solutions GPA Calculator");
  163. contentLabel.setBounds(40,300,500,20);
  164. contentPane.add(contentLabel);
  165.  
  166. contentLabel=new JLabel("Comments:");
  167. contentLabel.setBounds(40,320,500,20);
  168. contentPane.add(contentLabel);
  169.  
  170. contentLabel=new JLabel("This software is a gpa calculator. The user gives the number of courses taken.");
  171. contentLabel.setBounds(40,340,500,20);
  172. contentPane.add(contentLabel);
  173.  
  174. contentLabel=new JLabel("The user then enters the course name, gpa earned and the credit hours of that course.");
  175. contentLabel.setBounds(40,360,500,20);
  176. contentPane.add(contentLabel);
  177.  
  178. /** Creating JButtons */
  179.  
  180. startSoftware=new JButton("Start Software");
  181. exitSoftware=new JButton("Exit Software");
  182.  
  183.  
  184. startSoftware.setBounds(40,420,120,30);
  185. startSoftware.addActionListener(this);
  186. contentPane.add(startSoftware);
  187.  
  188.  
  189. exitSoftware.setBounds(170,420,120,30);
  190. exitSoftware.addActionListener(this);
  191. contentPane.add(exitSoftware);
  192.  
  193.  
  194. /** Creating the footer and adding its content */
  195.  
  196. footer.setBounds(0,520,640,220);
  197. footer.add(new LoadImageApp("images/footer.gif"));
  198.  
  199. footerLabel=new JLabel("MN Tech Solutions GPA Calculator COPYRIGHT 2009 MN Tech Solutions");
  200. footerLabel.setBounds(80,560,500,20);
  201.  
  202. contentPane.add(footerLabel);
  203.  
  204. /** I am adding the JPanels to the outer JPanel.*/
  205.  
  206. back.add(header);
  207. back.add(menu);
  208. back.add(content);
  209. back.add(footer);
  210.  
  211.  
  212.  
  213. contentPane.add(back);
  214.  
  215.  
  216. //register 'Exit upon closing' as a default close operation
  217. setDefaultCloseOperation( EXIT_ON_CLOSE );
  218.  
  219. break;
  220.  
  221. case 2:
  222.  
  223.  
  224. id=2;
  225. contentPane= getContentPane();
  226.  
  227. setSize(640,680);
  228. setResizable(false);
  229.  
  230. setTitle("MN Tech Solutions GPA Calculator");
  231. setLocation(0,0);
  232.  
  233. /** Creating JPanel objects */
  234.  
  235. back=new JPanel();
  236. header = new JPanel();
  237. menu=new JPanel();
  238. content=new JPanel();
  239. footer=new JPanel();
  240.  
  241.  
  242.  
  243.  
  244.  
  245. /** Build the menu of the menu bar */
  246.  
  247. //** Build File Menu */
  248.  
  249. fileMenu= new JMenu("File");
  250. item= new JMenuItem("Main Page");
  251. item.addActionListener(this);
  252. fileMenu.add(item);
  253.  
  254. fileMenu.addSeparator();
  255. item= new JMenuItem("Exit Software");
  256. item.addActionListener(this);
  257. fileMenu.add(item);
  258.  
  259.  
  260.  
  261. menuBar= new JMenuBar();
  262. setJMenuBar(menuBar);
  263. menuBar.add(fileMenu);
  264.  
  265.  
  266.  
  267. back.setLayout(null); //i am using absolute positioning
  268.  
  269. /** Set the background color of each JPanel object to black. */
  270.  
  271. menu.setBackground(Color.BLACK);
  272. header.setBackground(Color.BLACK);
  273.  
  274. content.setBackground(Color.BLACK);
  275. footer.setBackground(Color.BLACK);
  276.  
  277. /** I am setting the bounds of the JPanel objects so that they can be displayed on the screen
  278.   and i am also inserting the data to be shown in the JPanel objects.
  279.   */
  280.  
  281. header.setBounds(0,0,640,80);
  282. header.add(new LoadImageApp("images/logo.gif"));
  283.  
  284. menu.setBounds(0,80,640,60);
  285. menu.add(new LoadImageApp("images/menu.gif"));
  286.  
  287. content.setBounds(0,140,640,400);
  288. content.add(new LoadImageApp("images/content.gif"));
  289.  
  290. contentLabel=new JLabel("Enter the course name, course gpa, and credit hours earned in that course: ");
  291. contentLabel.setBounds(40,180,600,20);
  292. contentPane.add(contentLabel);
  293.  
  294.  
  295. /** Creating JButtons */
  296.  
  297. submit=new JButton("Submit And Do Not Add A New Course");
  298. submit.addActionListener(this);
  299. submit.setBounds(40,320,300,30);
  300. contentPane.add(submit);
  301.  
  302. addMore=new JButton("Submit And Add A New Course");
  303. addMore.addActionListener(this);
  304. addMore.setBounds(40,360,300,30);
  305. contentPane.add(addMore);
  306.  
  307.  
  308.  
  309.  
  310. /** Creating the JTextField object */
  311.  
  312.  
  313. int i=0,height=220;
  314.  
  315.  
  316.  
  317. nameOfCourse=new JTextField();
  318. creditHoursOfCourse=new JTextField();
  319. gpaOfCourse=new JTextField();
  320.  
  321.  
  322.  
  323. name=new JLabel("Course Name: ");
  324. courseGpa=new JLabel("GPA: ");
  325. hours=new JLabel("Credit Hours: ");
  326.  
  327.  
  328.  
  329. name.setBounds(30,height,122,22);
  330. contentPane.add(name);
  331. nameOfCourse.setColumns(22);
  332. nameOfCourse.setBounds(120,height,122,22);
  333. contentPane.add(nameOfCourse);
  334.  
  335.  
  336. height=height+20;
  337.  
  338.  
  339. hours.setBounds(30,height,122,22);
  340. contentPane.add(hours);
  341. creditHoursOfCourse.setColumns(22);
  342. creditHoursOfCourse.setBounds(120,height,122,22);
  343. contentPane.add(creditHoursOfCourse);
  344.  
  345.  
  346. height=height+20;
  347.  
  348.  
  349. courseGpa.setBounds(30,height,122,22);
  350. contentPane.add(courseGpa);
  351. gpaOfCourse.setColumns(22);
  352. gpaOfCourse.setBounds(120,height,122,22);
  353. contentPane.add(gpaOfCourse);
  354.  
  355.  
  356.  
  357. /** Creating the footer and adding its content */
  358.  
  359. footer.setBounds(0,520,640,220);
  360. footer.add(new LoadImageApp("images/footer.gif"));
  361.  
  362. footerLabel=new JLabel("MN Tech Solutions GPA Calculator COPYRIGHT 2009 MN Tech Solutions");
  363. footerLabel.setBounds(80,560,500,20);
  364.  
  365. contentPane.add(footerLabel);
  366.  
  367. /** I am adding the JPanels to the outer JPanel.*/
  368.  
  369. back.add(header);
  370. back.add(menu);
  371. back.add(content);
  372. back.add(footer);
  373.  
  374.  
  375.  
  376. contentPane.add(back);
  377.  
  378.  
  379. //register 'Exit upon closing' as a default close operation
  380. setDefaultCloseOperation( EXIT_ON_CLOSE );
  381.  
  382.  
  383.  
  384. break;
  385.  
  386.  
  387. case 3:
  388.  
  389.  
  390. id=3;
  391. contentPane= getContentPane();
  392.  
  393. setSize(640,680);
  394. setResizable(false);
  395.  
  396. setTitle("MN Tech Solutions GPA Calculator");
  397. setLocation(0,0);
  398.  
  399. /** Creating JPanel objects */
  400.  
  401. back=new JPanel();
  402. header = new JPanel();
  403. menu=new JPanel();
  404. content=new JPanel();
  405. footer=new JPanel();
  406.  
  407.  
  408.  
  409.  
  410.  
  411. /** Build the menu of the menu bar */
  412.  
  413. //** Build File Menu */
  414.  
  415. fileMenu= new JMenu("File");
  416. item= new JMenuItem("Main Page");
  417. item.addActionListener(this);
  418. fileMenu.add(item);
  419.  
  420. fileMenu.addSeparator();
  421. item= new JMenuItem("Exit Software");
  422. item.addActionListener(this);
  423. fileMenu.add(item);
  424.  
  425.  
  426.  
  427. menuBar= new JMenuBar();
  428. setJMenuBar(menuBar);
  429. menuBar.add(fileMenu);
  430.  
  431.  
  432.  
  433. back.setLayout(null); //i am using absolute positioning
  434.  
  435. /** Set the background color of each JPanel object to black. */
  436.  
  437. menu.setBackground(Color.BLACK);
  438. header.setBackground(Color.BLACK);
  439.  
  440. content.setBackground(Color.BLACK);
  441. footer.setBackground(Color.BLACK);
  442.  
  443. /** I am setting the bounds of the JPanel objects so that they can be displayed on the screen
  444.   and i am also inserting the data to be shown in the JPanel objects.
  445.   */
  446.  
  447. header.setBounds(0,0,640,80);
  448. header.add(new LoadImageApp("images/logo.gif"));
  449.  
  450. menu.setBounds(0,80,640,60);
  451. menu.add(new LoadImageApp("images/menu.gif"));
  452.  
  453. content.setBounds(0,140,640,400);
  454. content.add(new LoadImageApp("images/content.gif"));
  455.  
  456. contentLabel=new JLabel("Following is the Cumulative Grade Point Average of your courses: ");
  457. contentLabel.setBounds(40,180,600,20);
  458. contentPane.add(contentLabel);
  459.  
  460.  
  461. /** Creating JButtons */
  462.  
  463. submit=new JButton("Start Again");
  464. submit.addActionListener(this);
  465. submit.setBounds(40,470,100,30);
  466. contentPane.add(submit);
  467.  
  468. JScrollPane contentScroll;
  469.  
  470. coursesListLabel=new JLabel(" ");
  471. coursesListLabel.setLayout(null);
  472. coursesListLabel.setBounds(40,170,100,200);
  473.  
  474. contentScroll=new JScrollPane(coursesListLabel);
  475. contentScroll.setBounds(new Rectangle(50,230,200,200));
  476. contentScroll.setSize(200,200);
  477.  
  478.  
  479. contentPane.add(contentScroll);
  480. // contentPane.add(coursesListLabel);
  481.  
  482.  
  483. /** Creating the footer and adding its content */
  484.  
  485. footer.setBounds(0,520,640,220);
  486. footer.add(new LoadImageApp("images/footer.gif"));
  487.  
  488. footerLabel=new JLabel("MN Tech Solutions GPA Calculator COPYRIGHT 2009 MN Tech Solutions");
  489. footerLabel.setBounds(80,560,500,20);
  490.  
  491. contentPane.add(footerLabel);
  492.  
  493. /** I am adding the JPanels to the outer JPanel.*/
  494.  
  495. back.add(header);
  496. back.add(menu);
  497. back.add(content);
  498. back.add(footer);
  499.  
  500.  
  501.  
  502. contentPane.add(back);
  503.  
  504.  
  505. //register 'Exit upon closing' as a default close operation
  506. setDefaultCloseOperation( EXIT_ON_CLOSE );
  507.  
  508.  
  509.  
  510.  
  511. break;
  512.  
  513. default: break;
  514.  
  515. }//end switch
  516.  
  517. }//end constructor
  518.  
  519.  
  520.  
  521. public void actionPerformed(ActionEvent event)
  522. {
  523.  
  524. /** actions of the menu of the menu bar */
  525.  
  526.  
  527. String menuName;
  528.  
  529. menuName = event.getActionCommand();
  530.  
  531. if (menuName.equals("Exit Software")) {
  532.  
  533.  
  534. System.exit(0);
  535.  
  536. }//end if
  537. else if(menuName.equals("Main Page"))
  538. {
  539. setVisible(false);//do not show the present window
  540. rootGuiNode.setVisible(true);//display the first page
  541.  
  542. }//end else if
  543.  
  544.  
  545.  
  546. JButton clickedButton;
  547. String buttonText;
  548.  
  549.  
  550. clickedButton= (JButton) event.getSource();
  551.  
  552. buttonText=clickedButton.getText();
  553.  
  554.  
  555.  
  556.  
  557. if( buttonText.equals("Start Software"))
  558. {//go to the main menu
  559.  
  560. nodeGpaList=new gpaList(); //create a new object to the gpaList which will create a new list
  561. setVisible(false);//do not show the present window
  562. rootGuiNode.next.setVisible(true);//display the second page
  563.  
  564.  
  565. }//end if
  566. else if(buttonText.equals("Exit Software"))
  567. {
  568.  
  569. System.exit(0);
  570.  
  571. }//end else if
  572. else if(buttonText.equals("Submit And Add A New Course"))
  573. {//add the course to the linked list and then again display the input dialog
  574.  
  575.  
  576. String nameCourse,courseGpa1,creditHourCourse;
  577.  
  578. nameCourse=new String();
  579. courseGpa1=new String();
  580. creditHourCourse=new String();
  581.  
  582. nameCourse=nameOfCourse.getText();//person
  583. courseGpa1=gpaOfCourse.getText();//place
  584. creditHourCourse=creditHoursOfCourse.getText();//date
  585.  
  586.  
  587. nodeGpaList.insertNode(nameCourse, Double.parseDouble(courseGpa1),Integer.parseInt(creditHourCourse));
  588.  
  589. //** the following lines reset the text fields */
  590. rootGuiNode.next.nameOfCourse.setText("");
  591. rootGuiNode.next.creditHoursOfCourse.setText("");
  592. rootGuiNode.next.gpaOfCourse.setText("");
  593.  
  594. setVisible(false);//do not show the present window
  595. rootGuiNode.next.setVisible(true);
  596.  
  597.  
  598. }//end else if
  599. else if(buttonText.equals("Submit And Do Not Add A New Course"))
  600. {//submit the course to the linked list and then display the cgpa
  601.  
  602.  
  603. String nameCourse,courseGpa1,creditHourCourse;
  604.  
  605. nameCourse=new String();
  606. courseGpa1=new String();
  607. creditHourCourse=new String();
  608.  
  609. nameCourse=nameOfCourse.getText();//person
  610. courseGpa1=gpaOfCourse.getText();//place
  611. creditHourCourse=creditHoursOfCourse.getText();//date
  612.  
  613.  
  614. nodeGpaList.insertNode(nameCourse, Double.parseDouble(courseGpa1),Integer.parseInt(creditHourCourse));
  615.  
  616. gpaNode ptr;
  617. String contentList=new String();
  618.  
  619. if(nodeGpaList.rootGpa==null)
  620. {//the linked list is empty
  621.  
  622. contentList="No courses exist. The list is empty.";
  623.  
  624. }//end if
  625. else
  626. {//the linked list is not empty
  627.  
  628. ptr=nodeGpaList.rootGpa;
  629.  
  630. nodeGpaList.calculateValue(ptr); //calculate the cgpa. the cgpa is stored in the data member of the gpaList class.
  631.  
  632.  
  633. contentList="<html>";
  634.  
  635. while(ptr!=null)
  636. {//get the contents of the linked list
  637.  
  638. contentList=contentList+"Course Name: "+ptr.courseName+"<br>"+"Course GPA: "+ptr.gpa+"<br>"+"Credit Hours: "+ptr.creditHour+"<br><br>";
  639.  
  640. ptr=ptr.next;
  641.  
  642. }//end while
  643.  
  644. contentList=contentList+"cgpa: "+nodeGpaList.cgpa+"<br>";
  645. contentList=contentList+"</html>";
  646.  
  647. }//end else
  648.  
  649.  
  650.  
  651. rootGuiNode.next.next.coursesListLabel.setText(contentList);
  652.  
  653. setVisible(false);//do not show the present window
  654. rootGuiNode.next.next.setVisible(true);//display the second page
  655.  
  656.  
  657.  
  658. }//end else if
  659. else if(buttonText.equals("Start Again"))
  660. {
  661.  
  662. //** the following lines reset the text fields */
  663. rootGuiNode.next.nameOfCourse.setText("");
  664. rootGuiNode.next.creditHoursOfCourse.setText("");
  665. rootGuiNode.next.gpaOfCourse.setText("");
  666.  
  667. nodeGpaList=null; //set the variable/pointer to null
  668. nodeGpaList=new gpaList(); //create a new object to the gpaList which will create a new list
  669. setVisible(false);//do not show the present window
  670. rootGuiNode.next.setVisible(true);//display the second page
  671.  
  672.  
  673. }//end else if
  674.  
  675.  
  676. }//end actionPerformed
  677.  
  678.  
  679. }//end class guiNode

gpaList.java
  1.  
  2. /*
  3.  * To change this template, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. /**
  8.  *
  9.  * @author Mustafa Neguib
  10.  */
  11.  
  12. import javax.swing.*;
  13.  
  14. public class gpaList {
  15.  
  16. public gpaNode rootGpa;
  17. public double cgpa;
  18. public int totalCreditHours;
  19.  
  20. public gpaList()
  21. {
  22.  
  23. /** i am not using the reserved key this because i am not using any local variables */
  24.  
  25. rootGpa=null;
  26. cgpa=0.0;
  27. totalCreditHours=0;
  28.  
  29. }//end construtor
  30.  
  31. public void insertNode(String courseName, double gpa, int creditHour)
  32. {
  33.  
  34. gpaNode temp=new gpaNode(courseName,gpa, creditHour);
  35. gpaNode ptr;
  36.  
  37. if(rootGpa==null)
  38. {
  39. rootGpa=temp;
  40.  
  41. }//end if
  42. else
  43. {
  44.  
  45. ptr=rootGpa;
  46.  
  47.  
  48. while(ptr.next!=null)
  49. {//execute the while statement as long as the next is not null
  50.  
  51. ptr=ptr.next;
  52.  
  53. }//end while
  54.  
  55.  
  56. ptr.next=temp; //point ptr to the new node
  57.  
  58.  
  59. }//end else
  60.  
  61.  
  62.  
  63. }//end function insertNode
  64.  
  65.  
  66.  
  67. public void calculateValue(gpaNode ptr)
  68. {
  69. gpaNode ptr1=ptr;
  70.  
  71. totalCreditHours=0;
  72.  
  73. while(ptr1!=null)
  74. {//get the contents of the linked list and calculate the total number of credit hours
  75.  
  76. totalCreditHours=totalCreditHours+ptr1.creditHour; //calculate the total number of credit hours
  77.  
  78. ptr1=ptr1.next;
  79.  
  80. }//end while
  81.  
  82.  
  83. while(ptr!=null)
  84. {//get the contents of the linked list and calculate the cgpa
  85.  
  86. cgpa=cgpa+((ptr.gpa)*(ptr.creditHour/totalCreditHours));
  87.  
  88. ptr=ptr.next;
  89.  
  90.  
  91.  
  92. }//end while
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99. }//end function calculateValue
  100.  
  101.  
  102.  
  103.  
  104. }//end class gpaList

gpaNode.java
  1.  
  2.  
  3. /*
  4.  * To change this template, choose Tools | Templates
  5.  * and open the template in the editor.
  6.  */
  7.  
  8. /**
  9.  *
  10.  * @author Mustafa Neguib
  11.  */
  12. public class gpaNode {
  13.  
  14. /** data members of class gpaNode */
  15.  
  16. public String courseName;
  17. public double gpa;
  18. public int creditHour;
  19. public gpaNode next;
  20.  
  21. public gpaNode(String courseName, double gpa, int creditHour)
  22. {
  23.  
  24. /** i am using the reserved this so that i can use the local variable of the same name so that no confusion takes place */
  25.  
  26. this.courseName=courseName;
  27. this.gpa=gpa;
  28. this.creditHour=creditHour;
  29. next=null;
  30.  
  31. }//end constructor
  32.  
  33. }//end class gpaNode

LoadImageApp.java
  1.  
  2.  
  3. /*
  4.  * Copyright (c) 1995 - 2008 Sun Microsystems, Inc. All rights reserved.
  5.  *
  6.  * Redistribution and use in source and binary forms, with or without
  7.  * modification, are permitted provided that the following conditions
  8.  * are met:
  9.  *
  10.  * - Redistributions of source code must retain the above copyright
  11.  * notice, this list of conditions and the following disclaimer.
  12.  *
  13.  * - Redistributions in binary form must reproduce the above copyright
  14.  * notice, this list of conditions and the following disclaimer in the
  15.  * documentation and/or other materials provided with the distribution.
  16.  *
  17.  * - Neither the name of Sun Microsystems nor the names of its
  18.  * contributors may be used to endorse or promote products derived
  19.  * from this software without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  22.  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  23.  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  24.  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  25.  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  26.  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27.  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28.  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29.  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30.  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31.  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32.  */
  33.  
  34.  
  35. import java.awt.*;
  36. import java.awt.event.*;
  37. import java.awt.image.*;
  38. import java.io.*;
  39. import javax.imageio.*;
  40. import javax.swing.*;
  41.  
  42.  
  43. /**
  44.  * This class demonstrates how to load an Image from an external file
  45.  */
  46. public class LoadImageApp extends Component {
  47.  
  48. BufferedImage img;
  49.  
  50. public void paint(Graphics g) {
  51. g.drawImage(img, 0, 0, null);
  52. }
  53.  
  54. public LoadImageApp(String image) {
  55. try {
  56. img = ImageIO.read(new File(image));
  57. } catch (IOException e) {
  58.  
  59. JOptionPane.showMessageDialog(null,"error");
  60. }
  61.  
  62. }
  63.  
  64. public Dimension getPreferredSize() {
  65. if (img == null) {
  66. return new Dimension(100,100);
  67. } else {
  68. return new Dimension(img.getWidth(null), img.getHeight(null));
  69. }
  70. }
  71. /*
  72.   public static void main(String[] args) {
  73.  
  74.   JFrame f = new JFrame("Load Image Sample");
  75.  
  76.   f.addWindowListener(new WindowAdapter(){
  77.   public void windowClosing(WindowEvent e) {
  78.   System.exit(0);
  79.   }
  80.   });
  81.  
  82.   f.add(new LoadImageApp());
  83.   f.pack();
  84.   f.setVisible(true);
  85.   }
  86.  
  87.   */
  88.  
  89. }
If one has not had the chance to do assembly prgramming then he has not had the chance to do programming at all.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 75
Reputation: mustafaneguib is an unknown quantity at this point 
Solved Threads: 3
mustafaneguib mustafaneguib is offline Offline
Junior Poster in Training

Re: hey all help please

 
0
  #2
Jul 29th, 2009
guys i have uploaded the whole project with all the images and everything.
download it from the following link,
please help guys i need to complete this program.

Downlad gpa calculator files

thanx in advance
If one has not had the chance to do assembly prgramming then he has not had the chance to do programming at all.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 75
Reputation: mustafaneguib is an unknown quantity at this point 
Solved Threads: 3
mustafaneguib mustafaneguib is offline Offline
Junior Poster in Training

Re: hey all help please

 
0
  #3
Jul 30th, 2009
i have solved the cgpa problem.

however i am yet to solve the other two errors, ie the jar file error, and the menu bar exceptions.

what i was doing was that i had declared the variable for the credit hour and total credit hours in the gpaNode class and gpaList class as int type.

when i was dividing the credit hour and the total credit hours the result was truncating to zero. because of that my cgpa was coming as 0.0 .

so guys please help me with the other two problems. i do not have enough experience with java/netbeans to solve those two problems.

also note that i am not doing any exception handling, but that will not prevent the exceptions from coming.
If one has not had the chance to do assembly prgramming then he has not had the chance to do programming at all.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 114
Reputation: KirkPatrick is an unknown quantity at this point 
Solved Threads: 3
KirkPatrick KirkPatrick is offline Offline
Junior Poster

Re: hey all help please

 
0
  #4
Jul 31st, 2009
Posting the exact exceptions might be helpful to those who are wanting to help you. (i didn't see them posted, but could have missed them. If they aren't in your post, add them and it should help in getting a response)
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 75
Reputation: mustafaneguib is an unknown quantity at this point 
Solved Threads: 3
mustafaneguib mustafaneguib is offline Offline
Junior Poster in Training

Re: hey all help please

 
0
  #5
Jul 31st, 2009
here is the exception. this exception is generated when i click the

file menu in the menu ar and the item main menu in it.

this code is in the file guiNode.java and the function is actionPerformed.
the error that is at this line,

  1. clickedButton= (JButton) event.getSource();


of the following part of code,

  1.  
  2. ...
  3. JButton clickedButton;
  4. String buttonText;
  5.  
  6. clickedButton= (JButton) event.getSource();
  7.  
  8. buttonText=clickedButton.getText();
  9. ...

following is the exception that i am getting,

  1.  
  2.  
  3. Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.JMenuItem
  4. at guiNode.actionPerformed(guiNode.java:575)
  5. at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
  6. at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
  7. at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
  8. at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
  9. at javax.swing.AbstractButton.doClick(AbstractButton.java:302)
  10. at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1051)
  11. at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1092)
  12. at java.awt.Component.processMouseEvent(Component.java:5517)
  13. at javax.swing.JComponent.processMouseEvent(JComponent.java:3135)
  14. at java.awt.Component.processEvent(Component.java:5282)
  15. at java.awt.Container.processEvent(Container.java:1966)
  16. at java.awt.Component.dispatchEventImpl(Component.java:3984)
  17. at java.awt.Container.dispatchEventImpl(Container.java:2024)
  18. at java.awt.Component.dispatchEvent(Component.java:3819)
  19. at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
  20. at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
  21. at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
  22. at java.awt.Container.dispatchEventImpl(Container.java:2010)
  23. at java.awt.Window.dispatchEventImpl(Window.java:1791)
  24. at java.awt.Component.dispatchEvent(Component.java:3819)
  25. at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
  26. at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
  27. at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
  28. at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
  29. at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
  30. at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Last edited by mustafaneguib; Jul 31st, 2009 at 6:54 pm.
If one has not had the chance to do assembly prgramming then he has not had the chance to do programming at all.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 686
Reputation: sillyboy is on a distinguished road 
Solved Threads: 61
sillyboy's Avatar
sillyboy sillyboy is offline Offline
Practically a Master Poster

Re: hey all help please

 
0
  #6
Jul 31st, 2009
it looks like it is complaining because the getSource is getting a javax.swing.JMenuItem, yet you are trying to use it as a JButton instead.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 75
Reputation: mustafaneguib is an unknown quantity at this point 
Solved Threads: 3
mustafaneguib mustafaneguib is offline Offline
Junior Poster in Training

Re: hey all help please

 
0
  #7
Aug 1st, 2009
thanx, the exceptions are gone. i am now just using the getActionCommand data now to use with the menu and the buttons.

also i managed to make the jar file execute.

thanx again guys, i am marking this thread as solved.
If one has not had the chance to do assembly prgramming then he has not had the chance to do programming at all.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC