Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Name Ryan Nilo Ybañez
- * Course BSCS - IV
- * Subject Data Structure java implemented
- *
- **/
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class Add extends AbstractAction
- {
- private JDialog dialog;
- private JFrame frame;
- public Add(String commandAction,JFrame frame)
- {
- super(commandAction);
- this.frame = frame;
- }
- public void actionPerformed(ActionEvent event)
- {
- addNewStudent();
- }
- public void addNewStudent()
- {
- dialog = new JDialog(frame,"Add Record",true);
- dialog.setContentPane(new NewStudent(dialog).getPanel());
- dialog.pack();
- dialog.setLocationRelativeTo(frame);
- dialog.setVisible(true);
- }
- }
- ----------------------------------------------------------------------------
- /*
- * Name Ryan Nilo Ybañez
- * Course BSCS - IV
- * Subject Data Structure java implemented
- *
- **/
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class Delete extends AbstractAction
- {
- private StudentList studentList = new StudentList();
- private JFrame frame = null;
- public Delete(String commandAction,JFrame frame)
- {
- super(commandAction);
- this.frame = frame;
- }
- public void actionPerformed(ActionEvent event)
- {
- if(studentList.getList().size() != 0)
- {
- int n = JOptionPane.showConfirmDialog(
- frame,
- "Are you sure? you want to delete this record 'student'",
- "Confirm delete",
- JOptionPane.YES_NO_OPTION);
- if(n == JOptionPane.YES_OPTION)
- {
- deleteStudentRecord();
- }
- }
- }
- public void deleteStudentRecord()
- {
- studentList.getList().remove(studentList.getRecord());
- if(studentList.getList().size() != 0)
- {
- Student student = (Student)studentList.getList().getLast();
- studentList.setRecord(studentList.getList().size() - 1);
- new StudentRecordGUI(studentList.getRecord() + 1);
- new StudentRecordGUI(student.getFirstName(),
- student.getLastName(),
- student.getIdNum(),
- student.getCourse(),
- student.getYearLevel());
- }
- else
- {
- new StudentRecordGUI(false);
- new StudentRecordGUI(0);
- new StudentRecordGUI("","",0,"","");
- }
- }
- }
- ---------------------------------------------------------------------------
- /*
- * Name Ryan Nilo Ybañez
- * Course BSCS - IV
- * Subject Data Structure java implemented
- *
- **/
- import java.awt.event.*;
- import javax.swing.*;
- public class Edit extends AbstractAction
- {
- StudentList studentList = new StudentList();
- Student student = null;
- private JFrame frame = null;
- private JDialog dialog = null;
- public Edit(String commandAction,JFrame frame)
- {
- super(commandAction);
- this.frame = frame;
- }
- public void actionPerformed(ActionEvent event)
- {
- try
- {
- if(studentList.getList().getFirst() != null)
- {
- editStudentProfile();
- }
- else
- {
- JOptionPane.showMessageDialog(
- frame,
- "Empty student record.",
- "Edit",
- JOptionPane.ERROR_MESSAGE);
- }
- }
- catch(Exception e)
- {
- JOptionPane.showMessageDialog(
- frame,
- "Empty student record.",
- "Edit",
- JOptionPane.ERROR_MESSAGE);
- }
- }
- public void editStudentProfile()
- {
- int i = studentList.getRecord();
- student = (Student)studentList.getList().get(i);
- studentList.setRecord(i);
- dialog = new JDialog(frame,"Edit Student Profile",true);
- dialog.setContentPane(new EditProfile(student,dialog,i).getPanel());
- dialog.pack();
- dialog.setLocationRelativeTo(frame);
- dialog.setVisible(true);
- }
- }
- -------------------------------------------------------------------------------
- /*
- * Name Ryan Nilo Ybañez
- * Course BSCS - IV
- * Subject Data Structure java implemented
- *
- **/
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class EditProfile extends JPanel
- {
- private StudentList studentList = new StudentList();
- private Student student;
- private JPanel panel,mainPanel,txtLblPanel,btnPanel,iconPanel;
- private JLabel label,lblIcon;
- private JTextField firstName, lastName, idNum;
- private JButton btnSave,btnExt;
- private JComboBox course,yearLevel;
- private JDialog dialog;
- private String[] listOfCourse = {
- "SELECT COURSE","",
- "ACCOUNTANCY",
- "BANKING IN FINANACE",
- "COMPUTER SCIENCE",
- "CRIMINOLOGY",
- "COM - E",
- "ELECTRONIC COMM - E",
- "INFORMATION TECHNOLOGY",
- "MANAGEMENT",
- "MARINE ENGINEERING",
- "NURCING",
- "NAUTICAL"
- };
- private String[] levelYear = {
- "1TH YEAR",
- "2TH YEAR",
- "3TH YEAR",
- "4TH YEAR",
- "5TH YEAR"
- };
- private int index;
- public EditProfile(Student student,JDialog dialog,int index)
- {
- this();
- this.dialog = dialog;
- this.index = index;
- firstName.setText(student.getFirstName());
- lastName.setText(student.getLastName());
- idNum.setText(String.valueOf(student.getIdNum()));
- course.setSelectedItem(student.getCourse());
- yearLevel.setSelectedItem(student.getYearLevel());
- }
- public EditProfile()
- {
- panel = new JPanel();
- panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
- panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
- txtLblPanel = new JPanel();
- iconPanel = new JPanel();
- btnPanel = new JPanel();
- addLayout();
- mainPanel = new JPanel();
- mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));
- mainPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
- mainPanel.add(txtLblPanel);
- mainPanel.add(Box.createRigidArea(new Dimension(5,5)));
- mainPanel.add(btnPanel);
- panel.add(iconPanel);
- panel.add(mainPanel);
- }
- public JPanel getPanel()
- {
- return panel;
- }
- public void addLayout()
- {
- JPanel lblPanel = new JPanel();
- lblPanel.setLayout(new GridLayout(5,1,5,1));
- lblPanel.add(label = new JLabel("Student Id :",JLabel.RIGHT));
- lblPanel.add(label = new JLabel("First Name :",JLabel.RIGHT));
- lblPanel.add(label = new JLabel("Last Name :",JLabel.RIGHT));
- lblPanel.add(label = new JLabel("Course :",JLabel.RIGHT));
- lblPanel.add(label = new JLabel("Year Level :",JLabel.RIGHT));
- JPanel txtPanel = new JPanel();
- txtPanel.setLayout(new GridLayout(5,1));
- txtPanel.add(idNum = new JTextField(15));
- txtPanel.add(firstName = new JTextField(15));
- txtPanel.add(lastName = new JTextField(15));
- txtPanel.add(course = new JComboBox(listOfCourse));
- txtPanel.add(yearLevel = new JComboBox(levelYear));
- idNum.setHorizontalAlignment(JTextField.CENTER);
- firstName.setHorizontalAlignment(JTextField.CENTER);
- lastName.setHorizontalAlignment(JTextField.CENTER);
- btnPanel.setLayout(new FlowLayout(FlowLayout.CENTER,5,0));
- btnPanel.add(btnSave = new JButton("Save"));
- btnPanel.add(btnExt = new JButton("Close"));
- txtLblPanel.setLayout(new BoxLayout(txtLblPanel, BoxLayout.LINE_AXIS));
- txtLblPanel.add(lblPanel);
- txtLblPanel.add(Box.createRigidArea(new Dimension(5,5)));
- txtLblPanel.add(txtPanel);
- iconPanel.setLayout(new FlowLayout(FlowLayout.RIGHT,1,1));
- iconPanel.add(lblIcon = new JLabel(new ImageIcon("image/wi0062-32.gif"),JLabel.LEFT));
- iconPanel.setBorder(BorderFactory.createEtchedBorder());
- btnSave.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e)
- {
- int n = JOptionPane.showConfirmDialog(
- dialog,
- "Continue save?",
- "Confirm save",
- JOptionPane.YES_NO_OPTION);
- if(n == JOptionPane.YES_OPTION)
- {
- save();
- message();
- dispose();
- }
- }
- });
- btnExt.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e)
- {
- dispose();
- }
- });
- }
- public void save()
- {
- student = new Student(firstName.getText().trim(),
- lastName.getText().trim(),
- Integer.valueOf(idNum.getText().trim()),
- String.valueOf(course.getSelectedItem()),
- String.valueOf(yearLevel.getSelectedItem()));
- studentList.getList().set(index,student);
- Student update = (Student)studentList.getList().get(index);
- new StudentRecordGUI(update.getFirstName(),
- update.getLastName(),
- update.getIdNum(),
- update.getCourse(),
- update.getYearLevel());
- }
- public void message()
- {
- JOptionPane.showMessageDialog(
- dialog,
- "Successfull.",
- "Message",
- JOptionPane.INFORMATION_MESSAGE);
- }
- public void dispose()
- {
- dialog.setVisible(false);
- dialog.dispose();
- }
- }
- ----------------------------------------------------------------
- /*
- * Name Ryan Nilo Ybañez
- * Course BSCS - IV
- * Subject Data Structure java implemented
- *
- **/
- import java.util.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class First extends AbstractAction
- {
- private StudentList studentList = new StudentList();
- public First(String command, ImageIcon icon)
- {
- super(command,icon);
- }
- public void actionPerformed(ActionEvent event)
- {
- try
- {
- Student student = (Student)studentList.getList().getFirst();
- studentList.setRecord(0);
- new StudentRecordGUI(1);
- new StudentRecordGUI(student.getFirstName(),
- student.getLastName(),
- student.getIdNum(),
- student.getCourse(),
- student.getYearLevel());
- }
- catch(Exception e)
- {}
- }
- }
- --------------------------------------------------------------------------------
- /*
- * Name Ryan Nilo Ybañez
- * Course BSCS - IV
- * Subject Data Structure java implemented
- *
- **/
- import java.awt.event.*;
- import javax.swing.*;
- public class Last extends AbstractAction
- {
- StudentList studentList = new StudentList();
- public Last(String command,ImageIcon icon)
- {
- super(command,icon);
- }
- public void actionPerformed(ActionEvent event)
- {
- try
- {
- Student student = (Student)studentList.getList().getLast();
- studentList.setRecord(studentList.getList().size() - 1);
- new StudentRecordGUI(studentList.getSize());
- new StudentRecordGUI(student.getFirstName(),
- student.getLastName(),
- student.getIdNum(),
- student.getCourse(),
- student.getYearLevel());
- }
- catch(Exception e)
- {}
- }
- }
- -------------------------------------------------------------
- public class MyException extends Exception
- {
- public MyException(String message)
- {
- super(message);
- }
- }
- -----------------------------------------------------------------------------
- /*
- * Name: Ryan Nilo Ybanez
- * Course: BSCS - IV
- *
- **/
- public class MyLinkedList
- {
- private Node head,tail;
- private int size;
- public void add(Object data)
- {
- addEnd(data);
- size++;
- }
- public void addFront(Object data)
- {
- Node newNode = new Node(data,null);
- newNode.setNext(head);
- head = newNode;
- }
- public void addEnd(Object data)
- {
- if(isEmpty()){
- head = new Node(data,null);
- tail = head;
- }
- else{
- Node p = tail;
- tail = new Node(data,p.getNext());
- p.setNext(tail);
- }
- }
- public boolean remove(Object data)
- {
- boolean remove = false;
- Node p = head;
- Node prev = head;
- if(p.getData().equals(data)){
- head = p.getNext();
- p.setNext(null);
- remove = true;
- }
- else{
- while(p.getNext() != null){
- prev = p;
- p = p.getNext();
- if(p.getData().equals(data)){
- prev.setNext(p.getNext());
- p.setNext(null);
- remove = true;
- }
- }
- }
- System.gc();
- return remove;
- }
- public Object getFirst()
- {
- return head.getData();
- }
- public Object getLast()
- {
- return tail.getData();
- }
- public int size()
- {
- return size;
- }
- public boolean isEmpty()
- {
- return head == null;
- }
- public String toString()
- {
- StringBuffer sb = new StringBuffer();
- Node p = head;
- while(p != null)
- {
- sb.append(p.getData());
- p = p.getNext();
- if(p != null)
- {
- sb.append(",");
- }
- }
- return sb.toString();
- }
- public static void main(String[] args)
- {
- MyLinkedList linklist = new MyLinkedList();
- StringBuffer sb = new StringBuffer();
- linklist.add("adsf");
- linklist.add("02938");
- linklist.add("asdfasdf");
- System.out.println(linklist);
- }
- }
- -----------------------------------------------------
- /*
- * Name Ryan Nilo Ybañez
- * Course BSCS - IV
- * Subject Data Structure java implemented
- *
- **/
- import java.util.*;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class NewStudent extends JFrame
- {
- static private LinkedList list = new LinkedList();
- static private Student newStudent;
- private JPanel panel,mainPanel,txtLblPanel,btnPanel,iconPanel;
- private JLabel label,lblIcon;
- private JTextField firstName, lastName, idNum;
- private JButton btnAdd,btnExt;
- private JComboBox course,yearLevel;
- private JDialog dialog;
- private String[] listOfCourse = {
- "[ SELECT COURSE ]",
- "ACCOUNTANCY",
- "BANKING IN FINANACE",
- "COMPUTER SCIENCE",
- "CRIMINOLOGY",
- "COM - E",
- "ELECTRONIC COMM - E",
- "INFORMATION TECHNOLOGY",
- "MANAGEMENT",
- "MARINE ENGINEERING",
- "NURCING",
- "NAUTICAL"
- };
- private String[] levelYear = {
- "[ SELECT LEVEL ]",
- "1TH YEAR",
- "2TH YEAR",
- "3TH YEAR",
- "4TH YEAR",
- "5TH YEAR"
- };
- public NewStudent(JDialog dialog)
- {
- this();
- this.dialog = dialog;
- }
- public NewStudent()
- {
- panel = new JPanel();
- panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
- panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
- txtLblPanel = new JPanel();
- iconPanel = new JPanel();
- btnPanel = new JPanel();
- addLayout();
- mainPanel = new JPanel();
- mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));
- mainPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
- mainPanel.add(txtLblPanel);
- mainPanel.add(Box.createRigidArea(new Dimension(5,5)));
- mainPanel.add(btnPanel);
- panel.add(iconPanel);
- panel.add(mainPanel);
- }
- public void addLayout()
- {
- JPanel lblPanel = new JPanel();
- lblPanel.setLayout(new GridLayout(5,1,5,1));
- lblPanel.add(label = new JLabel("Student Id :",JLabel.RIGHT));
- lblPanel.add(label = new JLabel("First Name :",JLabel.RIGHT));
- lblPanel.add(label = new JLabel("Last Name :",JLabel.RIGHT));
- lblPanel.add(label = new JLabel("Course :",JLabel.RIGHT));
- lblPanel.add(label = new JLabel("Year Level :",JLabel.RIGHT));
- JPanel txtPanel = new JPanel();
- txtPanel.setLayout(new GridLayout(5,1));
- txtPanel.add(idNum = new JTextField(15));
- txtPanel.add(firstName = new JTextField(15));
- txtPanel.add(lastName = new JTextField(15));
- txtPanel.add(course = new JComboBox(listOfCourse));
- txtPanel.add(yearLevel = new JComboBox(levelYear));
- idNum.setHorizontalAlignment(JTextField.CENTER);
- firstName.setHorizontalAlignment(JTextField.CENTER);
- lastName.setHorizontalAlignment(JTextField.CENTER);
- btnPanel.setLayout(new FlowLayout(FlowLayout.CENTER,5,0));
- btnPanel.add(btnAdd = new JButton("Add"));
- btnPanel.add(btnExt = new JButton("Close"));
- txtLblPanel.setLayout(new BoxLayout(txtLblPanel, BoxLayout.LINE_AXIS));
- txtLblPanel.add(lblPanel);
- txtLblPanel.add(Box.createRigidArea(new Dimension(5,5)));
- txtLblPanel.add(txtPanel);
- iconPanel.setLayout(new FlowLayout(FlowLayout.RIGHT,1,1));
- iconPanel.add(lblIcon = new JLabel(new ImageIcon("image/wi0062-32.gif"),JLabel.LEFT));
- iconPanel.setBorder(BorderFactory.createEtchedBorder());
- btnAdd.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e)
- {
- if(!isEmptyTextBox()){
- if(!existIdNum(idNum.getText())){
- addNewStudent();
- message();
- dispose();
- }else{
- JOptionPane.showMessageDialog(dialog,"ID number has already exist.","Message",JOptionPane.ERROR_MESSAGE);
- }
- }
- else{
- JOptionPane.showMessageDialog(dialog,"Please fill up the textbox complete.","Message",JOptionPane.ERROR_MESSAGE);
- }
- }
- });
- btnExt.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e)
- {
- dispose();
- }
- });
- }
- public JPanel getPanel()
- {
- return panel;
- }
- public boolean isEmptyTextBox()
- {
- return(firstName.getText().length() == 0 ||
- lastName.getText().length() == 0 ||
- idNum.getText().length() == 0 ||
- course.getSelectedIndex() == 0 ||
- yearLevel.getSelectedIndex() == 0);
- }
- public void message()
- {
- JOptionPane.showMessageDialog(dialog,"Successfull","Message",JOptionPane.INFORMATION_MESSAGE);
- }
- public void addNewStudent()
- {
- newStudent = new Student(firstName.getText().trim(),
- lastName.getText().trim(),
- Integer.valueOf(idNum.getText().trim()),
- String.valueOf(course.getSelectedItem()),
- String.valueOf(yearLevel.getSelectedItem()));
- list.addLast(newStudent);
- StudentList sl = new StudentList(newStudent,list);
- System.out.println(list.size() - 1);
- sl.setRecord(list.size() - 1);
- Student student = (Student)list.getLast();
- new StudentRecordGUI(true);
- new StudentRecordGUI(list.size());
- new StudentRecordGUI(student.getFirstName(),
- student.getLastName(),
- student.getIdNum(),
- student.getCourse(),
- student.getYearLevel());
- }
- public boolean existIdNum(String idNumber)
- {
- boolean found = false;
- StudentList s = new StudentList();
- for(int i = 0; i < list.size(); i++)
- {
- Student id = (Student)s.getList().get(i);
- if(Integer.valueOf(idNumber).equals(id.getIdNum()))
- {
- found = true;
- break;
- }
- }
- return found;
- }
- public void dispose()
- {
- dialog.setVisible(false);
- dialog.dispose();
- }
- }
- ---------------------------------------------------------------------------
- /*
- * Name Ryan Nilo Ybañez
- * Course BSCS - IV
- * Subject Data Structure java implemented
- *
- **/
- import java.awt.event.*;
- import javax.swing.*;
- public class Next extends AbstractAction
- {
- StudentList studentList = new StudentList();
- private int size;
- public Next(String command,ImageIcon icon)
- {
- super(command,icon);
- }
- public void actionPerformed(ActionEvent event)
- {
- try{
- if(studentList.getRecord() < studentList.getSize())
- {
- int i = studentList.getRecord();
- Student student = (Student)studentList.getList().get(i + 1);
- studentList.setRecord(++i);
- new StudentRecordGUI(1 + i);
- new StudentRecordGUI(student.getFirstName(),
- student.getLastName(),
- student.getIdNum(),
- student.getCourse(),
- student.getYearLevel());
- }
- }
- catch(Exception e)
- {}
- }
- }
- -------------------------------------------------------------------------------
- public class Node
- {
- private Object data;
- private Node next;
- public Node()
- {
- data = null;
- next = null;
- }
- public Node(Object data)
- {
- this.data = data;
- }
- public Node(Object data,Node next)
- {
- this.data = data;
- this.next = next;
- }
- public void setNext(Node n)
- {
- next = n;
- }
- public Node getNext()
- {
- return next;
- }
- public Object getData()
- {
- return data;
- }
- }
- --------------------------------------------------------------------------------
- /*
- * Name Ryan Nilo Ybañez
- * Course BSCS - IV
- * Subject Data Structure java implemented
- *
- **/
- public class Person
- {
- private String fName;
- private String lName;
- public Person(String firstname, String lastname)
- {
- fName = firstname;
- lName = lastname;
- }
- public void setFirstName(String firstname)
- {
- fName = firstname;
- }
- public void setLastName(String lastname)
- {
- lName = lastname;
- }
- public String getFirstName()
- {
- return fName;
- }
- public String getLastName()
- {
- return lName;
- }
- }
- -------------------------------------------------------------------------
- /*
- * Name Ryan Nilo Ybañez
- * Course BSCS - IV
- * Subject Data Structure java implemented
- *
- **/
- import java.awt.event.*;
- import javax.swing.*;
- public class Prev extends AbstractAction
- {
- StudentList studentList = new StudentList();
- public Prev(String command,ImageIcon icon)
- {
- super(command,icon);
- }
- public void actionPerformed(ActionEvent event)
- {
- try
- {
- prevStudentRecord();
- }
- catch(Exception e)
- {}
- }
- public void prevStudentRecord()
- {
- if(studentList.getRecord() != 0)
- {
- int i = studentList.getRecord();
- Student student = (Student)studentList.getList().get(i - 1);
- studentList.setRecord(--i);
- new StudentRecordGUI(i + 1);
- new StudentRecordGUI(student.getFirstName(),
- student.getLastName(),
- student.getIdNum(),
- student.getCourse(),
- student.getYearLevel());
- }
- }
- }
- -----------------------------------------------------------------------------
- /*
- * Name Ryan Nilo Ybañez
- * Course BSCS - IV
- * Subject Data Structure java implemented
- *
- **/
- import java.awt.event.*;
- import javax.swing.*;
- public class Search extends AbstractAction
- {
- private StudentList studentList = new StudentList();
- private JFrame frame;
- private JOptionPane dialog;
- public Search(String commandAction,JFrame frame)
- {
- super(commandAction);
- this.frame = frame;
- }
- public void actionPerformed(ActionEvent event)
- {
- Object[] search = {"ID #","FirstName","LastName"};
- String s = (String)dialog.showInputDialog(
- frame,
- "Search By:",
- "Search",
- JOptionPane.PLAIN_MESSAGE,
- null,
- search,
- "ID #");
- if(s == "ID #")
- {
- boolean foundID = false;
- String id = JOptionPane.showInputDialog(
- frame,
- "Search " + s +":",
- "Search",
- JOptionPane.PLAIN_MESSAGE);
- if(id != null && id.length() != 0){
- for(int i = 0; i < studentList.getSize(); i++){
- Student student = (Student)studentList.getList().get(i);
- if(Integer.valueOf(id).equals(student.getIdNum())){
- studentList(student,i);
- foundID = true;
- break;
- }
- }
- if(foundID == false)
- {
- JOptionPane.showMessageDialog(frame,
- "Searching,"+" " + id +" "+"does not exist.",
- "Search",
- JOptionPane.ERROR_MESSAGE);
- }
- }
- }
- else if(s == "FirstName")
- {
- boolean foundFirstName = false;
- String firstname = (String)JOptionPane.showInputDialog(
- frame,
- "Search " + s +":",
- "Search",
- JOptionPane.PLAIN_MESSAGE);
- if(firstname != null && firstname.length() != 0){
- for(int i = 0; i < studentList.getSize(); i++){
- Student student = (Student)studentList.getList().get(i);
- if(firstname.equals(student.getFirstName())){
- studentList(student,i);
- foundFirstName = true;
- break;
- }
- }
- if(foundFirstName == false)
- {
- JOptionPane.showMessageDialog(frame,
- "Searching,"+" " + firstname +" "+"does not exist.",
- "Search",
- JOptionPane.ERROR_MESSAGE);
- }
- }
- }
- else if(s == "LastName")
- {
- boolean foundLastName = false;
- String lastname = JOptionPane.showInputDialog(
- frame,
- "Search " + s +":",
- "Search",
- JOptionPane.PLAIN_MESSAGE);
- if(lastname != null && lastname.length() != 0){
- for(int i = 0; i < studentList.getSize(); i++){
- Student student = (Student)studentList.getList().get(i);
- if(lastname.equals(student.getLastName())){
- studentList(student,i);
- foundLastName = true;
- break;
- }
- }
- if(foundLastName == false)
- {
- JOptionPane.showMessageDialog(frame,
- "Searching,"+" " + lastname +" "+"does not exist.",
- "Search",
- JOptionPane.ERROR_MESSAGE);
- }
- }
- }
- }
- public void studentList(Student student,int index)
- {
- student = (Student)studentList.getList().get(index);
- studentList.setRecord(index);
- new StudentRecordGUI(studentList.getRecord() + 1);
- new StudentRecordGUI(student.getFirstName(),
- student.getLastName(),
- student.getIdNum(),
- student.getCourse(),
- student.getYearLevel());
- }
- }
- ------------------------------------------------------------------------------
- /*
- * Name Ryan Nilo Ybañez
- * Course BSCS - IV
- * Subject Data Structure java implemented
- *
- **/
- public class Student extends Person
- {
- private Integer id;
- private String course;
- private String level;
- public Student(String firstname, String lastname, Integer id, String course, String level)
- {
- super(firstname,lastname);
- this.id = id;
- this.course = course;
- this.level = level;
- }
- public void setId(Integer id)
- {
- this.id = id;
- }
- public void SetCourse(String course)
- {
- this.course = course;
- }
- public void setLevel(String level)
- {
- this.level = level;
- }
- public Integer getIdNum()
- {
- return id;
- }
- public String getCourse()
- {
- return course;
- }
- public String getYearLevel()
- {
- return level;
- }
- }
- --------------------------------------------------------------------------
- /*
- * Name Ryan Nilo Ybañez
- * Course BSCS - IV
- * Subject Data Structure java implemented
- *
- **/
- import java.util.*;
- public class StudentList
- {
- static Student student = null;
- static LinkedList list = null;
- static int record;
- public StudentList()
- {}
- public StudentList(Student student,LinkedList list)
- {
- this.student = student;
- this.list = list;
- }
- public Student getStudentList()
- {
- return student;
- }
- public void setRecord(int n)
- {
- record = n;
- }
- public int getRecord()
- {
- return record;
- }
- public LinkedList getList()
- {
- return list;
- }
- public static int getSize()
- {
- return list.size();
- }
- }
- --------------------------------------------------------------------------------
- /*
- * Name Ryan Nilo Ybañez
- *
- **/
- import java.util.*;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- import javax.swing.border.*;
- public class StudentRecordGUI extends JPanel
- {
- static private final int BUTTON_INDEX = 8;
- static private JFrame frame;
- static private JTextField firstName, lastName, idNum, course, yearLevel;
- static private JLabel numRecord;
- static private JButton[] button = new JButton[BUTTON_INDEX];
- private JPanel mainPanel, iconPanel,txtLblPanel;
- private JPanel symPanel, comPanel;
- private JLabel label, lblIcon;
- private JDialog dialog;
- private JButton btnCount;
- private Action add,delete,search,edit,first,last,prev,next,count;
- public StudentRecordGUI(JFrame frame)
- {
- add = new Add("Add",frame);
- delete = new Delete("Delete",frame);
- search = new Search("Search",frame);
- edit = new Edit("Edit",frame);
- first = new First(null,new ImageIcon("image/first.gif"));
- last = new Last(null, new ImageIcon("image/last.gif"));
- prev = new Prev(null, new ImageIcon("image/prev.gif"));
- next = new Next(null, new ImageIcon("image/next.gif"));
- setLayout(new BorderLayout());
- setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
- JToolBar toolBar = new JToolBar("ToolBar");
- toolBar.setFloatable(false);
- toolBar.setRollover(true);
- txtLblPanel = new JPanel();
- iconPanel = new JPanel();
- symPanel = new JPanel();
- comPanel = new JPanel();
- toolBar.add(button[0] = new JButton(first));
- toolBar.add(button[1] = new JButton(prev));
- toolBar.add(button[2] = new JButton(next));
- toolBar.add(button[3] = new JButton(last));
- toolBar.addSeparator();
- toolBar.add(numRecord = new JLabel("Record #: 0"));
- button[4] = new JButton(add);
- button[5] = new JButton(edit);
- button[6] = new JButton(search);
- button[7] = new JButton(delete);
- button[5].setEnabled(false);
- button[6].setEnabled(false);
- button[7].setEnabled(false);
- button[4].setPreferredSize(new Dimension(80,26));
- button[5].setPreferredSize(new Dimension(80,26));
- button[6].setPreferredSize(new Dimension(80,26));
- button[7].setPreferredSize(new Dimension(80,26));
- button[0].setToolTipText("First");
- button[1].setToolTipText("Previous");
- button[2].setToolTipText("Next");
- button[3].setToolTipText("Last");
- addLayout();
- mainPanel = new JPanel();
- mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));
- mainPanel.setBorder(BorderFactory.createCompoundBorder(
- BorderFactory.createTitledBorder("Student Information"),
- BorderFactory.createEmptyBorder(5,5,5,5)));
- mainPanel.add(txtLblPanel);
- JPanel layout = new JPanel();
- layout.setLayout(new BoxLayout(layout, BoxLayout.PAGE_AXIS));
- layout.add(Box.createRigidArea(new Dimension(5,5)));
- layout.add(iconPanel);
- layout.add(Box.createRigidArea(new Dimension(5,5)));
- layout.add(mainPanel);
- layout.add(Box.createRigidArea(new Dimension(5,5)));
- layout.add(comPanel);
- add(toolBar, BorderLayout.PAGE_START);
- add(layout, BorderLayout.PAGE_END);
- }
- public StudentRecordGUI(boolean tF)
- {
- button[5].setEnabled(tF);
- button[6].setEnabled(tF);
- button[7].setEnabled(tF);
- }
- public StudentRecordGUI(int n)
- {
- numRecord.setText("Record #: " + String.valueOf(n));
- }
- public StudentRecordGUI(String firstname, String lastname, Integer num, String c, String yearlevel)
- {
- idNum.setText(String.valueOf(num));
- firstName.setText(firstname);
- lastName.setText(lastname);
- course.setText(c);
- yearLevel.setText(yearlevel);
- }
- public void addLayout()
- {
- JPanel lblPanel = new JPanel();
- lblPanel.setLayout(new GridLayout(5,1,25,5));
- lblPanel.add(label = new JLabel("Student Id :",JLabel.RIGHT));
- lblPanel.add(label = new JLabel("First Name :",JLabel.RIGHT));
- lblPanel.add(label = new JLabel("Last Name :",JLabel.RIGHT));
- lblPanel.add(label = new JLabel("Course :",JLabel.RIGHT));
- lblPanel.add(label = new JLabel("Year Level :",JLabel.RIGHT));
- JPanel txtPanel = new JPanel();
- txtPanel.setLayout(new GridLayout(5,1,25,0));
- txtPanel.add(idNum = new JTextField(25));
- txtPanel.add(firstName = new JTextField(25));
- txtPanel.add(lastName = new JTextField(25));
- txtPanel.add(course = new JTextField(25));
- txtPanel.add(yearLevel = new JTextField(25));
- idNum.setHorizontalAlignment(JTextField.CENTER);
- firstName.setHorizontalAlignment(JTextField.CENTER);
- lastName.setHorizontalAlignment(JTextField.CENTER);
- course.setHorizontalAlignment(JTextField.CENTER);
- yearLevel.setHorizontalAlignment(JTextField.CENTER);
- idNum.setFocusable(false);
- firstName.setFocusable(false);
- lastName.setFocusable(false);
- course.setFocusable(false);
- yearLevel.setFocusable(false);
- txtLblPanel.setLayout(new BoxLayout(txtLblPanel, BoxLayout.LINE_AXIS));
- txtLblPanel.add(lblPanel);
- txtLblPanel.add(Box.createRigidArea(new Dimension(5,5)));
- txtLblPanel.add(txtPanel);
- txtLblPanel.setPreferredSize(new Dimension(350,130));
- comPanel.setLayout(new FlowLayout(FlowLayout.CENTER,5,0));
- for(int i = 4; i < button.length; i++){
- comPanel.add(button[i]);
- button[i].setFont(new Font("sans-serif",Font.PLAIN,10));
- }
- iconPanel.setLayout(new FlowLayout(FlowLayout.RIGHT,1,1));
- iconPanel.add(lblIcon = new JLabel(new ImageIcon("image/wi0054-32.gif")));
- iconPanel.setBorder(BorderFactory.createEtchedBorder());
- }
- public static void createAndShowGUI()
- {
- JFrame frame = new JFrame("Student Record");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setContentPane(new StudentRecordGUI(frame));
- frame.pack();
- frame.setVisible(true);
- frame.setResizable(false);
- }
- public static void main(String[] args)
- {
- Runnable doRun = new Runnable(){
- public void run(){
- createAndShowGUI();
- }
- };
- javax.swing.SwingUtilities.invokeLater(doRun);
- }
- }
- --------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment