Guest User

Untitled

a guest
Jul 24th, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.66 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. import java.sql.*;
  7. import javax.swing.*;
  8. /**
  9. *
  10. * @author Aniket
  11. */
  12. public class PrefApp extends javax.swing.JApplet {
  13.  
  14. DefaultListModel<String> list=new DefaultListModel<>(); //holds items(preferences) in Preference List displayed in applet
  15.  
  16. public static String collegeName[]=new String[100];//holds the college name according to preference list made
  17. 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
  18.  
  19. public static int count=0; //global var; used by collName[]&courseName[] to prioritise according to internal preference list | [top] of stacks of collegeName & courseName
  20.  
  21. public String quota; //holds the CETRank and Quota from database
  22. public int rank;
  23. /**
  24. * Initializes the applet PrefApp
  25. */
  26. @Override
  27. public void init() {
  28. /* Set the Nimbus look and feel */
  29. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  30. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  31. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  32. */
  33. try {
  34. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  35. if ("Nimbus".equals(info.getName())) {
  36. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  37. break;
  38. }
  39. }
  40. } catch (ClassNotFoundException ex) {
  41. java.util.logging.Logger.getLogger(PrefApp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  42. } catch (InstantiationException ex) {
  43. java.util.logging.Logger.getLogger(PrefApp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  44. } catch (IllegalAccessException ex) {
  45. java.util.logging.Logger.getLogger(PrefApp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  46. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  47. java.util.logging.Logger.getLogger(PrefApp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  48. }
  49. //</editor-fold>
  50.  
  51. /* Create and display the applet */
  52. try {
  53. java.awt.EventQueue.invokeAndWait(new Runnable() {
  54. @Override
  55. public void run() {
  56. initComponents();
  57. }
  58. });
  59. } catch (Exception ex) {
  60. ex.printStackTrace();
  61. }
  62. }
  63.  
  64. /**
  65. * This method is called from within the init() method to initialize the
  66. * form. WARNING: Do NOT modify this code. The content of this method is
  67. * always regenerated by the Form Editor.
  68. */
  69. @SuppressWarnings("unchecked")
  70. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  71. private void initComponents() {
  72.  
  73. PageLabel = new javax.swing.JLabel();
  74. DescTextLabel = new javax.swing.JLabel();
  75. jScrollPane1 = new javax.swing.JScrollPane();
  76. CollegeList = new javax.swing.JList<>();
  77. CollegeLabel = new javax.swing.JLabel();
  78. CoursesLabel = new javax.swing.JLabel();
  79. jScrollPane2 = new javax.swing.JScrollPane();
  80. CoursesList = new javax.swing.JList<>();
  81. AddButton = new javax.swing.JButton();
  82. RemoveButton = new javax.swing.JButton();
  83. UpButton = new javax.swing.JButton();
  84. DownButton = new javax.swing.JButton();
  85. NoteLabel = new javax.swing.JLabel();
  86. jScrollPane3 = new javax.swing.JScrollPane();
  87. PreferenceList = new javax.swing.JList<>(list);
  88. PrefListMade = new javax.swing.JLabel();
  89. SubmitButton = new javax.swing.JButton();
  90.  
  91. PageLabel.setFont(new java.awt.Font("Malgun Gothic", 1, 36)); // NOI18N
  92. PageLabel.setText("PREFERENCE LIST");
  93.  
  94. DescTextLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  95. DescTextLabel.setText("List the College & Courses of your choice according to the admission priority.");
  96.  
  97. CollegeList.setModel(new javax.swing.AbstractListModel<String>() {
  98. 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" };
  99. public int getSize() { return strings.length; }
  100. public String getElementAt(int i) { return strings[i]; }
  101. });
  102. CollegeList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
  103. jScrollPane1.setViewportView(CollegeList);
  104.  
  105. CollegeLabel.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
  106. CollegeLabel.setText("Colleges");
  107.  
  108. CoursesLabel.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
  109. CoursesLabel.setText("Courses Available");
  110.  
  111. CoursesList.setModel(new javax.swing.AbstractListModel<String>() {
  112. String[] strings = { "Computer Science & Engineering", "Information Technology", "Electronics & Communication Engineering", "Mechanical & Automation Engineering" };
  113. public int getSize() { return strings.length; }
  114. public String getElementAt(int i) { return strings[i]; }
  115. });
  116. CoursesList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
  117. jScrollPane2.setViewportView(CoursesList);
  118.  
  119. AddButton.setText("Add");
  120. AddButton.addActionListener(new java.awt.event.ActionListener() {
  121. public void actionPerformed(java.awt.event.ActionEvent evt) {
  122. AddButtonActionPerformed(evt);
  123. }
  124. });
  125.  
  126. RemoveButton.setText("Remove");
  127. RemoveButton.addActionListener(new java.awt.event.ActionListener() {
  128. public void actionPerformed(java.awt.event.ActionEvent evt) {
  129. RemoveButtonActionPerformed(evt);
  130. }
  131. });
  132.  
  133. UpButton.setText("Up");
  134. UpButton.addActionListener(new java.awt.event.ActionListener() {
  135. public void actionPerformed(java.awt.event.ActionEvent evt) {
  136. UpButtonActionPerformed(evt);
  137. }
  138. });
  139.  
  140. DownButton.setText("Down");
  141. DownButton.addActionListener(new java.awt.event.ActionListener() {
  142. public void actionPerformed(java.awt.event.ActionEvent evt) {
  143. DownButtonActionPerformed(evt);
  144. }
  145. });
  146.  
  147. NoteLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  148. NoteLabel.setForeground(new java.awt.Color(255, 0, 0));
  149. NoteLabel.setText("NOTE: Review your admission preferences carefully. Once submitted, they can't be altered!");
  150.  
  151. PreferenceList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
  152. PreferenceList.addContainerListener(new java.awt.event.ContainerAdapter() {
  153. public void componentAdded(java.awt.event.ContainerEvent evt) {
  154. PreferenceListComponentAdded(evt);
  155. }
  156. });
  157. jScrollPane3.setViewportView(PreferenceList);
  158.  
  159. PrefListMade.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
  160. PrefListMade.setText("Preferences of Admission");
  161.  
  162. SubmitButton.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  163. SubmitButton.setText("Submit");
  164. SubmitButton.addActionListener(new java.awt.event.ActionListener() {
  165. public void actionPerformed(java.awt.event.ActionEvent evt) {
  166. SubmitButtonActionPerformed(evt);
  167. }
  168. });
  169.  
  170. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  171. getContentPane().setLayout(layout);
  172. layout.setHorizontalGroup(
  173. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  174. .addGroup(layout.createSequentialGroup()
  175. .addContainerGap()
  176. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  177. .addComponent(PageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 450, javax.swing.GroupLayout.PREFERRED_SIZE)
  178. .addComponent(DescTextLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 480, javax.swing.GroupLayout.PREFERRED_SIZE)
  179. .addGroup(layout.createSequentialGroup()
  180. .addComponent(CollegeLabel)
  181. .addGap(225, 225, 225)
  182. .addComponent(CoursesLabel)
  183. .addGap(142, 142, 142)
  184. .addComponent(PrefListMade))
  185. .addGroup(layout.createSequentialGroup()
  186. .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE)
  187. .addGap(20, 20, 20)
  188. .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
  189. .addGap(18, 18, 18)
  190. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
  191. .addComponent(RemoveButton, javax.swing.GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE)
  192. .addComponent(DownButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  193. .addComponent(UpButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  194. .addComponent(AddButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  195. .addGap(18, 18, 18)
  196. .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE))
  197. .addGroup(layout.createSequentialGroup()
  198. .addComponent(NoteLabel)
  199. .addGap(188, 188, 188)
  200. .addComponent(SubmitButton, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
  201. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  202. );
  203. layout.setVerticalGroup(
  204. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  205. .addGroup(layout.createSequentialGroup()
  206. .addComponent(PageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
  207. .addGap(10, 10, 10)
  208. .addComponent(DescTextLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
  209. .addGap(30, 30, 30)
  210. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  211. .addComponent(CollegeLabel)
  212. .addComponent(CoursesLabel)
  213. .addComponent(PrefListMade))
  214. .addGap(8, 8, 8)
  215. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  216. .addGroup(layout.createSequentialGroup()
  217. .addComponent(AddButton)
  218. .addGap(7, 7, 7)
  219. .addComponent(RemoveButton)
  220. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  221. .addComponent(UpButton)
  222. .addGap(7, 7, 7)
  223. .addComponent(DownButton))
  224. .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
  225. .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
  226. .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE))
  227. .addGap(20, 20, 20)
  228. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  229. .addGroup(layout.createSequentialGroup()
  230. .addGap(10, 10, 10)
  231. .addComponent(NoteLabel))
  232. .addComponent(SubmitButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
  233. .addGap(0, 10, Short.MAX_VALUE))
  234. );
  235. }// </editor-fold>
  236.  
  237. private void AddButtonActionPerformed(java.awt.event.ActionEvent evt) {
  238. // TODO add your handling code here:
  239. String collSelected=CollegeList.getSelectedValue(); //reads value of selected college in CollegeList
  240. String courSelected=CoursesList.getSelectedValue(); //reads value of selected course in CoursesList
  241.  
  242. /*ADDITION OF PREFERENCE LIST*/
  243. collegeName[count]=collSelected; //adds name of college to internal priority list
  244. if(null != courSelected)
  245. switch (courSelected) { //adds name of course to internal priority list
  246. case "Computer Science & Engineering":
  247. courseName[count]="CUTCSE";
  248. break;
  249. case "Information Technology":
  250. courseName[count]="CUTIT";
  251. break;
  252. case "Electronics & Communication Engineering":
  253. courseName[count]="CUTECE";
  254. break;
  255. default:
  256. courseName[count]="CUTMAE";
  257. break;
  258. }
  259. count++; //priority variable
  260. /*ADDITION OF PREFEENCE LIST*/ //Addition works like push of a stack
  261.  
  262. String choice=courSelected+"@"+collSelected; //creats a string for displaying in applet
  263.  
  264. list.addElement(choice); //adds to displayed list PreferenceList
  265. }
  266.  
  267. private void PreferenceListComponentAdded(java.awt.event.ContainerEvent evt) {
  268. // TODO add your handling code here:
  269. }
  270.  
  271. private void RemoveButtonActionPerformed(java.awt.event.ActionEvent evt) {
  272. // TODO add your handling code here:
  273. int index=PreferenceList.getSelectedIndex(); //holds position of selected item from PreferenceList to be removed
  274.  
  275.  
  276. for(int i=index;i<count;i++) //removes the selected item at index (selected position) from internal pref list
  277. {
  278. collegeName[i]=collegeName[i+1];
  279. courseName[i]=courseName[i+1];
  280. }
  281.  
  282. count--; //decrease value of 'top' of stacks for further insertion (collegeName & courseName)
  283.  
  284. collegeName[count]=null;
  285. courseName[count]=null;
  286.  
  287. list.remove(index); //removes the choihe from Preference List
  288. }
  289.  
  290. private void UpButtonActionPerformed(java.awt.event.ActionEvent evt) {
  291. // TODO add your handling code here:
  292. int pos=PreferenceList.getSelectedIndex(); //holds the position of item selected
  293. int newpos=pos-1; //holds the one above position of selected item
  294. String tempstring; //temporary string variable for swapping choices
  295.  
  296. /*UPDATING INTERNAL LIST*/
  297. tempstring=collegeName[pos]; //swaps the item stored in internal college priority list
  298. collegeName[pos]=collegeName[newpos];
  299. collegeName[newpos]=tempstring;
  300.  
  301. tempstring=courseName[pos]; //swaps the item stored in internal course priority list
  302. courseName[pos]=courseName[newpos];
  303. courseName[newpos]=tempstring;
  304. /*UPDATING INTERNAL LIST*/
  305.  
  306. /*UPDATING DISPLAY LIST*/
  307. String spos=PreferenceList.getSelectedValue();
  308. PreferenceList.setSelectedIndex(newpos);
  309. String npos=PreferenceList.getSelectedValue();
  310.  
  311. list.setElementAt(spos, newpos);
  312. list.setElementAt(npos, pos);
  313. /*UPDATING DISPLAY LIST*/
  314. }
  315.  
  316. private void DownButtonActionPerformed(java.awt.event.ActionEvent evt) {
  317. // TODO add your handling code here:
  318. int pos=PreferenceList.getSelectedIndex(); //holds the position of item selected
  319. int newpos=pos+1; //holds the one above position of selected item
  320. String tempstring; //temporary string variable for swapping choices
  321.  
  322. /*UPDATING INTERNAL LIST*/
  323. tempstring=collegeName[pos]; //swaps the item stored in internal college priority list
  324. collegeName[pos]=collegeName[newpos];
  325. collegeName[newpos]=tempstring;
  326.  
  327. tempstring=courseName[pos]; //swaps the item stored in internal course priority list
  328. courseName[pos]=courseName[newpos];
  329. courseName[newpos]=tempstring;
  330. /*UPDATING INTERNAL LIST*/
  331.  
  332. /*UPDATING DISPLAY LIST*/
  333. String spos=PreferenceList.getSelectedValue();
  334. PreferenceList.setSelectedIndex(newpos);
  335. String npos=PreferenceList.getSelectedValue();
  336.  
  337. list.setElementAt(spos, newpos);
  338. list.setElementAt(npos, pos);
  339. /*UPDATING DISPLAY LIST*/
  340. }
  341.  
  342. private void SubmitButtonActionPerformed(java.awt.event.ActionEvent evt) {
  343. // TODO add your handling code here:
  344. try{
  345. Connection link=DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb","Aniket","root");
  346. Statement stmt=link.createStatement();
  347. ResultSet result=stmt.executeQuery("SELECT`student`.`QUOTA` FROM `mydb`.`student`;");
  348. while(result.next())
  349. {
  350. quota = result.getString("QUOTA"); //getting quota from student record
  351. }
  352.  
  353. result=stmt.executeQuery("SELECT`student`.`CET_RANK`FROM `mydb`.`student`;");
  354. while(result.next())
  355. {
  356. rank = result.getInt("CET_RANK"); //getting rank from student record
  357. }
  358.  
  359.  
  360. if(null != quota)
  361. switch (quota) { //applying universal quota realxations
  362. case "SC":
  363. rank=rank-5000;
  364. break;
  365. case "ST":
  366. rank=rank-3000;
  367. break;
  368. case "DEF":
  369. rank=rank-1000;
  370. break;
  371. default:
  372. break;
  373. }
  374.  
  375. for(int i=0;i<count;i++)
  376. {
  377. result=stmt.executeQuery("SELECT "+courseName[i]+" FROM Institutions WHERE COLLEGENAME = '"+collegeName[i]+"';");
  378. while(result.next())
  379. {
  380. int Cutoff=result.getInt(courseName[i]);
  381. }
  382. }
  383. } catch(Exception exc){exc.printStackTrace();}
  384.  
  385. }
  386.  
  387. // Variables declaration - do not modify
  388. private javax.swing.JButton AddButton;
  389. private javax.swing.JLabel CollegeLabel;
  390. private javax.swing.JList<String> CollegeList;
  391. private javax.swing.JLabel CoursesLabel;
  392. private javax.swing.JList<String> CoursesList;
  393. private javax.swing.JLabel DescTextLabel;
  394. private javax.swing.JButton DownButton;
  395. private javax.swing.JLabel NoteLabel;
  396. private javax.swing.JLabel PageLabel;
  397. private javax.swing.JLabel PrefListMade;
  398. private javax.swing.JList<String> PreferenceList;
  399. private javax.swing.JButton RemoveButton;
  400. private javax.swing.JButton SubmitButton;
  401. private javax.swing.JButton UpButton;
  402. private javax.swing.JScrollPane jScrollPane1;
  403. private javax.swing.JScrollPane jScrollPane2;
  404. private javax.swing.JScrollPane jScrollPane3;
  405. // End of variables declaration
  406. }
Add Comment
Please, Sign In to add comment