Advertisement
Guest User

Untitled

a guest
May 19th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.07 KB | None | 0 0
  1. // Lect22
  2. // Demonstrating the JTextField class.
  3. import java.awt.FlowLayout;
  4. import java.awt.event.ActionListener;
  5. import java.awt.event.ActionEvent;
  6. import javax.swing.JFrame;
  7. import javax.swing.JTextField;
  8. import javax.swing.JLabel;
  9. import javax.swing.JOptionPane;
  10. import javax.swing.JButton;
  11. import javax.swing.JLabel;
  12. import javax.swing.JFrame;
  13. import java.util.InputMismatchException;
  14. import java.awt.BorderLayout;
  15. import java.awt.GridLayout;
  16. import java.awt.*;
  17. import javax.swing.Icon;
  18. import javax.swing.ImageIcon;
  19. import javax.swing.JDialog;
  20. //import java.awt.event.*;
  21. import javax.swing.JPanel;
  22. import javax.swing.JRadioButton;
  23. import javax.swing.ButtonGroup;
  24. import java.awt.event.ItemListener;
  25. import java.awt.event.ItemEvent;
  26. import oracle.jdbc.driver.*; //make sure this is in classpath
  27. import java.sql.*;
  28.  
  29. public class MyProject extends JFrame
  30. {
  31. private JLabel studentno_label;
  32. private JLabel edulevel_label;
  33. private JLabel vislevel_label;
  34. private JLabel firstname_label;
  35. private JLabel lastname_label;
  36. private JLabel dob_label;
  37. private JLabel menulabel;
  38. private JLabel title;
  39. private JLabel visionlabel;
  40. private JLabel subjectlabel;
  41.  
  42. private JTextField studentno_tf;
  43. private JTextField edulevel_tf;
  44. private JTextField vislevel_tf;
  45. private JTextField firstname_tf;
  46. private JTextField lastname_tf;
  47. private JTextField dob_tf;
  48.  
  49.  
  50.  
  51. private JRadioButton infant;
  52. private JRadioButton senior;
  53. private JRadioButton junior;
  54.  
  55.  
  56. private JRadioButton low;
  57. private JRadioButton partial;
  58. private JRadioButton severe;
  59.  
  60. private JRadioButton mathsbutton;
  61. private JRadioButton musicbutton;
  62.  
  63. private ButtonGroup edradiogroup;
  64. private ButtonGroup visradiogroup;
  65. private ButtonGroup subjectradiogroup;
  66.  
  67.  
  68. private JLabel datelabel;
  69. private JTextField datetextField;
  70.  
  71. JPanel statsbutton;
  72. JPanel process;
  73. JPanel buttons;
  74. JPanel j1;
  75. // JPanel buttons;
  76. JPanel header;
  77. JPanel labels;
  78. JPanel visbutton;
  79. JPanel subjectbutton;
  80.  
  81. private JLabel statuslabel;
  82.  
  83. private JButton processbutton;
  84. private JButton addButton;
  85.  
  86.  
  87.  
  88. private static String servername = "147.252.224.76"; //"ferdia.student.comp.dit.ie";
  89. private static String portnumber = "1521";
  90. private static String sid = "ORA11GDB";
  91. private static String url = "jdbc:oracle:thin:@" + servername + ":" + portnumber + ":" + sid;
  92. private static String user = "lmariano";
  93. private static String pass = "c07685874";
  94. private static Connection conn = null;
  95.  
  96.  
  97. Student c;
  98. Student student[] = new Student [10];
  99. int i = 0;
  100.  
  101. // TextFieldFrame constructor adds JTextFields to JFrame
  102. public MyProject()
  103. {
  104. super("My Project");
  105.  
  106.  
  107. try { conn = DriverManager.getConnection( url, user, pass );
  108. } catch( SQLException e )
  109. { e.printStackTrace();
  110. System.exit( 0 );
  111. }
  112.  
  113.  
  114. DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
  115. //conn = DriverManager.getConnection(url, user, pass);
  116.  
  117.  
  118. /*for(int i = 0; i<claim.length;i++)
  119. {
  120. claim[i] = new Claim();
  121. }*/
  122. menu();
  123.  
  124.  
  125. } // end TextFieldFrame constructor
  126.  
  127.  
  128. // private inner class for event handling
  129. public class TextFieldHandler implements ActionListener
  130. {
  131. // process textfield events
  132. public void actionPerformed( ActionEvent event )
  133. {
  134.  
  135. //claim[i] = c;
  136.  
  137. //**MENU BUTTONS
  138. if (event.getSource() == addButton)
  139. {
  140.  
  141. addstudent();
  142. JOptionPane.showMessageDialog( MyProject.this, String.format ( "%s", event. getActionCommand() ) );
  143.  
  144. }
  145.  
  146.  
  147.  
  148. } // end method actionPerformed
  149.  
  150. } // end private inner class TextFieldHandler
  151.  
  152.  
  153.  
  154.  
  155. public void menu()
  156. {
  157. //Create a panel and add components to it.
  158. JPanel j1 = new JPanel();
  159.  
  160.  
  161. buttons = new JPanel();
  162.  
  163.  
  164. buttons.setLayout(new GridLayout(8,1,10,2));
  165.  
  166.  
  167. menulabel = new JLabel( " Pick from the Menu below:");
  168. buttons.add( menulabel );// add datelabel to JFrame
  169.  
  170. //Icon bug1 = new ImageIcon (getClass().getResource( "bug1.gif"));
  171. //Icon bug2 = new ImageIcon (getClass().getResource( "bug2.gif"));
  172.  
  173. addButton = new JButton("Add a Student");
  174. //addButton.setRolloverIcon(bug2);
  175. buttons.add(addButton);
  176. addButton.setVisible(true);
  177.  
  178.  
  179.  
  180. addButton.addActionListener(new TextFieldHandler());
  181.  
  182. j1.add(buttons, BorderLayout.WEST);
  183. setContentPane(j1);
  184. j1.revalidate();
  185.  
  186.  
  187.  
  188. }
  189. public void addstudent()
  190.  
  191. { student[i] = new Student();
  192.  
  193. //c = new Claim();
  194.  
  195. //claim.getClaimNo();
  196.  
  197. //claim[i] = c;
  198.  
  199.  
  200. JPanel addstudent = new JPanel();
  201.  
  202. //addButton.setVisible(false);
  203. addstudent.add(buttons, BorderLayout.WEST);
  204. header = new JPanel();
  205. header.setLayout (new FlowLayout(FlowLayout.LEFT,15,10));
  206. // JLabel constructor with a string argument
  207. title = new JLabel(" ADD A STUDENT");
  208. header.add(title);
  209. addstudent.add(header, BorderLayout.EAST);//**BORDERLAYOUT
  210.  
  211. labels = new JPanel();
  212. labels.setLayout (new FlowLayout(FlowLayout.LEFT,30,30));
  213. // JLabel constructor with a string argument
  214.  
  215.  
  216. //System.out.printf("student number is: %d",student[i].getClaimNo());
  217.  
  218. //**DAY
  219. datelabel = new JLabel( " Enter BirthDate");
  220. labels.add( datelabel );// add datelabel to JFrame
  221.  
  222.  
  223. // construct textfield with 2 columns
  224. datetextField = new JTextField( 10);
  225. labels.add( datetextField ); // add datetextField to JFrame
  226.  
  227.  
  228.  
  229. TextFieldHandler handler = new TextFieldHandler();
  230.  
  231.  
  232.  
  233.  
  234. addstudent.add(labels, BorderLayout.EAST);//**BORDERLAYOUT
  235.  
  236. statsbutton = new JPanel();
  237. statsbutton.setLayout( new GridLayout(7,1));
  238.  
  239. statuslabel = new JLabel( " Pick an education level" );
  240. statsbutton.add( statuslabel ); // add statuslabel to JFrame
  241.  
  242. infant = new JRadioButton( "infant",false);
  243. junior = new JRadioButton( "junior",false);
  244. senior = new JRadioButton( "senior",false);
  245.  
  246.  
  247. statsbutton.add(infant);
  248. statsbutton.add(junior);
  249. statsbutton.add(senior);
  250.  
  251.  
  252. // create logical relationship between JRadioButtons
  253. edradiogroup= new ButtonGroup(); // create ButtonGroup
  254. edradiogroup.add( infant ); // add infant to group
  255. edradiogroup.add( junior ); // add junior to group
  256. edradiogroup.add( senior ); // add senior to group
  257.  
  258.  
  259.  
  260. //register events for JRadioButtons
  261. infant.addActionListener( new TextFieldHandler());
  262. junior.addActionListener( new TextFieldHandler());
  263. senior.addActionListener( new TextFieldHandler());
  264.  
  265.  
  266. visbutton = new JPanel();
  267. visbutton.setLayout( new GridLayout(5,1));
  268.  
  269. visionlabel = new JLabel( " Pick a vision level" );
  270. visbutton.add( visionlabel ); // add statuslabel to JFrame
  271.  
  272. low = new JRadioButton( "low",false);
  273. partial = new JRadioButton( "partial",false);
  274. severe = new JRadioButton( "severe",false);
  275.  
  276.  
  277. visbutton.add(low);
  278. visbutton.add(partial);
  279. visbutton.add(severe);
  280.  
  281.  
  282. // create logical relationship between JRadioButtons
  283. visradiogroup= new ButtonGroup(); // create ButtonGroup
  284. visradiogroup.add( low ); // add infant to group
  285. visradiogroup.add( partial ); // add junior to group
  286. visradiogroup.add( severe ); // add senior to group
  287.  
  288.  
  289.  
  290. //register events for JRadioButtons
  291. low.addActionListener( new TextFieldHandler());
  292. partial.addActionListener( new TextFieldHandler());
  293. severe.addActionListener( new TextFieldHandler());
  294.  
  295.  
  296.  
  297. /*process = new JPanel();
  298. process.setLayout(new FlowLayout(FlowLayout.CENTER,15,10));
  299. processButton = new JButton("Process Student Record");
  300. process.add(processButton);
  301.  
  302. processButton.addActionListener(new TextFieldHandler());
  303. addstudent.add(process, BorderLayout.SOUTH);*/
  304.  
  305.  
  306. //System.out.printf("Claim Status is %s: ", claim1.getStatus());
  307. addstudent.add(visbutton, BorderLayout.SOUTH);//**BORDERLAYOUT
  308. addstudent.add(statsbutton, BorderLayout.SOUTH);//**BORDERLAYOUT
  309. setContentPane(addstudent);
  310. addstudent.revalidate();
  311.  
  312. //picklesson();
  313. //i++;
  314.  
  315. }// end method addclaim()
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322. public void picklesson()
  323.  
  324. {
  325.  
  326. JPanel picklesson = new JPanel();
  327.  
  328.  
  329. title = new JLabel("PICK A LESSON");
  330.  
  331. header.add(title);
  332. picklesson.add(header, BorderLayout.EAST);//**BORDERLAYOUT
  333.  
  334. labels = new JPanel();
  335. labels.setLayout (new FlowLayout(FlowLayout.LEFT,30,30));
  336. // JLabel constructor with a string argument
  337.  
  338.  
  339. //System.out.printf("student number is: %d",student[i].getClaimNo());
  340.  
  341.  
  342. TextFieldHandler handler = new TextFieldHandler();
  343.  
  344.  
  345.  
  346. subjectbutton = new JPanel();
  347. subjectbutton.setLayout( new GridLayout(7,1));
  348.  
  349. subjectlabel = new JLabel( " Pick a subject" );
  350. subjectbutton.add( subjectlabel ); // add statuslabel to JFrame
  351.  
  352. mathsbutton = new JRadioButton( "maths",false);
  353. musicbutton = new JRadioButton( "music",false);
  354.  
  355.  
  356.  
  357. subjectbutton.add(mathsbutton);
  358. subjectbutton.add(musicbutton);
  359.  
  360.  
  361.  
  362. // create logical relationship between JRadioButtons
  363. subjectradiogroup= new ButtonGroup(); // create ButtonGroup
  364. subjectradiogroup.add( mathsbutton ); // add infant to group
  365. subjectradiogroup.add( musicbutton ); // add junior to group
  366.  
  367.  
  368.  
  369.  
  370. //register events for JRadioButtons
  371. mathsbutton.addActionListener( new TextFieldHandler());
  372. musicbutton.addActionListener( new TextFieldHandler());
  373.  
  374.  
  375.  
  376.  
  377.  
  378. picklesson.add(subjectbutton, BorderLayout.SOUTH);//**BORDERLAYOUT
  379. setContentPane(picklesson);
  380. picklesson.revalidate();
  381.  
  382.  
  383. }
  384.  
  385.  
  386. }
  387.  
  388.  
  389. //} // end class TextFieldFrame
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement