Advertisement
Guest User

Untitled

a guest
May 19th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.14 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.         DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
  109.         } catch( SQLException e )
  110.             { e.printStackTrace();
  111.             System.exit( 0 );
  112.         }
  113.  
  114.  
  115.         //DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
  116.         //conn = DriverManager.getConnection(url, user, pass);
  117.  
  118.  
  119.         /*for(int i = 0; i<claim.length;i++)
  120.         {
  121.             claim[i] = new Claim();
  122.         }*/
  123.         menu();
  124.  
  125.  
  126.    } // end TextFieldFrame constructor
  127.  
  128.  
  129.    // private inner class for event handling
  130.    public class TextFieldHandler implements ActionListener
  131.    {
  132.       // process textfield events
  133.       public void actionPerformed( ActionEvent event )
  134.       {
  135.  
  136.             //claim[i] = c;
  137.  
  138.           //**MENU BUTTONS
  139.                         if (event.getSource() == addButton)
  140.                         {
  141.  
  142.                             addstudent();
  143.                             JOptionPane.showMessageDialog( MyProject.this, String.format ( "%s", event. getActionCommand() ) );
  144.  
  145.                         }
  146.  
  147.  
  148.  
  149.       } // end method actionPerformed
  150.  
  151.    } // end private inner class TextFieldHandler
  152.  
  153.  
  154.  
  155.  
  156. public void menu()
  157. {
  158.     //Create a panel and add components to it.
  159.                 JPanel j1 = new JPanel();
  160.  
  161.  
  162.                 buttons = new JPanel();
  163.  
  164.  
  165.                 buttons.setLayout(new GridLayout(8,1,10,2));
  166.  
  167.  
  168.                 menulabel = new JLabel( " Pick from the Menu below:");
  169.                 buttons.add( menulabel );// add datelabel to JFrame
  170.  
  171.                 //Icon bug1 = new ImageIcon (getClass().getResource( "bug1.gif"));
  172.                 //Icon bug2 = new ImageIcon (getClass().getResource( "bug2.gif"));
  173.  
  174.                 addButton = new JButton("Add a Student");
  175.                 //addButton.setRolloverIcon(bug2);
  176.                 buttons.add(addButton);
  177.                 addButton.setVisible(true);
  178.  
  179.  
  180.  
  181.                 addButton.addActionListener(new TextFieldHandler());
  182.  
  183.                 j1.add(buttons, BorderLayout.WEST);
  184.             setContentPane(j1);
  185.             j1.revalidate();
  186.  
  187.  
  188.  
  189.         }
  190. public void addstudent()
  191.  
  192. {                           student[i] = new Student();
  193.  
  194.                             //c = new Claim();
  195.  
  196.                             //claim.getClaimNo();
  197.  
  198.                             //claim[i] = c;
  199.  
  200.  
  201.                                 JPanel addstudent = new JPanel();
  202.  
  203.                                 //addButton.setVisible(false);
  204.                                 addstudent.add(buttons, BorderLayout.WEST);
  205.                                 header = new JPanel();
  206.                                 header.setLayout (new FlowLayout(FlowLayout.LEFT,15,10));
  207.                                             // JLabel constructor with a string argument
  208.                                 title = new JLabel(" ADD A STUDENT");
  209.                                 header.add(title);
  210.                                 addstudent.add(header, BorderLayout.EAST);//**BORDERLAYOUT
  211.  
  212.                                 labels = new JPanel();
  213.                                 labels.setLayout (new FlowLayout(FlowLayout.LEFT,30,30));
  214.                                 // JLabel constructor with a string argument
  215.  
  216.  
  217.                                 //System.out.printf("student number is: %d",student[i].getClaimNo());
  218.  
  219.                                 //**DAY
  220.                                 datelabel = new JLabel( " Enter BirthDate");
  221.                                 labels.add( datelabel );// add datelabel to JFrame
  222.  
  223.  
  224.                                         // construct textfield with 2 columns
  225.                                 datetextField = new JTextField( 10);
  226.                                 labels.add( datetextField ); // add datetextField to JFrame
  227.  
  228.  
  229.  
  230.                                 TextFieldHandler handler = new TextFieldHandler();
  231.  
  232.  
  233.  
  234.  
  235.                                 addstudent.add(labels, BorderLayout.EAST);//**BORDERLAYOUT
  236.  
  237.                                 statsbutton = new JPanel();
  238.                                 statsbutton.setLayout( new GridLayout(7,1));
  239.  
  240.                                 statuslabel = new JLabel( " Pick an education level" );
  241.                                 statsbutton.add( statuslabel ); // add statuslabel to JFrame
  242.  
  243.                                 infant = new JRadioButton( "infant",false);
  244.                                 junior = new JRadioButton( "junior",false);
  245.                                 senior = new JRadioButton( "senior",false);
  246.  
  247.  
  248.                                 statsbutton.add(infant);
  249.                                 statsbutton.add(junior);
  250.                                 statsbutton.add(senior);
  251.  
  252.  
  253.                                 // create logical relationship between JRadioButtons
  254.                                 edradiogroup= new ButtonGroup(); // create ButtonGroup
  255.                                 edradiogroup.add( infant ); // add infant to group
  256.                                 edradiogroup.add( junior ); // add junior to group
  257.                                 edradiogroup.add( senior ); // add senior to group
  258.  
  259.  
  260.  
  261.                                 //register events for JRadioButtons
  262.                                 infant.addActionListener( new TextFieldHandler());
  263.                                 junior.addActionListener( new TextFieldHandler());
  264.                                 senior.addActionListener( new TextFieldHandler());
  265.  
  266.  
  267.                                 visbutton = new JPanel();
  268.                                 visbutton.setLayout( new GridLayout(5,1));
  269.  
  270.                                 visionlabel = new JLabel( " Pick a vision level" );
  271.                                 visbutton.add( visionlabel ); // add statuslabel to JFrame
  272.  
  273.                                 low = new JRadioButton( "low",false);
  274.                                 partial = new JRadioButton( "partial",false);
  275.                                 severe = new JRadioButton( "severe",false);
  276.  
  277.  
  278.                                 visbutton.add(low);
  279.                                 visbutton.add(partial);
  280.                                 visbutton.add(severe);
  281.  
  282.  
  283.                                 // create logical relationship between JRadioButtons
  284.                                 visradiogroup= new ButtonGroup(); // create ButtonGroup
  285.                                 visradiogroup.add( low ); // add infant to group
  286.                                 visradiogroup.add( partial ); // add junior to group
  287.                                 visradiogroup.add( severe ); // add senior to group
  288.  
  289.  
  290.  
  291.                                 //register events for JRadioButtons
  292.                                 low.addActionListener( new TextFieldHandler());
  293.                                 partial.addActionListener( new TextFieldHandler());
  294.                                 severe.addActionListener( new TextFieldHandler());
  295.  
  296.  
  297.  
  298.                                 /*process = new JPanel();
  299.                                 process.setLayout(new FlowLayout(FlowLayout.CENTER,15,10));
  300.                                 processButton = new JButton("Process Student Record");
  301.                                 process.add(processButton);
  302.  
  303.                                 processButton.addActionListener(new TextFieldHandler());
  304.                                 addstudent.add(process, BorderLayout.SOUTH);*/
  305.  
  306.  
  307.                                 //System.out.printf("Claim Status is %s: ", claim1.getStatus());
  308.                                 addstudent.add(visbutton, BorderLayout.SOUTH);//**BORDERLAYOUT
  309.                                 addstudent.add(statsbutton, BorderLayout.SOUTH);//**BORDERLAYOUT
  310.                                 setContentPane(addstudent);
  311.                                 addstudent.revalidate();
  312.  
  313.                                 //picklesson();
  314.                                 //i++;
  315.  
  316. }// end method addclaim()
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323. public void picklesson()
  324.  
  325. {
  326.  
  327.     JPanel picklesson = new JPanel();
  328.  
  329.  
  330.     title = new JLabel("PICK A LESSON");
  331.  
  332.                                     header.add(title);
  333.                                     picklesson.add(header, BorderLayout.EAST);//**BORDERLAYOUT
  334.  
  335.                                     labels = new JPanel();
  336.                                     labels.setLayout (new FlowLayout(FlowLayout.LEFT,30,30));
  337.                                     // JLabel constructor with a string argument
  338.  
  339.  
  340.                                     //System.out.printf("student number is: %d",student[i].getClaimNo());
  341.  
  342.  
  343.                                     TextFieldHandler handler = new TextFieldHandler();
  344.  
  345.  
  346.  
  347.                                     subjectbutton = new JPanel();
  348.                                     subjectbutton.setLayout( new GridLayout(7,1));
  349.  
  350.                                     subjectlabel = new JLabel( " Pick a subject" );
  351.                                     subjectbutton.add( subjectlabel ); // add statuslabel to JFrame
  352.  
  353.                                     mathsbutton = new JRadioButton( "maths",false);
  354.                                     musicbutton = new JRadioButton( "music",false);
  355.  
  356.  
  357.  
  358.                                     subjectbutton.add(mathsbutton);
  359.                                     subjectbutton.add(musicbutton);
  360.  
  361.  
  362.  
  363.                                     // create logical relationship between JRadioButtons
  364.                                     subjectradiogroup= new ButtonGroup(); // create ButtonGroup
  365.                                     subjectradiogroup.add( mathsbutton ); // add infant to group
  366.                                     subjectradiogroup.add( musicbutton ); // add junior to group
  367.  
  368.  
  369.  
  370.  
  371.                                     //register events for JRadioButtons
  372.                                     mathsbutton.addActionListener( new TextFieldHandler());
  373.                                     musicbutton.addActionListener( new TextFieldHandler());
  374.  
  375.  
  376.  
  377.  
  378.  
  379.                                     picklesson.add(subjectbutton, BorderLayout.SOUTH);//**BORDERLAYOUT
  380.                                     setContentPane(picklesson);
  381.                                     picklesson.revalidate();
  382.  
  383.  
  384. }
  385.  
  386.  
  387. }
  388.  
  389.  
  390. //} // end class TextFieldFrame
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement