masokis

JAVA- Student Management

Mar 23rd, 2011
483
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 32.60 KB | None | 0 0
  1. /*
  2.  *  Name    Ryan Nilo Ybañez
  3.  *  Course  BSCS - IV
  4.  *  Subject Data Structure java implemented
  5.  *
  6.  **/
  7.  
  8. import java.awt.*;
  9. import java.awt.event.*;
  10.  
  11. import javax.swing.*;
  12.  
  13. public class Add extends AbstractAction
  14. {
  15.     private JDialog     dialog;
  16.     private JFrame      frame;
  17.    
  18.     public Add(String commandAction,JFrame frame)
  19.     {
  20.         super(commandAction);
  21.         this.frame = frame;
  22.     }
  23.    
  24.     public void actionPerformed(ActionEvent event)
  25.     {
  26.         addNewStudent();
  27.     }
  28.    
  29.     public void addNewStudent()
  30.     {
  31.         dialog = new JDialog(frame,"Add Record",true);
  32.        
  33.         dialog.setContentPane(new NewStudent(dialog).getPanel());
  34.         dialog.pack();
  35.         dialog.setLocationRelativeTo(frame);
  36.         dialog.setVisible(true);
  37.     }
  38. }
  39. ----------------------------------------------------------------------------
  40. /*
  41.  *  Name    Ryan Nilo Ybañez
  42.  *  Course  BSCS - IV
  43.  *  Subject Data Structure java implemented
  44.  *
  45.  **/
  46.  
  47. import java.awt.*;
  48. import java.awt.event.*;
  49.  
  50. import javax.swing.*;
  51.  
  52. public class Delete extends AbstractAction
  53. {
  54.     private StudentList studentList = new StudentList();
  55.     private JFrame      frame = null;
  56.    
  57.     public Delete(String commandAction,JFrame frame)
  58.     {
  59.         super(commandAction);
  60.         this.frame = frame;
  61.     }
  62.    
  63.     public void actionPerformed(ActionEvent event)
  64.     {
  65.         if(studentList.getList().size() != 0)
  66.         {
  67.             int n = JOptionPane.showConfirmDialog(
  68.                                 frame,
  69.                                 "Are you sure? you want to  delete this record 'student'",
  70.                                 "Confirm delete",
  71.                                 JOptionPane.YES_NO_OPTION);
  72.        
  73.             if(n == JOptionPane.YES_OPTION)
  74.             {
  75.                 deleteStudentRecord();
  76.             }
  77.         }
  78.     }
  79.  
  80.     public void deleteStudentRecord()
  81.     {      
  82.         studentList.getList().remove(studentList.getRecord());
  83.        
  84.         if(studentList.getList().size() != 0)
  85.         {
  86.             Student student = (Student)studentList.getList().getLast();
  87.    
  88.             studentList.setRecord(studentList.getList().size() - 1);
  89.            
  90.             new StudentRecordGUI(studentList.getRecord() + 1);
  91.             new StudentRecordGUI(student.getFirstName(),
  92.                                  student.getLastName(),
  93.                                  student.getIdNum(),
  94.                                  student.getCourse(),
  95.                                  student.getYearLevel());
  96.         }
  97.         else
  98.         {
  99.             new StudentRecordGUI(false);
  100.             new StudentRecordGUI(0);
  101.             new StudentRecordGUI("","",0,"","");
  102.         }
  103.    
  104.     }
  105. }
  106. ---------------------------------------------------------------------------
  107. /*
  108.  *  Name    Ryan Nilo Ybañez
  109.  *  Course  BSCS - IV
  110.  *  Subject Data Structure java implemented
  111.  *
  112.  **/
  113.  
  114. import java.awt.event.*;
  115.  
  116. import javax.swing.*;
  117.  
  118. public class Edit extends AbstractAction
  119. {
  120.     StudentList studentList = new StudentList();
  121.     Student     student     = null;
  122.    
  123.     private JFrame  frame   = null;
  124.     private JDialog dialog  = null;
  125.    
  126.     public Edit(String commandAction,JFrame frame)
  127.     {
  128.         super(commandAction);
  129.         this.frame = frame;
  130.     }
  131.    
  132.     public void actionPerformed(ActionEvent event)
  133.     {
  134.         try
  135.         {
  136.             if(studentList.getList().getFirst() != null)
  137.             {
  138.                 editStudentProfile();
  139.             }
  140.             else
  141.             {
  142.                 JOptionPane.showMessageDialog(
  143.                         frame,
  144.                         "Empty student record.",
  145.                         "Edit",
  146.                         JOptionPane.ERROR_MESSAGE);
  147.             }
  148.         }
  149.         catch(Exception e)
  150.         {
  151.             JOptionPane.showMessageDialog(
  152.                         frame,
  153.                         "Empty student record.",
  154.                         "Edit",
  155.                         JOptionPane.ERROR_MESSAGE);
  156.         }
  157.     }
  158.    
  159.     public void editStudentProfile()
  160.     {
  161.         int i = studentList.getRecord();
  162.         student = (Student)studentList.getList().get(i);
  163.  
  164.         studentList.setRecord(i);
  165.    
  166.         dialog = new JDialog(frame,"Edit Student Profile",true);
  167.         dialog.setContentPane(new EditProfile(student,dialog,i).getPanel());
  168.         dialog.pack();
  169.         dialog.setLocationRelativeTo(frame);
  170.         dialog.setVisible(true);
  171.     }
  172. }
  173.  
  174.  
  175. -------------------------------------------------------------------------------
  176.  
  177.  
  178.  
  179.  
  180. /*
  181.  *  Name    Ryan Nilo Ybañez
  182.  *  Course  BSCS - IV
  183.  *  Subject Data Structure java implemented
  184.  *
  185.  **/
  186.  
  187. import java.awt.*;
  188. import java.awt.event.*;
  189.  
  190. import javax.swing.*;
  191.  
  192. public class EditProfile extends JPanel
  193. {  
  194.     private StudentList studentList = new StudentList();
  195.     private Student     student;
  196.    
  197.     private JPanel      panel,mainPanel,txtLblPanel,btnPanel,iconPanel;
  198.    
  199.     private JLabel      label,lblIcon;
  200.     private JTextField  firstName, lastName, idNum;
  201.     private JButton     btnSave,btnExt;
  202.    
  203.     private JComboBox   course,yearLevel;
  204.     private JDialog     dialog;
  205.    
  206.     private String[]    listOfCourse = {
  207.                                          "SELECT COURSE","",
  208.                                          "ACCOUNTANCY",
  209.                                          "BANKING IN FINANACE",
  210.                                          "COMPUTER SCIENCE",
  211.                                          "CRIMINOLOGY",
  212.                                          "COM - E",
  213.                                          "ELECTRONIC COMM - E",
  214.                                          "INFORMATION TECHNOLOGY",
  215.                                          "MANAGEMENT",
  216.                                          "MARINE ENGINEERING",
  217.                                          "NURCING",
  218.                                          "NAUTICAL"
  219.                                         };
  220.                                        
  221.     private String[]    levelYear    = {
  222.                                          "1TH YEAR",
  223.                                          "2TH YEAR",
  224.                                          "3TH YEAR",
  225.                                          "4TH YEAR",
  226.                                          "5TH YEAR"
  227.                                         }; 
  228.     private int index;
  229.    
  230.     public EditProfile(Student student,JDialog dialog,int index)
  231.     {
  232.         this();
  233.         this.dialog  = dialog;
  234.         this.index   = index;
  235.        
  236.         firstName.setText(student.getFirstName());
  237.         lastName.setText(student.getLastName());
  238.         idNum.setText(String.valueOf(student.getIdNum()));
  239.         course.setSelectedItem(student.getCourse());
  240.         yearLevel.setSelectedItem(student.getYearLevel());
  241.     }
  242.    
  243.     public EditProfile()
  244.     {
  245.         panel = new JPanel();
  246.        
  247.         panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
  248.         panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
  249.  
  250.         txtLblPanel = new JPanel();
  251.         iconPanel   = new JPanel();
  252.         btnPanel    = new JPanel();
  253.        
  254.         addLayout();
  255.                        
  256.         mainPanel = new JPanel();
  257.         mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));
  258.         mainPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
  259.        
  260.         mainPanel.add(txtLblPanel);
  261.         mainPanel.add(Box.createRigidArea(new Dimension(5,5)));
  262.         mainPanel.add(btnPanel);
  263.        
  264.         panel.add(iconPanel);
  265.         panel.add(mainPanel);      
  266.     }
  267.    
  268.     public JPanel getPanel()
  269.     {
  270.         return panel;
  271.     }
  272.        
  273.     public void addLayout()
  274.     {
  275.         JPanel lblPanel = new JPanel();
  276.         lblPanel.setLayout(new GridLayout(5,1,5,1));
  277.             lblPanel.add(label = new JLabel("Student Id :",JLabel.RIGHT));
  278.             lblPanel.add(label = new JLabel("First Name :",JLabel.RIGHT));
  279.             lblPanel.add(label = new JLabel("Last Name :",JLabel.RIGHT));
  280.             lblPanel.add(label = new JLabel("Course :",JLabel.RIGHT));
  281.             lblPanel.add(label = new JLabel("Year Level :",JLabel.RIGHT));
  282.        
  283.         JPanel txtPanel = new JPanel();
  284.         txtPanel.setLayout(new GridLayout(5,1));   
  285.             txtPanel.add(idNum      = new JTextField(15));
  286.             txtPanel.add(firstName  = new JTextField(15));
  287.             txtPanel.add(lastName   = new JTextField(15));
  288.             txtPanel.add(course     = new JComboBox(listOfCourse));
  289.             txtPanel.add(yearLevel  = new JComboBox(levelYear));
  290.            
  291.             idNum.setHorizontalAlignment(JTextField.CENTER);
  292.             firstName.setHorizontalAlignment(JTextField.CENTER);
  293.             lastName.setHorizontalAlignment(JTextField.CENTER);
  294.            
  295.         btnPanel.setLayout(new FlowLayout(FlowLayout.CENTER,5,0));
  296.             btnPanel.add(btnSave = new JButton("Save"));
  297.             btnPanel.add(btnExt  = new JButton("Close"));
  298.            
  299.         txtLblPanel.setLayout(new BoxLayout(txtLblPanel, BoxLayout.LINE_AXIS));        
  300.             txtLblPanel.add(lblPanel);
  301.             txtLblPanel.add(Box.createRigidArea(new Dimension(5,5)));
  302.             txtLblPanel.add(txtPanel);
  303.            
  304.         iconPanel.setLayout(new FlowLayout(FlowLayout.RIGHT,1,1));
  305.             iconPanel.add(lblIcon = new JLabel(new ImageIcon("image/wi0062-32.gif"),JLabel.LEFT));                 
  306.             iconPanel.setBorder(BorderFactory.createEtchedBorder());
  307.  
  308.         btnSave.addActionListener(new ActionListener(){
  309.             public void actionPerformed(ActionEvent e)
  310.             {
  311.                 int n = JOptionPane.showConfirmDialog(
  312.                                     dialog,
  313.                                     "Continue save?",
  314.                                     "Confirm save",
  315.                                     JOptionPane.YES_NO_OPTION);
  316.                 if(n == JOptionPane.YES_OPTION)
  317.                 {
  318.                     save();
  319.                     message();
  320.                     dispose();
  321.                 }
  322.             }
  323.         });
  324.        
  325.         btnExt.addActionListener(new ActionListener(){
  326.             public void actionPerformed(ActionEvent e)
  327.             {
  328.                 dispose();
  329.             }
  330.         });
  331.     }
  332.    
  333.     public void save()
  334.     {
  335.         student = new Student(firstName.getText().trim(),
  336.                               lastName.getText().trim(),
  337.                               Integer.valueOf(idNum.getText().trim()),
  338.                               String.valueOf(course.getSelectedItem()),
  339.                               String.valueOf(yearLevel.getSelectedItem()));
  340.        
  341.         studentList.getList().set(index,student);
  342.        
  343.         Student update = (Student)studentList.getList().get(index);
  344.         new StudentRecordGUI(update.getFirstName(),
  345.                              update.getLastName(),
  346.                              update.getIdNum(),
  347.                              update.getCourse(),
  348.                              update.getYearLevel());
  349.     }
  350.    
  351.     public void message()
  352.     {
  353.         JOptionPane.showMessageDialog(
  354.                     dialog,
  355.                     "Successfull.",
  356.                     "Message",
  357.                     JOptionPane.INFORMATION_MESSAGE);
  358.     }
  359.    
  360.     public void dispose()
  361.     {
  362.         dialog.setVisible(false);
  363.         dialog.dispose();
  364.     }
  365. }
  366.  
  367.  
  368. ----------------------------------------------------------------
  369.  
  370.  
  371.  
  372. /*
  373.  *  Name    Ryan Nilo Ybañez
  374.  *  Course  BSCS - IV
  375.  *  Subject Data Structure java implemented
  376.  *
  377.  **/
  378.  
  379. import java.util.*;
  380. import java.awt.event.*;
  381.  
  382. import javax.swing.*;
  383.  
  384. public class First extends AbstractAction
  385. {  
  386.     private StudentList studentList = new StudentList();
  387.    
  388.     public First(String command, ImageIcon icon)
  389.     {
  390.         super(command,icon);
  391.     }
  392.    
  393.     public void actionPerformed(ActionEvent event)
  394.     {
  395.         try
  396.         {
  397.             Student student = (Student)studentList.getList().getFirst();
  398.        
  399.             studentList.setRecord(0);
  400.                    
  401.             new StudentRecordGUI(1);           
  402.             new StudentRecordGUI(student.getFirstName(),
  403.                                  student.getLastName(),
  404.                                  student.getIdNum(),
  405.                                  student.getCourse(),
  406.                                  student.getYearLevel());
  407.         }
  408.         catch(Exception e)
  409.         {}
  410.    
  411.     }
  412. }
  413.  
  414.  
  415. --------------------------------------------------------------------------------
  416.  
  417. /*
  418.  *  Name    Ryan Nilo Ybañez
  419.  *  Course  BSCS - IV
  420.  *  Subject Data Structure java implemented
  421.  *
  422.  **/
  423.  
  424. import java.awt.event.*;
  425.  
  426. import javax.swing.*;
  427.  
  428. public class Last extends AbstractAction
  429. {
  430.     StudentList studentList = new StudentList();
  431.    
  432.     public Last(String command,ImageIcon icon)
  433.     {
  434.         super(command,icon);
  435.     }
  436.    
  437.     public void actionPerformed(ActionEvent event)
  438.     {
  439.         try
  440.         {
  441.             Student student = (Student)studentList.getList().getLast();
  442.        
  443.             studentList.setRecord(studentList.getList().size() - 1);
  444.        
  445.             new StudentRecordGUI(studentList.getSize());
  446.             new StudentRecordGUI(student.getFirstName(),
  447.                                  student.getLastName(),
  448.                                  student.getIdNum(),
  449.                                  student.getCourse(),
  450.                                  student.getYearLevel());
  451.         }
  452.         catch(Exception e)
  453.         {}
  454.     }
  455. }
  456.  
  457.  
  458. -------------------------------------------------------------
  459.  
  460.  
  461.  
  462.  
  463. public class MyException extends Exception
  464. {
  465.     public MyException(String message)
  466.     {
  467.         super(message);
  468.     }
  469. }
  470.  
  471.  
  472. -----------------------------------------------------------------------------
  473.  
  474.  
  475.  
  476. /*
  477.  *  Name:       Ryan Nilo Ybanez
  478.  *  Course:     BSCS - IV
  479.  *  
  480.  **/
  481.  
  482. public class MyLinkedList
  483. {
  484.     private Node head,tail;
  485.     private int size;
  486.        
  487.     public void add(Object data)
  488.     {
  489.         addEnd(data);
  490.         size++;
  491.     }
  492.    
  493.     public void addFront(Object data)
  494.     {
  495.         Node newNode = new Node(data,null);
  496.         newNode.setNext(head);
  497.         head = newNode;
  498.     }
  499.        
  500.     public void addEnd(Object data)
  501.     {
  502.         if(isEmpty()){
  503.             head = new Node(data,null);
  504.             tail = head;
  505.         }
  506.         else{
  507.             Node p = tail;
  508.             tail = new Node(data,p.getNext());
  509.             p.setNext(tail);
  510.         }
  511.     }
  512.    
  513.     public boolean remove(Object data)
  514.     {
  515.         boolean remove = false;
  516.         Node p = head;
  517.         Node prev = head;
  518.        
  519.         if(p.getData().equals(data)){
  520.             head = p.getNext();
  521.             p.setNext(null);
  522.             remove = true;
  523.         }
  524.         else{
  525.             while(p.getNext() != null){
  526.                 prev = p;
  527.                 p = p.getNext();
  528.            
  529.                 if(p.getData().equals(data)){
  530.                     prev.setNext(p.getNext());
  531.                     p.setNext(null);
  532.                     remove = true;
  533.                 }
  534.             }
  535.         }
  536.         System.gc();
  537.         return remove;
  538.     }
  539.    
  540.     public Object getFirst()
  541.     {
  542.         return head.getData();
  543.     }
  544.    
  545.     public Object getLast()
  546.     {
  547.         return tail.getData();
  548.     }
  549.    
  550.     public int size()
  551.     {
  552.         return size;
  553.     }
  554.    
  555.     public boolean isEmpty()
  556.     {
  557.         return head == null;
  558.     }
  559.    
  560.     public String toString()
  561.     {
  562.         StringBuffer sb = new StringBuffer();
  563.        
  564.         Node p = head;
  565.        
  566.         while(p != null)
  567.         {
  568.             sb.append(p.getData());
  569.             p = p.getNext();
  570.             if(p != null)
  571.             {
  572.                 sb.append(",");
  573.             }
  574.         }
  575.         return sb.toString();
  576.     }
  577.    
  578.     public static void main(String[] args)
  579.     {
  580.         MyLinkedList linklist = new MyLinkedList();
  581.         StringBuffer sb = new StringBuffer();
  582.        
  583.         linklist.add("adsf");
  584.         linklist.add("02938");
  585.         linklist.add("asdfasdf");
  586.         System.out.println(linklist);
  587.     }
  588. }
  589.  
  590.  
  591. -----------------------------------------------------
  592.  
  593.  
  594. /*
  595.  *  Name    Ryan Nilo Ybañez
  596.  *  Course  BSCS - IV
  597.  *  Subject Data Structure java implemented
  598.  *
  599.  **/
  600.  
  601. import java.util.*;
  602. import java.awt.*;
  603. import java.awt.event.*;
  604.  
  605. import javax.swing.*;
  606.  
  607. public class NewStudent extends JFrame
  608. {  
  609.     static private LinkedList list = new LinkedList();
  610.     static private Student newStudent;
  611.            
  612.     private JPanel      panel,mainPanel,txtLblPanel,btnPanel,iconPanel;
  613.    
  614.     private JLabel      label,lblIcon;
  615.     private JTextField  firstName, lastName, idNum;
  616.     private JButton     btnAdd,btnExt;
  617.    
  618.     private JComboBox   course,yearLevel;
  619.     private JDialog     dialog;
  620.    
  621.     private String[]    listOfCourse = {
  622.                                          "[ SELECT COURSE ]",
  623.                                          "ACCOUNTANCY",
  624.                                          "BANKING IN FINANACE",
  625.                                          "COMPUTER SCIENCE",
  626.                                          "CRIMINOLOGY",
  627.                                          "COM - E",
  628.                                          "ELECTRONIC COMM - E",
  629.                                          "INFORMATION TECHNOLOGY",
  630.                                          "MANAGEMENT",
  631.                                          "MARINE ENGINEERING",
  632.                                          "NURCING",
  633.                                          "NAUTICAL"
  634.                                         };
  635.                                        
  636.     private String[]    levelYear    = {
  637.                                          "[ SELECT LEVEL ]",
  638.                                          "1TH YEAR",
  639.                                          "2TH YEAR",
  640.                                          "3TH YEAR",
  641.                                          "4TH YEAR",
  642.                                          "5TH YEAR"
  643.                                         };
  644.    
  645.     public NewStudent(JDialog dialog)
  646.     {
  647.         this();
  648.         this.dialog = dialog;
  649.     }
  650.    
  651.     public NewStudent()
  652.     {
  653.         panel = new JPanel();
  654.        
  655.         panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
  656.         panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
  657.  
  658.         txtLblPanel = new JPanel();
  659.         iconPanel   = new JPanel();
  660.         btnPanel    = new JPanel();
  661.        
  662.         addLayout();
  663.                        
  664.         mainPanel = new JPanel();
  665.         mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));
  666.         mainPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
  667.        
  668.         mainPanel.add(txtLblPanel);
  669.         mainPanel.add(Box.createRigidArea(new Dimension(5,5)));
  670.         mainPanel.add(btnPanel);
  671.        
  672.         panel.add(iconPanel);
  673.         panel.add(mainPanel);      
  674.     }
  675.        
  676.     public void addLayout()
  677.     {
  678.         JPanel lblPanel = new JPanel();
  679.         lblPanel.setLayout(new GridLayout(5,1,5,1));
  680.             lblPanel.add(label = new JLabel("Student Id :",JLabel.RIGHT));
  681.             lblPanel.add(label = new JLabel("First Name :",JLabel.RIGHT));
  682.             lblPanel.add(label = new JLabel("Last Name :",JLabel.RIGHT));
  683.             lblPanel.add(label = new JLabel("Course :",JLabel.RIGHT));
  684.             lblPanel.add(label = new JLabel("Year Level :",JLabel.RIGHT));
  685.        
  686.         JPanel txtPanel = new JPanel();
  687.         txtPanel.setLayout(new GridLayout(5,1));   
  688.             txtPanel.add(idNum      = new JTextField(15));
  689.             txtPanel.add(firstName  = new JTextField(15));
  690.             txtPanel.add(lastName   = new JTextField(15));
  691.             txtPanel.add(course     = new JComboBox(listOfCourse));
  692.             txtPanel.add(yearLevel  = new JComboBox(levelYear));
  693.            
  694.             idNum.setHorizontalAlignment(JTextField.CENTER);
  695.             firstName.setHorizontalAlignment(JTextField.CENTER);
  696.             lastName.setHorizontalAlignment(JTextField.CENTER);
  697.            
  698.         btnPanel.setLayout(new FlowLayout(FlowLayout.CENTER,5,0));
  699.             btnPanel.add(btnAdd = new JButton("Add"));
  700.             btnPanel.add(btnExt = new JButton("Close"));
  701.            
  702.         txtLblPanel.setLayout(new BoxLayout(txtLblPanel, BoxLayout.LINE_AXIS));        
  703.             txtLblPanel.add(lblPanel);
  704.             txtLblPanel.add(Box.createRigidArea(new Dimension(5,5)));
  705.             txtLblPanel.add(txtPanel);
  706.            
  707.         iconPanel.setLayout(new FlowLayout(FlowLayout.RIGHT,1,1));
  708.             iconPanel.add(lblIcon = new JLabel(new ImageIcon("image/wi0062-32.gif"),JLabel.LEFT));                 
  709.             iconPanel.setBorder(BorderFactory.createEtchedBorder());
  710.  
  711.         btnAdd.addActionListener(new ActionListener(){
  712.             public void actionPerformed(ActionEvent e)
  713.             {
  714.                 if(!isEmptyTextBox()){
  715.                     if(!existIdNum(idNum.getText())){
  716.                         addNewStudent();
  717.                         message();
  718.                         dispose(); 
  719.                     }else{
  720.                         JOptionPane.showMessageDialog(dialog,"ID number has already exist.","Message",JOptionPane.ERROR_MESSAGE);
  721.                     }
  722.                 }  
  723.                 else{
  724.                     JOptionPane.showMessageDialog(dialog,"Please fill up the textbox complete.","Message",JOptionPane.ERROR_MESSAGE);
  725.                 }
  726.             }
  727.         });
  728.        
  729.         btnExt.addActionListener(new ActionListener(){
  730.             public void actionPerformed(ActionEvent e)
  731.             {
  732.                 dispose();
  733.             }
  734.         });
  735.     }
  736.    
  737.     public JPanel getPanel()
  738.     {
  739.         return panel;
  740.     }
  741.  
  742.     public boolean isEmptyTextBox()
  743.     {
  744.         return(firstName.getText().length() == 0 ||
  745.                lastName.getText().length()  == 0 ||
  746.                idNum.getText().length()     == 0 ||
  747.                course.getSelectedIndex()    == 0 ||
  748.                yearLevel.getSelectedIndex() == 0);
  749.     }
  750.    
  751.     public void message()
  752.     {
  753.         JOptionPane.showMessageDialog(dialog,"Successfull","Message",JOptionPane.INFORMATION_MESSAGE);
  754.     }
  755.    
  756.     public void addNewStudent()
  757.     {
  758.         newStudent = new Student(firstName.getText().trim(),
  759.                                  lastName.getText().trim(),
  760.                                  Integer.valueOf(idNum.getText().trim()),
  761.                                  String.valueOf(course.getSelectedItem()),
  762.                                  String.valueOf(yearLevel.getSelectedItem()));
  763.        
  764.         list.addLast(newStudent);
  765.        
  766.         StudentList sl = new StudentList(newStudent,list);
  767.         System.out.println(list.size() - 1);
  768.         sl.setRecord(list.size() - 1);
  769.        
  770.         Student student = (Student)list.getLast();
  771.        
  772.         new StudentRecordGUI(true);
  773.         new StudentRecordGUI(list.size());
  774.         new StudentRecordGUI(student.getFirstName(),
  775.                              student.getLastName(),
  776.                              student.getIdNum(),
  777.                              student.getCourse(),
  778.                              student.getYearLevel());
  779.     }
  780.    
  781.     public boolean existIdNum(String idNumber)
  782.     {
  783.         boolean found = false;
  784.        
  785.         StudentList s = new StudentList();
  786.        
  787.         for(int i = 0; i < list.size(); i++)
  788.         {
  789.             Student id = (Student)s.getList().get(i);
  790.             if(Integer.valueOf(idNumber).equals(id.getIdNum()))
  791.             {
  792.                 found = true;
  793.                 break;
  794.             }
  795.         }
  796.         return found;  
  797.     }
  798.        
  799.     public void dispose()
  800.     {
  801.         dialog.setVisible(false);
  802.         dialog.dispose();
  803.     }
  804. }
  805.  
  806.  
  807. ---------------------------------------------------------------------------
  808.  
  809. /*
  810.  *  Name    Ryan Nilo Ybañez
  811.  *  Course  BSCS - IV
  812.  *  Subject Data Structure java implemented
  813.  *
  814.  **/
  815.  
  816. import java.awt.event.*;
  817.  
  818. import javax.swing.*;
  819.  
  820. public class Next extends AbstractAction
  821. {
  822.     StudentList studentList = new StudentList();
  823.     private int size;
  824.    
  825.  
  826.     public Next(String command,ImageIcon icon)
  827.     {
  828.         super(command,icon);
  829.     }
  830.    
  831.     public void actionPerformed(ActionEvent event)
  832.     {
  833.         try{
  834.             if(studentList.getRecord() < studentList.getSize())
  835.                 {
  836.                     int i = studentList.getRecord();
  837.                     Student student = (Student)studentList.getList().get(i + 1);
  838.            
  839.                     studentList.setRecord(++i);
  840.            
  841.                     new StudentRecordGUI(1 + i);           
  842.                     new StudentRecordGUI(student.getFirstName(),
  843.                                          student.getLastName(),
  844.                                          student.getIdNum(),
  845.                                          student.getCourse(),
  846.                                          student.getYearLevel());
  847.             }
  848.         }
  849.         catch(Exception e)
  850.         {}
  851.     }
  852. }
  853.  
  854.  
  855. -------------------------------------------------------------------------------
  856.  
  857.  
  858.  
  859. public class Node
  860. {
  861.     private Object data;
  862.     private Node next;
  863.    
  864.     public Node()
  865.     {
  866.         data = null;
  867.         next = null;
  868.     }
  869.    
  870.     public Node(Object data)
  871.     {
  872.         this.data = data;
  873.     }
  874.    
  875.     public Node(Object data,Node next)
  876.     {
  877.         this.data = data;
  878.         this.next = next;
  879.     }
  880.    
  881.     public void setNext(Node n)
  882.     {
  883.         next = n;
  884.     }
  885.    
  886.     public Node getNext()
  887.     {
  888.         return next;
  889.     }
  890.    
  891.     public Object getData()
  892.     {
  893.         return data;
  894.     }
  895. }
  896.  
  897.  
  898. --------------------------------------------------------------------------------
  899.  
  900.  
  901.  
  902. /*
  903.  *  Name    Ryan Nilo Ybañez
  904.  *  Course  BSCS - IV
  905.  *  Subject Data Structure java implemented
  906.  *
  907.  **/
  908.  
  909. public class Person
  910. {
  911.     private String fName;
  912.     private String lName;
  913.    
  914.     public Person(String firstname, String lastname)
  915.     {
  916.         fName = firstname;
  917.         lName = lastname;
  918.     }
  919.    
  920.     public void setFirstName(String firstname)
  921.     {
  922.         fName = firstname;
  923.     }
  924.    
  925.     public void setLastName(String lastname)
  926.     {
  927.         lName = lastname;
  928.     }
  929.    
  930.     public String getFirstName()
  931.     {
  932.         return fName;
  933.     }
  934.    
  935.     public String getLastName()
  936.     {
  937.         return lName;
  938.     }
  939. }
  940.  
  941.  
  942. -------------------------------------------------------------------------
  943.  
  944. /*
  945.  *  Name    Ryan Nilo Ybañez
  946.  *  Course  BSCS - IV
  947.  *  Subject Data Structure java implemented
  948.  *
  949.  **/
  950.  
  951. import java.awt.event.*;
  952. import javax.swing.*;
  953.  
  954. public class Prev extends AbstractAction
  955. {
  956.     StudentList studentList = new StudentList();
  957.    
  958.     public Prev(String command,ImageIcon icon)
  959.     {
  960.         super(command,icon);
  961.     }
  962.    
  963.     public void actionPerformed(ActionEvent event)
  964.     {
  965.         try
  966.         {
  967.             prevStudentRecord();
  968.         }
  969.         catch(Exception e)
  970.         {}
  971.     }
  972.    
  973.     public void prevStudentRecord()
  974.     {
  975.         if(studentList.getRecord() != 0)
  976.         {
  977.             int i = studentList.getRecord();
  978.            
  979.                 Student student = (Student)studentList.getList().get(i - 1);
  980.                 studentList.setRecord(--i);
  981.            
  982.                 new StudentRecordGUI(i + 1);           
  983.                 new StudentRecordGUI(student.getFirstName(),
  984.                                      student.getLastName(),
  985.                                      student.getIdNum(),
  986.                                      student.getCourse(),
  987.                                      student.getYearLevel());
  988.         }
  989.     }
  990. }
  991.  
  992. -----------------------------------------------------------------------------
  993.  
  994.  
  995.  
  996. /*
  997.  *  Name    Ryan Nilo Ybañez
  998.  *  Course  BSCS - IV
  999.  *  Subject Data Structure java implemented
  1000.  *
  1001.  **/
  1002.  
  1003. import java.awt.event.*;
  1004.  
  1005. import javax.swing.*;
  1006.  
  1007. public class Search extends AbstractAction
  1008. {
  1009.     private StudentList studentList = new StudentList();
  1010.    
  1011.     private JFrame      frame;
  1012.     private JOptionPane dialog;
  1013.    
  1014.     public Search(String commandAction,JFrame frame)
  1015.     {
  1016.         super(commandAction);
  1017.         this.frame = frame;
  1018.     }
  1019.    
  1020.     public void actionPerformed(ActionEvent event)
  1021.     {
  1022.         Object[] search = {"ID #","FirstName","LastName"};
  1023.         String s = (String)dialog.showInputDialog(
  1024.                                   frame,
  1025.                                   "Search By:",
  1026.                                   "Search",
  1027.                                   JOptionPane.PLAIN_MESSAGE,
  1028.                                   null,
  1029.                                   search,
  1030.                                   "ID #");
  1031.        
  1032.         if(s == "ID #")
  1033.         {
  1034.             boolean foundID = false;
  1035.             String id = JOptionPane.showInputDialog(
  1036.                                     frame,
  1037.                                     "Search " + s +":",
  1038.                                     "Search",
  1039.                                     JOptionPane.PLAIN_MESSAGE);
  1040.             if(id != null && id.length() != 0){
  1041.                 for(int i = 0; i < studentList.getSize(); i++){
  1042.                     Student student = (Student)studentList.getList().get(i);                                       
  1043.                     if(Integer.valueOf(id).equals(student.getIdNum())){
  1044.                         studentList(student,i);
  1045.                         foundID = true;
  1046.                         break;
  1047.                     }
  1048.                 }
  1049.                 if(foundID == false)
  1050.                 {
  1051.                     JOptionPane.showMessageDialog(frame,
  1052.                                                   "Searching,"+" " + id +" "+"does not exist.",
  1053.                                                   "Search",
  1054.                                                   JOptionPane.ERROR_MESSAGE);
  1055.                 }
  1056.             }
  1057.         }
  1058.         else if(s == "FirstName")
  1059.         {
  1060.             boolean foundFirstName = false;
  1061.             String firstname = (String)JOptionPane.showInputDialog(
  1062.                                            frame,
  1063.                                            "Search " + s +":",
  1064.                                            "Search",
  1065.                                            JOptionPane.PLAIN_MESSAGE);
  1066.             if(firstname != null && firstname.length() != 0){
  1067.                 for(int i = 0; i < studentList.getSize(); i++){
  1068.                     Student student = (Student)studentList.getList().get(i);                                       
  1069.                     if(firstname.equals(student.getFirstName())){
  1070.                         studentList(student,i);
  1071.                         foundFirstName = true;
  1072.                         break;
  1073.                     }
  1074.                 }
  1075.                 if(foundFirstName == false)
  1076.                 {
  1077.                     JOptionPane.showMessageDialog(frame,
  1078.                                                   "Searching,"+" " + firstname +" "+"does not exist.",
  1079.                                                   "Search",
  1080.                                                   JOptionPane.ERROR_MESSAGE);
  1081.                 }
  1082.             }
  1083.         }
  1084.         else if(s == "LastName")
  1085.         {
  1086.             boolean foundLastName = false;
  1087.             String lastname = JOptionPane.showInputDialog(
  1088.                                            frame,
  1089.                                            "Search " + s +":",
  1090.                                            "Search",
  1091.                                            JOptionPane.PLAIN_MESSAGE);
  1092.             if(lastname != null && lastname.length() != 0){
  1093.                 for(int i = 0; i < studentList.getSize(); i++){
  1094.                     Student student = (Student)studentList.getList().get(i);                                       
  1095.                     if(lastname.equals(student.getLastName())){
  1096.                         studentList(student,i);
  1097.                         foundLastName = true;
  1098.                         break;
  1099.                     }
  1100.                 }
  1101.                 if(foundLastName  == false)
  1102.                 {
  1103.                     JOptionPane.showMessageDialog(frame,
  1104.                                                   "Searching,"+" " + lastname +" "+"does not exist.",
  1105.                                                   "Search",
  1106.                                                   JOptionPane.ERROR_MESSAGE);
  1107.                 }
  1108.             }
  1109.         }
  1110.     }
  1111.    
  1112.     public void studentList(Student student,int index)
  1113.     {
  1114.         student = (Student)studentList.getList().get(index);
  1115.        
  1116.         studentList.setRecord(index);
  1117.  
  1118.         new StudentRecordGUI(studentList.getRecord() + 1);
  1119.         new StudentRecordGUI(student.getFirstName(),
  1120.                              student.getLastName(),
  1121.                              student.getIdNum(),
  1122.                              student.getCourse(),
  1123.                              student.getYearLevel());
  1124.     }
  1125. }
  1126.  
  1127.  
  1128. ------------------------------------------------------------------------------
  1129.  
  1130.  
  1131. /*
  1132.  *  Name    Ryan Nilo Ybañez
  1133.  *  Course  BSCS - IV
  1134.  *  Subject Data Structure java implemented
  1135.  *
  1136.  **/
  1137.  
  1138. public class Student extends Person
  1139. {
  1140.     private Integer id;
  1141.     private String course;
  1142.     private String level;
  1143.    
  1144.     public Student(String firstname, String lastname, Integer id, String course, String level)
  1145.     {
  1146.         super(firstname,lastname);
  1147.         this.id     = id;
  1148.         this.course = course;
  1149.         this.level  = level;
  1150.     }
  1151.    
  1152.     public void setId(Integer id)
  1153.     {
  1154.         this.id = id;
  1155.     }
  1156.    
  1157.     public void SetCourse(String course)
  1158.     {
  1159.         this.course = course;
  1160.     }
  1161.    
  1162.     public void setLevel(String level)
  1163.     {
  1164.         this.level = level;
  1165.     }
  1166.    
  1167.     public Integer getIdNum()
  1168.     {
  1169.         return id;
  1170.     }
  1171.    
  1172.     public String getCourse()
  1173.     {
  1174.         return course;
  1175.     }
  1176.    
  1177.     public String getYearLevel()
  1178.     {
  1179.         return level;
  1180.     }
  1181. }
  1182.  
  1183.  
  1184. --------------------------------------------------------------------------
  1185.  
  1186.  
  1187.  
  1188. /*
  1189.  *  Name    Ryan Nilo Ybañez
  1190.  *  Course  BSCS - IV
  1191.  *  Subject Data Structure java implemented
  1192.  *
  1193.  **/
  1194.  
  1195. import java.util.*;
  1196.  
  1197. public class StudentList
  1198. {
  1199.     static Student student = null;
  1200.     static LinkedList list = null;
  1201.     static int record;
  1202.    
  1203.     public StudentList()
  1204.     {}
  1205.        
  1206.     public StudentList(Student student,LinkedList list)
  1207.     {
  1208.         this.student = student;
  1209.         this.list    = list;
  1210.     }
  1211.    
  1212.     public Student getStudentList()
  1213.     {
  1214.         return student;
  1215.     }
  1216.    
  1217.     public void setRecord(int n)
  1218.     {
  1219.         record = n;
  1220.     }
  1221.    
  1222.     public int getRecord()
  1223.     {
  1224.         return record;
  1225.     }
  1226.    
  1227.     public LinkedList getList()
  1228.     {
  1229.         return list;
  1230.     }
  1231.  
  1232.     public static int getSize()
  1233.     {
  1234.         return list.size();
  1235.     }
  1236. }
  1237.  
  1238.  
  1239. --------------------------------------------------------------------------------
  1240.  
  1241.  
  1242.  
  1243.  
  1244. /*
  1245.  *  Name    Ryan Nilo Ybañez
  1246.  *
  1247.  **/
  1248.  
  1249. import java.util.*;
  1250. import java.awt.*;
  1251. import java.awt.event.*;
  1252.  
  1253. import javax.swing.*;
  1254. import javax.swing.border.*;
  1255.  
  1256. public class StudentRecordGUI extends JPanel
  1257. {
  1258.     static private final int BUTTON_INDEX = 8;
  1259.  
  1260.     static private JFrame       frame;
  1261.     static private JTextField   firstName, lastName, idNum, course, yearLevel;
  1262.     static private JLabel       numRecord;
  1263.     static private JButton[]    button = new JButton[BUTTON_INDEX];
  1264.  
  1265.     private JPanel      mainPanel, iconPanel,txtLblPanel;
  1266.     private JPanel      symPanel, comPanel;
  1267.     private JLabel      label, lblIcon;
  1268.     private JDialog     dialog;
  1269.  
  1270.     private JButton     btnCount;
  1271.     private Action      add,delete,search,edit,first,last,prev,next,count;
  1272.  
  1273.     public StudentRecordGUI(JFrame frame)
  1274.     {
  1275.         add     = new Add("Add",frame);
  1276.         delete  = new Delete("Delete",frame);
  1277.         search  = new Search("Search",frame);
  1278.         edit    = new Edit("Edit",frame);
  1279.  
  1280.         first   = new First(null,new ImageIcon("image/first.gif"));
  1281.         last    = new Last(null, new ImageIcon("image/last.gif"));
  1282.         prev    = new Prev(null, new ImageIcon("image/prev.gif"));
  1283.         next    = new Next(null, new ImageIcon("image/next.gif"));
  1284.  
  1285.         setLayout(new BorderLayout());
  1286.         setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
  1287.  
  1288.         JToolBar toolBar = new JToolBar("ToolBar");
  1289.         toolBar.setFloatable(false);
  1290.         toolBar.setRollover(true);
  1291.  
  1292.         txtLblPanel = new JPanel();
  1293.         iconPanel   = new JPanel();
  1294.         symPanel    = new JPanel();
  1295.         comPanel    = new JPanel();
  1296.  
  1297.         toolBar.add(button[0] = new JButton(first));
  1298.         toolBar.add(button[1] = new JButton(prev));
  1299.         toolBar.add(button[2] = new JButton(next));
  1300.         toolBar.add(button[3] = new JButton(last));
  1301.         toolBar.addSeparator();
  1302.         toolBar.add(numRecord = new JLabel("Record #: 0"));
  1303.  
  1304.         button[4] = new JButton(add);
  1305.         button[5] = new JButton(edit);
  1306.         button[6] = new JButton(search);
  1307.         button[7] = new JButton(delete);
  1308.  
  1309.         button[5].setEnabled(false);
  1310.         button[6].setEnabled(false);
  1311.         button[7].setEnabled(false);
  1312.  
  1313.         button[4].setPreferredSize(new Dimension(80,26));
  1314.         button[5].setPreferredSize(new Dimension(80,26));
  1315.         button[6].setPreferredSize(new Dimension(80,26));
  1316.         button[7].setPreferredSize(new Dimension(80,26));
  1317.  
  1318.         button[0].setToolTipText("First");
  1319.         button[1].setToolTipText("Previous");
  1320.         button[2].setToolTipText("Next");
  1321.         button[3].setToolTipText("Last");
  1322.  
  1323.         addLayout();
  1324.  
  1325.         mainPanel   = new JPanel();
  1326.         mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));
  1327.         mainPanel.setBorder(BorderFactory.createCompoundBorder(
  1328.                             BorderFactory.createTitledBorder("Student Information"),
  1329.                             BorderFactory.createEmptyBorder(5,5,5,5)));
  1330.  
  1331.         mainPanel.add(txtLblPanel);
  1332.  
  1333.         JPanel layout = new JPanel();
  1334.             layout.setLayout(new BoxLayout(layout, BoxLayout.PAGE_AXIS));
  1335.             layout.add(Box.createRigidArea(new Dimension(5,5)));
  1336.             layout.add(iconPanel);
  1337.             layout.add(Box.createRigidArea(new Dimension(5,5)));
  1338.             layout.add(mainPanel);
  1339.             layout.add(Box.createRigidArea(new Dimension(5,5)));
  1340.             layout.add(comPanel);
  1341.  
  1342.         add(toolBar, BorderLayout.PAGE_START);
  1343.         add(layout,  BorderLayout.PAGE_END);
  1344.  
  1345.     }
  1346.  
  1347.     public StudentRecordGUI(boolean tF)
  1348.     {
  1349.         button[5].setEnabled(tF);
  1350.         button[6].setEnabled(tF);
  1351.         button[7].setEnabled(tF);
  1352.     }
  1353.  
  1354.     public StudentRecordGUI(int n)
  1355.     {
  1356.         numRecord.setText("Record #: " + String.valueOf(n));
  1357.     }
  1358.  
  1359.     public StudentRecordGUI(String firstname, String lastname, Integer num, String c, String yearlevel)
  1360.     {
  1361.         idNum.setText(String.valueOf(num));
  1362.         firstName.setText(firstname);
  1363.         lastName.setText(lastname);
  1364.         course.setText(c);
  1365.         yearLevel.setText(yearlevel);
  1366.     }
  1367.  
  1368.     public void addLayout()
  1369.     {
  1370.         JPanel lblPanel = new JPanel();
  1371.         lblPanel.setLayout(new GridLayout(5,1,25,5));
  1372.             lblPanel.add(label = new JLabel("Student Id :",JLabel.RIGHT));
  1373.             lblPanel.add(label = new JLabel("First Name :",JLabel.RIGHT));
  1374.             lblPanel.add(label = new JLabel("Last Name :",JLabel.RIGHT));
  1375.             lblPanel.add(label = new JLabel("Course :",JLabel.RIGHT));
  1376.             lblPanel.add(label = new JLabel("Year Level :",JLabel.RIGHT));
  1377.  
  1378.         JPanel txtPanel = new JPanel();
  1379.         txtPanel.setLayout(new GridLayout(5,1,25,0));
  1380.             txtPanel.add(idNum      = new JTextField(25));
  1381.             txtPanel.add(firstName  = new JTextField(25));
  1382.             txtPanel.add(lastName   = new JTextField(25));
  1383.             txtPanel.add(course     = new JTextField(25));
  1384.             txtPanel.add(yearLevel  = new JTextField(25));
  1385.  
  1386.             idNum.setHorizontalAlignment(JTextField.CENTER);
  1387.             firstName.setHorizontalAlignment(JTextField.CENTER);
  1388.             lastName.setHorizontalAlignment(JTextField.CENTER);
  1389.             course.setHorizontalAlignment(JTextField.CENTER);
  1390.             yearLevel.setHorizontalAlignment(JTextField.CENTER);
  1391.  
  1392.             idNum.setFocusable(false);
  1393.             firstName.setFocusable(false);
  1394.             lastName.setFocusable(false);
  1395.             course.setFocusable(false);
  1396.             yearLevel.setFocusable(false);
  1397.  
  1398.         txtLblPanel.setLayout(new BoxLayout(txtLblPanel, BoxLayout.LINE_AXIS));
  1399.             txtLblPanel.add(lblPanel);
  1400.             txtLblPanel.add(Box.createRigidArea(new Dimension(5,5)));
  1401.             txtLblPanel.add(txtPanel);
  1402.             txtLblPanel.setPreferredSize(new Dimension(350,130));
  1403.  
  1404.         comPanel.setLayout(new FlowLayout(FlowLayout.CENTER,5,0));
  1405.             for(int i = 4; i < button.length; i++){
  1406.                 comPanel.add(button[i]);
  1407.                 button[i].setFont(new Font("sans-serif",Font.PLAIN,10));
  1408.             }
  1409.  
  1410.         iconPanel.setLayout(new FlowLayout(FlowLayout.RIGHT,1,1));
  1411.             iconPanel.add(lblIcon = new JLabel(new ImageIcon("image/wi0054-32.gif")));
  1412.             iconPanel.setBorder(BorderFactory.createEtchedBorder());
  1413.     }
  1414.  
  1415.     public static void createAndShowGUI()
  1416.     {
  1417.         JFrame frame = new JFrame("Student Record");
  1418.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  1419.  
  1420.         frame.setContentPane(new StudentRecordGUI(frame));
  1421.  
  1422.         frame.pack();
  1423.         frame.setVisible(true);
  1424.         frame.setResizable(false);
  1425.     }
  1426.  
  1427.     public static void main(String[] args)
  1428.     {
  1429.         Runnable doRun = new Runnable(){
  1430.             public void run(){
  1431.                 createAndShowGUI();
  1432.             }
  1433.         };
  1434.  
  1435.         javax.swing.SwingUtilities.invokeLater(doRun);
  1436.     }
  1437. }
  1438.  
  1439.  
  1440. --------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment