Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- import java.sql.*;
- import javax.swing.*;
- /**
- *
- * @author Aniket
- */
- public class PrefApp extends javax.swing.JApplet {
- DefaultListModel<String> list=new DefaultListModel<>(); //holds items(preferences) in Preference List displayed in applet
- public static String collegeName[]=new String[100];//holds the college name according to preference list made
- public static String courseName[]=new String[100]; //holds the course name according to preference list made | works like "Computer Science & Engineering"->"CUTCSE"; for easy usage when querying in database
- public static int count=0; //global var; used by collName[]&courseName[] to prioritise according to internal preference list | [top] of stacks of collegeName & courseName
- public String quota; //holds the CETRank and Quota from database
- public int rank;
- /**
- * Initializes the applet PrefApp
- */
- @Override
- public void init() {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(PrefApp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(PrefApp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(PrefApp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(PrefApp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the applet */
- try {
- java.awt.EventQueue.invokeAndWait(new Runnable() {
- @Override
- public void run() {
- initComponents();
- }
- });
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- /**
- * This method is called from within the init() method to initialize the
- * form. WARNING: Do NOT modify this code. The content of this method is
- * always regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- PageLabel = new javax.swing.JLabel();
- DescTextLabel = new javax.swing.JLabel();
- jScrollPane1 = new javax.swing.JScrollPane();
- CollegeList = new javax.swing.JList<>();
- CollegeLabel = new javax.swing.JLabel();
- CoursesLabel = new javax.swing.JLabel();
- jScrollPane2 = new javax.swing.JScrollPane();
- CoursesList = new javax.swing.JList<>();
- AddButton = new javax.swing.JButton();
- RemoveButton = new javax.swing.JButton();
- UpButton = new javax.swing.JButton();
- DownButton = new javax.swing.JButton();
- NoteLabel = new javax.swing.JLabel();
- jScrollPane3 = new javax.swing.JScrollPane();
- PreferenceList = new javax.swing.JList<>(list);
- PrefListMade = new javax.swing.JLabel();
- SubmitButton = new javax.swing.JButton();
- PageLabel.setFont(new java.awt.Font("Malgun Gothic", 1, 36)); // NOI18N
- PageLabel.setText("PREFERENCE LIST");
- DescTextLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- DescTextLabel.setText("List the College & Courses of your choice according to the admission priority.");
- CollegeList.setModel(new javax.swing.AbstractListModel<String>() {
- String[] strings = { "Amity School of Engineering & Technology, 580, Delhi", "Bhagwan Parshuram Institute of Technology, P.S.P. - 4,Sector - 17, Rohini,Delhi - 110085", "Bharti Vidyapeeth's College of Engineering, A - 4,Paschim Vihar, New Delhi - 110063", "Delhi Technical Campus, 28/1, Knowledge Park - III,Greater NOIDA, UP", "Guru Tegh Bahadur Institute of Technology,G-8 Area, Rajouri Garden, Opp. Swarg Ashram Mandir, Delhi - 110064", "HMR Institute of Technology & Management, Hameed Pur, Delhi - 110036", "JIMS Engineering Management Technical Campus,48/4, Knowledge Park - III, Greater NOIDA", "Maharaja Agrasen Institute of Technology, Sector - 22,Rohini, Delhi - 110085", "Maharaja Surajmal Institute of Technology, C - 4, Janakpuri, New Delhi - 110058", "Mahavir Swami Institute of Technology, Sonepat,Haryana (Minority Institution)", "Northern India Engineering College, FC-26, Shastri Park, Delhi - 110053", "Ambedkar Institute of Advanced Communication Technologies & Research,Geeta Colony, Delhi – 110092", "Ch. Brahm Prakash Govt. Engineering College,Behind Rao Tula Ram Hospital, Jaffarpur, New Delhi - 110073", "Delhi Institute of Tool Engineering, Okhla Industrial Area, Phase - II, Delhi - 20", "G. B. Pant Govt. Engineering College, Okhla Industrial Estate, Phase - III, Okhla, New Delhi - 110020", "National Power Training Institute, Badarpur,New Delhi" };
- public int getSize() { return strings.length; }
- public String getElementAt(int i) { return strings[i]; }
- });
- CollegeList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
- jScrollPane1.setViewportView(CollegeList);
- CollegeLabel.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
- CollegeLabel.setText("Colleges");
- CoursesLabel.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
- CoursesLabel.setText("Courses Available");
- CoursesList.setModel(new javax.swing.AbstractListModel<String>() {
- String[] strings = { "Computer Science & Engineering", "Information Technology", "Electronics & Communication Engineering", "Mechanical & Automation Engineering" };
- public int getSize() { return strings.length; }
- public String getElementAt(int i) { return strings[i]; }
- });
- CoursesList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
- jScrollPane2.setViewportView(CoursesList);
- AddButton.setText("Add");
- AddButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- AddButtonActionPerformed(evt);
- }
- });
- RemoveButton.setText("Remove");
- RemoveButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- RemoveButtonActionPerformed(evt);
- }
- });
- UpButton.setText("Up");
- UpButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- UpButtonActionPerformed(evt);
- }
- });
- DownButton.setText("Down");
- DownButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- DownButtonActionPerformed(evt);
- }
- });
- NoteLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- NoteLabel.setForeground(new java.awt.Color(255, 0, 0));
- NoteLabel.setText("NOTE: Review your admission preferences carefully. Once submitted, they can't be altered!");
- PreferenceList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
- PreferenceList.addContainerListener(new java.awt.event.ContainerAdapter() {
- public void componentAdded(java.awt.event.ContainerEvent evt) {
- PreferenceListComponentAdded(evt);
- }
- });
- jScrollPane3.setViewportView(PreferenceList);
- PrefListMade.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
- PrefListMade.setText("Preferences of Admission");
- SubmitButton.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
- SubmitButton.setText("Submit");
- SubmitButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- SubmitButtonActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(PageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 450, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(DescTextLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 480, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGroup(layout.createSequentialGroup()
- .addComponent(CollegeLabel)
- .addGap(225, 225, 225)
- .addComponent(CoursesLabel)
- .addGap(142, 142, 142)
- .addComponent(PrefListMade))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(20, 20, 20)
- .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
- .addComponent(RemoveButton, javax.swing.GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE)
- .addComponent(DownButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(UpButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(AddButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGap(18, 18, 18)
- .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(layout.createSequentialGroup()
- .addComponent(NoteLabel)
- .addGap(188, 188, 188)
- .addComponent(SubmitButton, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(PageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(10, 10, 10)
- .addComponent(DescTextLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(30, 30, 30)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(CollegeLabel)
- .addComponent(CoursesLabel)
- .addComponent(PrefListMade))
- .addGap(8, 8, 8)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addGroup(layout.createSequentialGroup()
- .addComponent(AddButton)
- .addGap(7, 7, 7)
- .addComponent(RemoveButton)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(UpButton)
- .addGap(7, 7, 7)
- .addComponent(DownButton))
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(20, 20, 20)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(10, 10, 10)
- .addComponent(NoteLabel))
- .addComponent(SubmitButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(0, 10, Short.MAX_VALUE))
- );
- }// </editor-fold>
- private void AddButtonActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- String collSelected=CollegeList.getSelectedValue(); //reads value of selected college in CollegeList
- String courSelected=CoursesList.getSelectedValue(); //reads value of selected course in CoursesList
- /*ADDITION OF PREFERENCE LIST*/
- collegeName[count]=collSelected; //adds name of college to internal priority list
- if(null != courSelected)
- switch (courSelected) { //adds name of course to internal priority list
- case "Computer Science & Engineering":
- courseName[count]="CUTCSE";
- break;
- case "Information Technology":
- courseName[count]="CUTIT";
- break;
- case "Electronics & Communication Engineering":
- courseName[count]="CUTECE";
- break;
- default:
- courseName[count]="CUTMAE";
- break;
- }
- count++; //priority variable
- /*ADDITION OF PREFEENCE LIST*/ //Addition works like push of a stack
- String choice=courSelected+"@"+collSelected; //creats a string for displaying in applet
- list.addElement(choice); //adds to displayed list PreferenceList
- }
- private void PreferenceListComponentAdded(java.awt.event.ContainerEvent evt) {
- // TODO add your handling code here:
- }
- private void RemoveButtonActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- int index=PreferenceList.getSelectedIndex(); //holds position of selected item from PreferenceList to be removed
- for(int i=index;i<count;i++) //removes the selected item at index (selected position) from internal pref list
- {
- collegeName[i]=collegeName[i+1];
- courseName[i]=courseName[i+1];
- }
- count--; //decrease value of 'top' of stacks for further insertion (collegeName & courseName)
- collegeName[count]=null;
- courseName[count]=null;
- list.remove(index); //removes the choihe from Preference List
- }
- private void UpButtonActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- int pos=PreferenceList.getSelectedIndex(); //holds the position of item selected
- int newpos=pos-1; //holds the one above position of selected item
- String tempstring; //temporary string variable for swapping choices
- /*UPDATING INTERNAL LIST*/
- tempstring=collegeName[pos]; //swaps the item stored in internal college priority list
- collegeName[pos]=collegeName[newpos];
- collegeName[newpos]=tempstring;
- tempstring=courseName[pos]; //swaps the item stored in internal course priority list
- courseName[pos]=courseName[newpos];
- courseName[newpos]=tempstring;
- /*UPDATING INTERNAL LIST*/
- /*UPDATING DISPLAY LIST*/
- String spos=PreferenceList.getSelectedValue();
- PreferenceList.setSelectedIndex(newpos);
- String npos=PreferenceList.getSelectedValue();
- list.setElementAt(spos, newpos);
- list.setElementAt(npos, pos);
- /*UPDATING DISPLAY LIST*/
- }
- private void DownButtonActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- int pos=PreferenceList.getSelectedIndex(); //holds the position of item selected
- int newpos=pos+1; //holds the one above position of selected item
- String tempstring; //temporary string variable for swapping choices
- /*UPDATING INTERNAL LIST*/
- tempstring=collegeName[pos]; //swaps the item stored in internal college priority list
- collegeName[pos]=collegeName[newpos];
- collegeName[newpos]=tempstring;
- tempstring=courseName[pos]; //swaps the item stored in internal course priority list
- courseName[pos]=courseName[newpos];
- courseName[newpos]=tempstring;
- /*UPDATING INTERNAL LIST*/
- /*UPDATING DISPLAY LIST*/
- String spos=PreferenceList.getSelectedValue();
- PreferenceList.setSelectedIndex(newpos);
- String npos=PreferenceList.getSelectedValue();
- list.setElementAt(spos, newpos);
- list.setElementAt(npos, pos);
- /*UPDATING DISPLAY LIST*/
- }
- private void SubmitButtonActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- try{
- Connection link=DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb","Aniket","root");
- Statement stmt=link.createStatement();
- ResultSet result=stmt.executeQuery("SELECT`student`.`QUOTA` FROM `mydb`.`student`;");
- while(result.next())
- {
- quota = result.getString("QUOTA"); //getting quota from student record
- }
- result=stmt.executeQuery("SELECT`student`.`CET_RANK`FROM `mydb`.`student`;");
- while(result.next())
- {
- rank = result.getInt("CET_RANK"); //getting rank from student record
- }
- if(null != quota)
- switch (quota) { //applying universal quota realxations
- case "SC":
- rank=rank-5000;
- break;
- case "ST":
- rank=rank-3000;
- break;
- case "DEF":
- rank=rank-1000;
- break;
- default:
- break;
- }
- for(int i=0;i<count;i++)
- {
- result=stmt.executeQuery("SELECT "+courseName[i]+" FROM Institutions WHERE COLLEGENAME = '"+collegeName[i]+"';");
- while(result.next())
- {
- int Cutoff=result.getInt(courseName[i]);
- }
- }
- } catch(Exception exc){exc.printStackTrace();}
- }
- // Variables declaration - do not modify
- private javax.swing.JButton AddButton;
- private javax.swing.JLabel CollegeLabel;
- private javax.swing.JList<String> CollegeList;
- private javax.swing.JLabel CoursesLabel;
- private javax.swing.JList<String> CoursesList;
- private javax.swing.JLabel DescTextLabel;
- private javax.swing.JButton DownButton;
- private javax.swing.JLabel NoteLabel;
- private javax.swing.JLabel PageLabel;
- private javax.swing.JLabel PrefListMade;
- private javax.swing.JList<String> PreferenceList;
- private javax.swing.JButton RemoveButton;
- private javax.swing.JButton SubmitButton;
- private javax.swing.JButton UpButton;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JScrollPane jScrollPane2;
- private javax.swing.JScrollPane jScrollPane3;
- // End of variables declaration
- }
Add Comment
Please, Sign In to add comment