0% found this document useful (0 votes)
46 views33 pages

Ryan

This document defines an enrollment system with a graphical user interface using Java Swing. It includes multiple frames for different screens like the main menu, enrollment menu, student menu, subject menu, and edit subject menu. It uses classes, methods, variables and handlers to populate the frames with labels, text fields, buttons, checkboxes and more to allow users to enroll students in subjects. Object-oriented programming principles are applied, with classes created to handle button clicks and pass data between frames as the user progresses through the enrollment process.

Uploaded by

Thaed Nyar Eton
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views33 pages

Ryan

This document defines an enrollment system with a graphical user interface using Java Swing. It includes multiple frames for different screens like the main menu, enrollment menu, student menu, subject menu, and edit subject menu. It uses classes, methods, variables and handlers to populate the frames with labels, text fields, buttons, checkboxes and more to allow users to enroll students in subjects. Object-oriented programming principles are applied, with classes created to handle button clicks and pass data between frames as the user progresses through the enrollment process.

Uploaded by

Thaed Nyar Eton
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 33

import javax.swing.

*;

import java.awt.*;

import java.awt.event.*;

public class EnrollmentSystem extends JFrame implements ItemListener

JFrame win1 = new JFrame("Enroll");

JFrame win2 = new JFrame("Student" );

JFrame win3 = new JFrame("Subject" );

JFrame win4 = new JFrame("Choose Subject");

JFrame win5 = new JFrame("Finish");

JFrame win6 = new JFrame("Edit Subject");

//main menu

private JLabel textL;

private JButton enterB, exitB;

private EnterButtonHandler enterHandler;

private ExitButtonHandler exitHandler;

private static final int WIDTH = 450;

private static final int HEIGHT = 400;

//enroll menu

private JLabel text1L;


private JButton studentB, subjectB, backB;

private StudentButtonHandler studHandler;

private SubjectButtonHandler subHandler;

private BackButtonHandler backHandler;

//student menu

private JComboBox course, year;

private JLabel text2L, text3L, text5L, nameL, idL, yearL;

private JTextField nameTF, idTF;

private JButton okB, cancelB;

private OkButtonHandler okHandler;

private CancelButtonHandler cancelHandler;

private String years[] = {"","1","2","3","4"}, Year;

private String courses[] = {"","BSIT","BSN"}, Course;

//subject menu

private JLabel text4L;

private JButton editB,retB;

private EditButtonHandler editHandler;

private RetButtonHandler retHandler;


//enroll subject menu

private JLabel text7L;

private JCheckBox subject[]= new JCheckBox[7];

private JButton enrollB;

private EnrollButtonHandler enrollHandler;

//display student info with subjects

private JLabel congrats;

private JTextArea info;

private JButton doneB, newB;

private NewButtonHandler newHandler;

private DoneButtonHandler doneHandler;

//edit subject menu

private JLabel text8L;

private JCheckBox subjectAdd[]= new JCheckBox[7];

private JButton addS, backS;

private AddSButtonHandler addSHandler;

private BackSButtonHandler backSHandler;

//initializations

private int xD=0;


private String student, nameStud, idStud, courseStud, yearStud;

private int row=10;

private int col=20;

private int a=0, b=0, c=0, d=0, e=0, f=0, g=0;

private int[] w = new int[7];

private int[] x = new int[7];

private int[] y = new int[7];

private String stringSub[]= {"","","","","","",""};

private String stringSubAdd[]= {"","","","","","",""};

public EnrollmentSystem()

mainMenu();

public static void main(String[] args)

EnrollmentSystem enrollSystemObject = new EnrollmentSystem();

public void mainMenu()

textL = new JLabel("Colegio de Dagupan", SwingConstants.CENTER);


enterB = new JButton("Enroll");

enterHandler = new EnterButtonHandler();

enterB.addActionListener(enterHandler);

exitB = new JButton("Exit");

exitHandler = new ExitButtonHandler();

exitB.addActionListener(exitHandler);

setTitle("Enrollment System");

Container pane = getContentPane();

pane.setLayout(new GridLayout(3,1));

pane.add(textL);

pane.add(enterB);

pane.add(exitB);

setLocation(200,200);

setSize(WIDTH, HEIGHT);

setVisible(true);

setDefaultCloseOperation(EXIT_ON_CLOSE);

public class EnterButtonHandler implements ActionListener

{
public void actionPerformed(ActionEvent z)

setVisible(false);

if (a <=0)

enrollMenu();

a++;

else win1.setVisible(true);

public class ExitButtonHandler implements ActionListener

public void actionPerformed(ActionEvent z)

System.exit(0);

public void enrollMenu()

text1L = new JLabel("Please choose by clicking the buttons below.",


SwingConstants.CENTER);

studentB = new JButton("Student");


studHandler = new StudentButtonHandler();

studentB.addActionListener(studHandler);

subjectB = new JButton("Subject");

subHandler = new SubjectButtonHandler();

subjectB.addActionListener(subHandler);

backB = new JButton("Back");

backHandler = new BackButtonHandler();

backB.addActionListener(backHandler);

win1.setTitle("Enroll");

Container pane1 = win1.getContentPane();

pane1.setLayout(new GridLayout(4,1));

pane1.add(text1L);

pane1.add(studentB);

pane1.add(subjectB);

pane1.add(backB);

win1.setLocation(300,250);

win1.setSize(400, 200);

win1.setVisible(true);

win1.setDefaultCloseOperation(EXIT_ON_CLOSE);

}
public class StudentButtonHandler implements ActionListener

public void actionPerformed(ActionEvent z)

win1.setVisible(false);

if (b <=0)

studMenu();

b++;

else win2.setVisible(true);

public class SubjectButtonHandler implements ActionListener

public void actionPerformed(ActionEvent z)

if(xD != 0)

win1.setVisible(false);

if (c <=0)

subMenu();
c++;

else win3.setVisible(true);

else JOptionPane.showMessageDialog(null,"There are no student enrolled!");

public class BackButtonHandler implements ActionListener

public void actionPerformed(ActionEvent z)

setVisible(true);

win1.setVisible(false);

public void studMenu()

text2L = new JLabel("Enter ",SwingConstants.RIGHT);

text3L = new JLabel("Information",SwingConstants.LEFT);

text5L = new JLabel("Course",SwingConstants.RIGHT);

nameL = new JLabel("Name: ", SwingConstants.RIGHT);

idL = new JLabel("Student ID Number: ", SwingConstants.RIGHT);

yearL = new JLabel("Year: ", SwingConstants.RIGHT);


course = new JComboBox(courses);

course.setMaximumRowCount(3);

course.addItemListener(this);

year = new JComboBox(years);

year.setMaximumRowCount(5);

year.addItemListener(this);

nameTF = new JTextField(30);

idTF = new JTextField(7);

okB = new JButton("Ok");

okHandler = new OkButtonHandler();

okB.addActionListener(okHandler);

cancelB = new JButton("Cancel");

cancelHandler = new CancelButtonHandler();

cancelB.addActionListener(cancelHandler);

win2.setTitle("Student");

Container pane2 = win2.getContentPane();

pane2.setLayout(new GridLayout(6,2));

pane2.add(text2L);

pane2.add(text3L);

pane2.add(nameL);
pane2.add(nameTF);

pane2.add(idL);

pane2.add(idTF);

pane2.add(text5L);

pane2.add(course);

pane2.add(yearL);

pane2.add(year);

pane2.add(okB);

pane2.add(cancelB);

win2.setLocation(300,250);

win2.setSize(400, 200);

win2.setVisible(true);

win2.setDefaultCloseOperation(EXIT_ON_CLOSE);

public class OkButtonHandler implements ActionListener

public void actionPerformed(ActionEvent z)

if(course.getSelectedIndex() != 0 && year.getSelectedIndex() != 0)

win2.setVisible(false);

if (d <=0)

{
addSubject();

d++;

else win4.setVisible(true);

public class CancelButtonHandler implements ActionListener

public void actionPerformed(ActionEvent z)

win1.setVisible(true);

win2.setVisible(false);

public void subMenu()

text4L = new JLabel("Please choose by clicking the buttons below.",


SwingConstants.CENTER);

editB = new JButton("Edit");

editHandler = new EditButtonHandler();

editB.addActionListener(editHandler);
retB = new JButton("Back");

retHandler = new RetButtonHandler();

retB.addActionListener(retHandler);

win3.setTitle("Subject");

Container pane3 = win3.getContentPane();

pane3.setLayout(new GridLayout(3,1));

pane3.add(text4L);

pane3.add(editB);

pane3.add(retB);

win3.setLocation(300,250);

win3.setSize(400, 200);

win3.setVisible(true);

win3.setDefaultCloseOperation(EXIT_ON_CLOSE);

public class EditButtonHandler implements ActionListener

public void actionPerformed(ActionEvent z)

win3.setVisible(false);

if (f <=0)

{
addMenu();

f++;

else win6.setVisible(true);

for(int z1=0; z1<=6; z1++)

if(w[z1]==1)

subjectAdd[z1].setSelected(true);

public class RetButtonHandler implements ActionListener

public void actionPerformed(ActionEvent z)

win1.setVisible(true);

win3.setVisible(false);

public void addSubject()


{

text7L = new JLabel("Choose Subjects to be Enrolled", SwingConstants.CENTER);

subject[0] = new JCheckBox("211D06 MODERN COMMUNICATION 3.0


11:00a-12:00p MWF V-305");

subject[0].addItemListener(this);

subject[1] = new JCheckBox("212D06 INSTALLATION OF COMPUTER SYS 3.0


02:00p-05:00p W V-401");

subject[1].addItemListener(this);

subject[2] = new JCheckBox("214D06 ENVIRONMENTAL SCIENCE 3.0


02:30p-04:00p TTh V-305");

subject[2].addItemListener(this);

subject[3] = new JCheckBox("215D06 PGBSA/PGSLAT SA IBAT IBNG DISP 3.0


04:00p-05:30p TTh V-202");

subject[3].addItemListener(this);

subject[4] = new JCheckBox("216D06 ANALYTIC GEOMETRY W/ CALCULUS 3.0


12:00a-01:00p MWF V-304");

subject[4].addItemListener(this);

subject[5] = new JCheckBox("217D06 RECREATIONAL ACTIVITIES 2.0


02:00p-04:00p F RT-3");

subject[5].addItemListener(this);

subject[6] = new JCheckBox("218D06 COMPUTER SYSTEM ORGANIZATION 3.0


01:00p-02:00p MWF V-304");

subject[6].addItemListener(this);

enrollB = new JButton("Enroll");

enrollHandler = new EnrollButtonHandler();

enrollB.addActionListener(enrollHandler);
win4.setTitle("Enroll Subject");

Container pane4 = win4.getContentPane();

pane4.setLayout(new GridLayout(9,1));

pane4.add(text7L);

pane4.add(subject[0]);

pane4.add(subject[1]);

pane4.add(subject[2]);

pane4.add(subject[3]);

pane4.add(subject[4]);

pane4.add(subject[5]);

pane4.add(subject[6]);

pane4.add(enrollB);

win4.setLocation(300,250);

win4.setSize(600, 400);

win4.setVisible(true);

win4.setDefaultCloseOperation(EXIT_ON_CLOSE);

public class EnrollButtonHandler implements ActionListener

public void actionPerformed(ActionEvent z)

{
xD++;

win4.setVisible(false);

if (e <=0)

studInfo();

e++;

else win5.setVisible(true);

for(int z2=0; z2<=6; z2++)

w[z2]=x[z2];

nameStud = nameTF.getText();

idStud = idTF.getText();

courseStud = Course;

yearStud = Year;

info.append("Name: "+nameTF.getText()+"\n");

info.append("ID Number: "+idTF.getText()+"\n");

info.append("Course: "+Course+"\n");

info.append("Year: "+Year+"\n");

info.append("\n");

info.append(" Code Description Units Time


Days Room\n");
for(int z4=0; z4<=6; z4++)

if(x[z4]==1)

info.append(stringSub[z4]+"\n");

public void studInfo()

congrats = new JLabel("Congratulations!",SwingConstants.CENTER);

info = new JTextArea(row,col);

info.setEditable(false);

newB = new JButton("New");

newHandler = new NewButtonHandler();

newB.addActionListener(newHandler);

doneB = new JButton("Done");

doneHandler = new DoneButtonHandler();

doneB.addActionListener(doneHandler);
win5.setTitle("Enrolled");

Container pane5 = win5.getContentPane();

pane5.setLayout(null);

congrats.setLocation(180,0);

info.setLocation(10,30);

newB.setLocation(120,280);

doneB.setLocation(370,280);

congrats.setSize(200,30);

info.setSize(555,245);

newB.setSize(80,30);

doneB.setSize(80,30);

pane5.add(congrats);

pane5.add(info);

pane5.add(newB);

pane5.add(doneB);

win5.setLocation(300,250);

win5.setSize(590, 350);

win5.setVisible(true);

win5.setDefaultCloseOperation(EXIT_ON_CLOSE);

}
public class NewButtonHandler implements ActionListener

public void actionPerformed(ActionEvent z)

student = info.getText();

win5.setVisible(false);

if (b <=0)

studMenu();

b++;

else win2.setVisible(true);

info.setText("");

nameTF.setText("");

idTF.setText("");

course.setSelectedIndex(0);

year.setSelectedIndex(0);

for(int z5=0; z5<=6; z5++)

subject[z5].setSelected(false);

}
public class DoneButtonHandler implements ActionListener

public void actionPerformed(ActionEvent z)

student = info.getText();

win5.setVisible(false);

setVisible(true);

info.setText("");

nameTF.setText("");

idTF.setText("");

course.setSelectedIndex(0);

year.setSelectedIndex(0);

for(int z6=0; z6<=6; z6++)

subject[z6].setSelected(false);

public void addMenu()

text8L = new JLabel("Choose subjectAdds to be Added", SwingConstants.CENTER);

subjectAdd[0] = new JCheckBox("211D06 MODERN COMMUNICATION 3.0


11:00a-12:00p MWF V-305");

subjectAdd[0].addItemListener(this);
subjectAdd[1] = new JCheckBox("212D06 INSTALLATION OF COMPUTER SYS 3.0
02:00p-05:00p W V-401");

subjectAdd[1].addItemListener(this);

subjectAdd[2] = new JCheckBox("214D06 ENVIRONMENTAL SCIENCE 3.0


02:30p-04:00p TTh V-305");

subjectAdd[2].addItemListener(this);

subjectAdd[3] = new JCheckBox("215D06 PGBSA/PGSLAT SA IBAT IBNG DISP 3.0


04:00p-05:30p TTh V-202");

subjectAdd[3].addItemListener(this);

subjectAdd[4] = new JCheckBox("216D06 ANALYTIC GEOMETRY W/ CALCULUS 3.0


12:00a-01:00p MWF V-304");

subjectAdd[4].addItemListener(this);

subjectAdd[5] = new JCheckBox("217D06 RECREATIONAL ACTIVITIES 2.0


02:00p-04:00p F RT-3");

subjectAdd[5].addItemListener(this);

subjectAdd[6] = new JCheckBox("218D06 COMPUTER SYSTEM ORGANIZATION 3.0


01:00p-02:00p MWF V-304");

subjectAdd[6].addItemListener(this);

addS = new JButton("Add");

addSHandler = new AddSButtonHandler();

addS.addActionListener(addSHandler);

backS = new JButton("Back");

backSHandler = new BackSButtonHandler();

backS.addActionListener(backSHandler);
win6.setTitle("Add/Delete Subject");

Container pane6 = win6.getContentPane();

pane6.setLayout(new GridLayout(10,1));

pane6.add(text8L);

pane6.add(subjectAdd[0]);

pane6.add(subjectAdd[1]);

pane6.add(subjectAdd[2]);

pane6.add(subjectAdd[3]);

pane6.add(subjectAdd[4]);

pane6.add(subjectAdd[5]);

pane6.add(subjectAdd[6]);

pane6.add(addS);

pane6.add(backS);

win6.setLocation(300,250);

win6.setSize(600, 400);

win6.setVisible(true);

win6.setDefaultCloseOperation(EXIT_ON_CLOSE);

public class AddSButtonHandler implements ActionListener

public void actionPerformed(ActionEvent z)

{
win6.setVisible(false);

if (e <=0)

studInfo();

e++;

else win5.setVisible(true);

info.append("Name: "+nameStud+"\n");

info.append("ID Number: "+idStud+"\n");

info.append("Course: "+courseStud+"\n");

info.append("Year: "+yearStud+"\n");

info.append("\n");

info.append(" Code Description Units Time


Days Room\n");

for(int z10=0; z10<=6; z10++)

if(w[z10]==1)

info.append(stringSubAdd[z10]+"\n");

public class BackSButtonHandler implements ActionListener


{

public void actionPerformed(ActionEvent z)

win3.setVisible(true);

win6.setVisible(false);

info.setText("");

nameTF.setText("");

idTF.setText("");

course.setSelectedIndex(0);

year.setSelectedIndex(0);

for(int z9=0; z9<=6; z9++)

subject[z9].setSelected(false);

public void itemStateChanged(ItemEvent i)

if(i.getSource() == course)

Course = courses[course.getSelectedIndex()];

if(i.getSource() == year)

{
Year = years[year.getSelectedIndex()];

if(i.getSource() == subject[0])

if(i.getStateChange() == ItemEvent.SELECTED)

x[0]=1;

stringSub[0] = "211D06 MODERN COMMUNICATION 3.0 11:00a-


12:00p MWF V-305";

if(i.getStateChange() == ItemEvent.DESELECTED)

x[0]=0;

stringSub[0] = "";

if(i.getSource() == subject[1])

if(i.getStateChange() == ItemEvent.SELECTED)

x[1]=1;

stringSub[1] = "212D06 INSTALLATION OF COMPUTER SYS 3.0 02:00p-


05:00p W V-401";

if(i.getStateChange() == ItemEvent.DESELECTED)

{
x[1]=0;

stringSub[1] = "";

if(i.getSource() == subject[2])

if(i.getStateChange() == ItemEvent.SELECTED)

x[2]=1;

stringSub[2] = "214D06 ENVIRONMENTAL SCIENCE 3.0 02:30p-


04:00p TTh V-305";

if(i.getStateChange() == ItemEvent.DESELECTED)

x[2]=0;

stringSub[2] = "";

if(i.getSource() == subject[3])

if(i.getStateChange() == ItemEvent.SELECTED)

x[3]=1;

stringSub[3] = "215D06 PGBSA/PGSLAT SA IBAT IBNG DISP 3.0 04:00p-


05:30p TTh V-202";

}
if(i.getStateChange() == ItemEvent.DESELECTED)

x[3]=0;

stringSub[3] = "";

if(i.getSource() == subject[4])

if(i.getStateChange() == ItemEvent.SELECTED)

x[4]=1;

stringSub[4] = "216D06 ANALYTIC GEOMETRY W/ CALCULUS 3.0 12:00a-


01:00p MWF V-304";

if(i.getStateChange() == ItemEvent.DESELECTED)

x[4]=0;

stringSub[4] = "";

if(i.getSource() == subject[5])

if(i.getStateChange() == ItemEvent.SELECTED)

x[5]=1;
stringSub[5] = "217D06 RECREATIONAL ACTIVITIES 2.0 02:00p-
04:00p F RT-3";

if(i.getStateChange() == ItemEvent.DESELECTED)

x[5]=0;

stringSub[5] = "";

if(i.getSource() == subject[6])

if(i.getStateChange() == ItemEvent.SELECTED)

x[6]=1;

stringSub[6] = "218D06 COMPUTER SYSTEM ORGANIZATION 3.0 01:00p-


02:00p MWF V-304";

if(i.getStateChange() == ItemEvent.DESELECTED)

x[6]=0;

stringSub[6] = "";

if(i.getSource() == subjectAdd[0])

if(i.getStateChange() == ItemEvent.SELECTED)
{

w[0]=1;

stringSubAdd[0] = "211D06 MODERN COMMUNICATION 3.0


11:00a-12:00p MWF V-305";

if(i.getStateChange() == ItemEvent.DESELECTED)

w[0]=0;

stringSubAdd[0] = "";

if(i.getSource() == subjectAdd[1])

if(i.getStateChange() == ItemEvent.SELECTED)

w[1]=1;

stringSubAdd[1] = "212D06 INSTALLATION OF COMPUTER SYS 3.0 02:00p-


05:00p W V-401";

if(i.getStateChange() == ItemEvent.DESELECTED)

w[1]=0;

stringSubAdd[1] = "";

if(i.getSource() == subjectAdd[2])
{

if(i.getStateChange() == ItemEvent.SELECTED)

w[2]=1;

stringSubAdd[2] = "214D06 ENVIRONMENTAL SCIENCE 3.0 02:30p-


04:00p TTh V-305";

if(i.getStateChange() == ItemEvent.DESELECTED)

w[2]=0;

stringSubAdd[2] = "";

if(i.getSource() == subjectAdd[3])

if(i.getStateChange() == ItemEvent.SELECTED)

w[3]=1;

stringSubAdd[3] = "215D06 PGBSA/PGSLAT SA IBAT IBNG DISP 3.0 04:00p-


05:30p TTh V-202";

if(i.getStateChange() == ItemEvent.DESELECTED)

w[3]=0;

stringSubAdd[3] = "";

}
}

if(i.getSource() == subjectAdd[4])

if(i.getStateChange() == ItemEvent.SELECTED)

w[4]=1;

stringSubAdd[4] = "216D06 ANALYTIC GEOMETRY W/ CALCULUS 3.0 12:00a-


01:00p MWF V-304";

if(i.getStateChange() == ItemEvent.DESELECTED)

w[4]=0;

stringSubAdd[4] = "";

if(i.getSource() == subjectAdd[5])

if(i.getStateChange() == ItemEvent.SELECTED)

w[5]=1;

stringSubAdd[5] = "217D06 RECREATIONAL ACTIVITIES 2.0 02:00p-


04:00p F RT-3";

if(i.getStateChange() == ItemEvent.DESELECTED)

w[5]=0;
stringSubAdd[5] = "";

if(i.getSource() == subjectAdd[6])

if(i.getStateChange() == ItemEvent.SELECTED)

w[6]=1;

stringSubAdd[6] = "218D06 COMPUTER SYSTEM ORGANIZATION 3.0


01:00p-02:00p MWF V-304";

if(i.getStateChange() == ItemEvent.DESELECTED)

w[6]=0;

stringSubAdd[6] = "";

You might also like