/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Mustafa Neguib
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class guiNode extends JFrame implements ActionListener {
/** Declaring variables for the gui. */
public int id;
public Container contentPane;
public JPanel header;
public JPanel back;
public JPanel menu;
public JPanel content;
public JPanel footer;
public JPanel textField;
public JTextField nameOfCourse;
public JTextField creditHoursOfCourse;
public JTextField gpaOfCourse;
public JLabel name;
public JLabel courseGpa;
public JLabel hours;
public JLabel coursesListLabel;
public JButton startSoftware;
public JButton exitSoftware;
public JButton submit;
public JButton addMore;
public JLabel contentLabel;
public JLabel footerLabel;
public JMenu fileMenu;
public JMenuItem item;
public JMenuBar menuBar;
public guiNode next;
public static gpaList nodeGpaList;
public static guiNode rootGuiNode;
public guiNode(int page)
{
next=null;
switch(page)
{
case 1:
id=1;
contentPane= getContentPane();
setSize(640,680);
setResizable(false);
setTitle("MN Tech Solutions GPA Calculator");
setLocation(0,0);
/** Creating JPanel objects */
back=new JPanel();
header = new JPanel();
menu=new JPanel();
content=new JPanel();
footer=new JPanel();
//** Build the menu of the menu bar */
//** Build File Menu */
fileMenu= new JMenu("File");
item= new JMenuItem("Main Page");
item.addActionListener(this);
fileMenu.add(item);
fileMenu.addSeparator();
item= new JMenuItem("Exit Software");
item.addActionListener(this);
fileMenu.add(item);
menuBar= new JMenuBar();
setJMenuBar(menuBar);
menuBar.add(fileMenu);
back.setLayout(null); //i am using absolute positioning
/** Set the background color of each JPanel object to black. */
menu.setBackground(Color.BLACK);
header.setBackground(Color.BLACK);
content.setBackground(Color.BLACK);
footer.setBackground(Color.BLACK);
/** I am setting the bounds of the JPanel objects so that they can be displayed on the screen
and i am also inserting the data to be shown in the JPanel objects.
*/
header.setBounds(0,0,640,80);
header.add(new LoadImageApp("images/logo.gif"));
menu.setBounds(0,80,640,60);
menu.add(new LoadImageApp("images/menu.gif"));
content.setBounds(0,140,640,400);
content.add(new LoadImageApp("images/content.gif"));
contentLabel=new JLabel("MN Tech Solutions GPA Calculator");
contentLabel.setBounds(40,180,200,20);
contentPane.add(contentLabel);
contentLabel=new JLabel("Software House/Developer: MN Tech Solutions");
contentLabel.setBounds(40,220,500,20);
contentPane.add(contentLabel);
contentLabel=new JLabel("Programmer/Software Developer: Mustafa Neguib");
contentLabel.setBounds(40,240,500,20);
contentPane.add(contentLabel);
contentLabel=new JLabel("Programming Language: JAVA");
contentLabel.setBounds(40,260,500,20);
contentPane.add(contentLabel);
contentLabel=new JLabel("Website: www.mntechsolutions.net");
contentLabel.setBounds(40,280,500,20);
contentPane.add(contentLabel);
contentLabel=new JLabel("Software Name: MN Tech Solutions GPA Calculator");
contentLabel.setBounds(40,300,500,20);
contentPane.add(contentLabel);
contentLabel=new JLabel("Comments:");
contentLabel.setBounds(40,320,500,20);
contentPane.add(contentLabel);
contentLabel=new JLabel("This software is a gpa calculator. The user gives the number of courses taken.");
contentLabel.setBounds(40,340,500,20);
contentPane.add(contentLabel);
contentLabel=new JLabel("The user then enters the course name, gpa earned and the credit hours of that course.");
contentLabel.setBounds(40,360,500,20);
contentPane.add(contentLabel);
/** Creating JButtons */
startSoftware=new JButton("Start Software");
exitSoftware=new JButton("Exit Software");
startSoftware.setBounds(40,420,120,30);
startSoftware.addActionListener(this);
contentPane.add(startSoftware);
exitSoftware.setBounds(170,420,120,30);
exitSoftware.addActionListener(this);
contentPane.add(exitSoftware);
/** Creating the footer and adding its content */
footer.setBounds(0,520,640,220);
footer.add(new LoadImageApp("images/footer.gif"));
footerLabel=new JLabel("MN Tech Solutions GPA Calculator COPYRIGHT 2009 MN Tech Solutions");
footerLabel.setBounds(80,560,500,20);
contentPane.add(footerLabel);
/** I am adding the JPanels to the outer JPanel.*/
back.add(header);
back.add(menu);
back.add(content);
back.add(footer);
contentPane.add(back);
//register 'Exit upon closing' as a default close operation
setDefaultCloseOperation( EXIT_ON_CLOSE );
break;
case 2:
id=2;
contentPane= getContentPane();
setSize(640,680);
setResizable(false);
setTitle("MN Tech Solutions GPA Calculator");
setLocation(0,0);
/** Creating JPanel objects */
back=new JPanel();
header = new JPanel();
menu=new JPanel();
content=new JPanel();
footer=new JPanel();
/** Build the menu of the menu bar */
//** Build File Menu */
fileMenu= new JMenu("File");
item= new JMenuItem("Main Page");
item.addActionListener(this);
fileMenu.add(item);
fileMenu.addSeparator();
item= new JMenuItem("Exit Software");
item.addActionListener(this);
fileMenu.add(item);
menuBar= new JMenuBar();
setJMenuBar(menuBar);
menuBar.add(fileMenu);
back.setLayout(null); //i am using absolute positioning
/** Set the background color of each JPanel object to black. */
menu.setBackground(Color.BLACK);
header.setBackground(Color.BLACK);
content.setBackground(Color.BLACK);
footer.setBackground(Color.BLACK);
/** I am setting the bounds of the JPanel objects so that they can be displayed on the screen
and i am also inserting the data to be shown in the JPanel objects.
*/
header.setBounds(0,0,640,80);
header.add(new LoadImageApp("images/logo.gif"));
menu.setBounds(0,80,640,60);
menu.add(new LoadImageApp("images/menu.gif"));
content.setBounds(0,140,640,400);
content.add(new LoadImageApp("images/content.gif"));
contentLabel=new JLabel("Enter the course name, course gpa, and credit hours earned in that course: ");
contentLabel.setBounds(40,180,600,20);
contentPane.add(contentLabel);
/** Creating JButtons */
submit=new JButton("Submit And Do Not Add A New Course");
submit.addActionListener(this);
submit.setBounds(40,320,300,30);
contentPane.add(submit);
addMore=new JButton("Submit And Add A New Course");
addMore.addActionListener(this);
addMore.setBounds(40,360,300,30);
contentPane.add(addMore);
/** Creating the JTextField object */
int i=0,height=220;
nameOfCourse=new JTextField();
creditHoursOfCourse=new JTextField();
gpaOfCourse=new JTextField();
name=new JLabel("Course Name: ");
courseGpa=new JLabel("GPA: ");
hours=new JLabel("Credit Hours: ");
name.setBounds(30,height,122,22);
contentPane.add(name);
nameOfCourse.setColumns(22);
nameOfCourse.setBounds(120,height,122,22);
contentPane.add(nameOfCourse);
height=height+20;
hours.setBounds(30,height,122,22);
contentPane.add(hours);
creditHoursOfCourse.setColumns(22);
creditHoursOfCourse.setBounds(120,height,122,22);
contentPane.add(creditHoursOfCourse);
height=height+20;
courseGpa.setBounds(30,height,122,22);
contentPane.add(courseGpa);
gpaOfCourse.setColumns(22);
gpaOfCourse.setBounds(120,height,122,22);
contentPane.add(gpaOfCourse);
/** Creating the footer and adding its content */
footer.setBounds(0,520,640,220);
footer.add(new LoadImageApp("images/footer.gif"));
footerLabel=new JLabel("MN Tech Solutions GPA Calculator COPYRIGHT 2009 MN Tech Solutions");
footerLabel.setBounds(80,560,500,20);
contentPane.add(footerLabel);
/** I am adding the JPanels to the outer JPanel.*/
back.add(header);
back.add(menu);
back.add(content);
back.add(footer);
contentPane.add(back);
//register 'Exit upon closing' as a default close operation
setDefaultCloseOperation( EXIT_ON_CLOSE );
break;
case 3:
id=3;
contentPane= getContentPane();
setSize(640,680);
setResizable(false);
setTitle("MN Tech Solutions GPA Calculator");
setLocation(0,0);
/** Creating JPanel objects */
back=new JPanel();
header = new JPanel();
menu=new JPanel();
content=new JPanel();
footer=new JPanel();
/** Build the menu of the menu bar */
//** Build File Menu */
fileMenu= new JMenu("File");
item= new JMenuItem("Main Page");
item.addActionListener(this);
fileMenu.add(item);
fileMenu.addSeparator();
item= new JMenuItem("Exit Software");
item.addActionListener(this);
fileMenu.add(item);
menuBar= new JMenuBar();
setJMenuBar(menuBar);
menuBar.add(fileMenu);
back.setLayout(null); //i am using absolute positioning
/** Set the background color of each JPanel object to black. */
menu.setBackground(Color.BLACK);
header.setBackground(Color.BLACK);
content.setBackground(Color.BLACK);
footer.setBackground(Color.BLACK);
/** I am setting the bounds of the JPanel objects so that they can be displayed on the screen
and i am also inserting the data to be shown in the JPanel objects.
*/
header.setBounds(0,0,640,80);
header.add(new LoadImageApp("images/logo.gif"));
menu.setBounds(0,80,640,60);
menu.add(new LoadImageApp("images/menu.gif"));
content.setBounds(0,140,640,400);
content.add(new LoadImageApp("images/content.gif"));
contentLabel=new JLabel("Following is the Cumulative Grade Point Average of your courses: ");
contentLabel.setBounds(40,180,600,20);
contentPane.add(contentLabel);
/** Creating JButtons */
submit=new JButton("Start Again");
submit.addActionListener(this);
submit.setBounds(40,470,100,30);
contentPane.add(submit);
JScrollPane contentScroll;
coursesListLabel=new JLabel(" ");
coursesListLabel.setLayout(null);
coursesListLabel.setBounds(40,170,100,200);
contentScroll=new JScrollPane(coursesListLabel);
contentScroll.setBounds(new Rectangle(50,230,200,200));
contentScroll.setSize(200,200);
contentPane.add(contentScroll);
// contentPane.add(coursesListLabel);
/** Creating the footer and adding its content */
footer.setBounds(0,520,640,220);
footer.add(new LoadImageApp("images/footer.gif"));
footerLabel=new JLabel("MN Tech Solutions GPA Calculator COPYRIGHT 2009 MN Tech Solutions");
footerLabel.setBounds(80,560,500,20);
contentPane.add(footerLabel);
/** I am adding the JPanels to the outer JPanel.*/
back.add(header);
back.add(menu);
back.add(content);
back.add(footer);
contentPane.add(back);
//register 'Exit upon closing' as a default close operation
setDefaultCloseOperation( EXIT_ON_CLOSE );
break;
default: break;
}//end switch
}//end constructor
public void actionPerformed(ActionEvent event)
{
/** actions of the menu of the menu bar */
String menuName;
menuName = event.getActionCommand();
if (menuName.equals("Exit Software")) {
System.exit(0);
}//end if
else if(menuName.equals("Main Page"))
{
setVisible(false);//do not show the present window
rootGuiNode.setVisible(true);//display the first page
}//end else if
JButton clickedButton;
String buttonText;
clickedButton= (JButton) event.getSource();
buttonText=clickedButton.getText();
if( buttonText.equals("Start Software"))
{//go to the main menu
nodeGpaList=new gpaList(); //create a new object to the gpaList which will create a new list
setVisible(false);//do not show the present window
rootGuiNode.next.setVisible(true);//display the second page
}//end if
else if(buttonText.equals("Exit Software"))
{
System.exit(0);
}//end else if
else if(buttonText.equals("Submit And Add A New Course"))
{//add the course to the linked list and then again display the input dialog
String nameCourse,courseGpa1,creditHourCourse;
nameCourse=new String();
courseGpa1=new String();
creditHourCourse=new String();
nameCourse=nameOfCourse.getText();//person
courseGpa1=gpaOfCourse.getText();//place
creditHourCourse=creditHoursOfCourse.getText();//date
nodeGpaList.insertNode(nameCourse, Double.parseDouble(courseGpa1),Integer.parseInt(creditHourCourse));
//** the following lines reset the text fields */
rootGuiNode.next.nameOfCourse.setText("");
rootGuiNode.next.creditHoursOfCourse.setText("");
rootGuiNode.next.gpaOfCourse.setText("");
setVisible(false);//do not show the present window
rootGuiNode.next.setVisible(true);
}//end else if
else if(buttonText.equals("Submit And Do Not Add A New Course"))
{//submit the course to the linked list and then display the cgpa
String nameCourse,courseGpa1,creditHourCourse;
nameCourse=new String();
courseGpa1=new String();
creditHourCourse=new String();
nameCourse=nameOfCourse.getText();//person
courseGpa1=gpaOfCourse.getText();//place
creditHourCourse=creditHoursOfCourse.getText();//date
nodeGpaList.insertNode(nameCourse, Double.parseDouble(courseGpa1),Integer.parseInt(creditHourCourse));
gpaNode ptr;
String contentList=new String();
if(nodeGpaList.rootGpa==null)
{//the linked list is empty
contentList="No courses exist. The list is empty.";
}//end if
else
{//the linked list is not empty
ptr=nodeGpaList.rootGpa;
nodeGpaList.calculateValue(ptr); //calculate the cgpa. the cgpa is stored in the data member of the gpaList class.
contentList="<html>";
while(ptr!=null)
{//get the contents of the linked list
contentList=contentList+"Course Name: "+ptr.courseName+"<br>"+"Course GPA: "+ptr.gpa+"<br>"+"Credit Hours: "+ptr.creditHour+"<br><br>";
ptr=ptr.next;
}//end while
contentList=contentList+"cgpa: "+nodeGpaList.cgpa+"<br>";
contentList=contentList+"</html>";
}//end else
rootGuiNode.next.next.coursesListLabel.setText(contentList);
setVisible(false);//do not show the present window
rootGuiNode.next.next.setVisible(true);//display the second page
}//end else if
else if(buttonText.equals("Start Again"))
{
//** the following lines reset the text fields */
rootGuiNode.next.nameOfCourse.setText("");
rootGuiNode.next.creditHoursOfCourse.setText("");
rootGuiNode.next.gpaOfCourse.setText("");
nodeGpaList=null; //set the variable/pointer to null
nodeGpaList=new gpaList(); //create a new object to the gpaList which will create a new list
setVisible(false);//do not show the present window
rootGuiNode.next.setVisible(true);//display the second page
}//end else if
}//end actionPerformed
}//end class guiNode