Guest User

Untitled

a guest
Aug 11th, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.34 KB | None | 0 0
  1. package gui;
  2. import java.awt.*;
  3.  
  4. import javax.swing.*;
  5. import java.awt.event.*;
  6. import java.sql.DriverManager;
  7.  
  8. import java.sql.*;
  9. import java.sql.ResultSetMetaData;
  10. import java.util.Vector;
  11.  
  12. @SuppressWarnings("serial")
  13. public class loginPage extends JFrame implements ActionListener, KeyListener{
  14.  
  15.     //requirements for LoginPage
  16.     // two JLabels
  17.     // two JTexts
  18.     // one JButton
  19.    
  20.     /**
  21.      *
  22.      */
  23.     JLabel labelUsername, labelPassword;
  24.     JTextField textUsername, textPassword;
  25.     JButton submitButton; JButton cancel; JButton b4;
  26.     JButton b1 = new JButton ("Add/Update Category");
  27.     JButton b2 = new JButton ("Manage GuestBok");
  28.     JButton b3 = new JButton ("Manage Shop Creation Requests");
  29.     JButton back = new JButton("Back");
  30.     JButton c1 = new JButton("Add / view Guestbook");
  31.     Connection con;
  32.     Statement st1;
  33.     ResultSet rs1;
  34.    
  35.     ResultSetMetaData md;
  36.     Vector columnNames, data;
  37.    
  38.    
  39.     public void CD(){
  40.        
  41.        
  42.         // Connecting to the database
  43.         try {
  44.              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  45.              String filename = "c:/db/signup.mdb"; //Location of an Access database
  46.              String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
  47.              database+= filename.trim() + ";DriverID=22;READONLY=true}";
  48.              con = DriverManager.getConnection (database," "," ");
  49.              st1=con.createStatement();
  50.              
  51.              rs1=st1.executeQuery("select FName from Info");
  52.             }
  53.         catch(Exception e)
  54.             {
  55.              System.out.println("Error in establishing the connection: "+e);
  56.             }
  57.        
  58.     }
  59.    
  60.    
  61.    
  62.    
  63.     loginPage(){
  64.        
  65.         labelUsername = new JLabel("Username: ");
  66.         textUsername = new JTextField(15);
  67.         labelPassword = new JLabel("Password: ");
  68.         textPassword = new JPasswordField(15);
  69.         submitButton = new JButton("Submit");
  70.         cancel = new JButton("Cancel");
  71.         b4 = new JButton("logout");
  72.        
  73.         setTitle("Online Mall");
  74.        
  75.            
  76.         //container
  77.         getContentPane().setLayout(new FlowLayout());
  78.        
  79.         //content
  80.         getContentPane().add(labelUsername);
  81.         getContentPane().add(textUsername);
  82.         getContentPane().add(labelPassword);
  83.         getContentPane().add(textPassword);
  84.         getContentPane().add(submitButton);
  85.         getContentPane().add(cancel);
  86.        
  87.        
  88.         submitButton.addActionListener(this);
  89.         cancel.addActionListener(this);
  90.        
  91.         //create and show
  92.         pack();
  93.         setVisible(true);
  94.         this.setResizable(false);
  95.         this.setLocationRelativeTo(null);
  96.         setDefaultCloseOperation(EXIT_ON_CLOSE);
  97.         submitButton.addKeyListener(this);
  98.         textPassword.addKeyListener(this);
  99.        
  100.     }
  101.    
  102.     public void A(){
  103.        
  104.        
  105.         dispose();
  106.         System.out.println("Submit is working");
  107.    
  108.        
  109.                    
  110.         getContentPane().setLayout (new FlowLayout());
  111.        
  112.         getContentPane().removeAll();
  113.        
  114.         getContentPane().add(b1);
  115.         getContentPane().add(b2);
  116.         getContentPane().add(b3);
  117.         getContentPane().add(b4);
  118.        
  119.         b1.addActionListener(this);
  120.         b2.addActionListener(this);
  121.         b3.addActionListener(this);
  122.         b4.addActionListener(this);
  123.        
  124.         pack();
  125.         setVisible(true);
  126.        
  127.        
  128.         setDefaultCloseOperation(EXIT_ON_CLOSE);
  129.        
  130.        
  131.        
  132.     }
  133.     public void U(){
  134.         JButton o1 = new JButton("Set Up Shop");
  135.         JButton o2 = new JButton("Discontinue shop");
  136.        
  137.         getContentPane().removeAll();
  138.        
  139.         getContentPane().add(o1);
  140.         getContentPane().add(o2);
  141.         getContentPane().add(b4);
  142.        
  143.         o1.addActionListener(this);
  144.         o2.addActionListener(this);
  145.         b4.addActionListener(this);
  146.        
  147.         pack();
  148.         setVisible(true);
  149.         }
  150.    
  151.     public void C(){
  152.        
  153.         JButton c2 = new JButton("Check Order Details");
  154.         JButton c3 = new JButton ("Enter Shop");
  155.        
  156.         getContentPane().removeAll();
  157.        
  158.         getContentPane().add(c1);
  159.         getContentPane().add(c2);
  160.         getContentPane().add(c3);
  161.         getContentPane().add(b4);
  162.        
  163.         c1.addActionListener(this);
  164.         c2.addActionListener(this);
  165.         c3.addActionListener(this);
  166.         b4.addActionListener(this);
  167.        
  168.         pack();
  169.         setVisible(true);
  170.        
  171.     }
  172.    
  173.     public void J(){
  174.         JTable tabel = new JTable();
  175.        
  176.         getContentPane().removeAll();
  177.        
  178.         getContentPane().add(tabel);
  179.         getContentPane().add(b4);
  180.        
  181.         pack();
  182.         setVisible(true);
  183.         CD();
  184.        
  185.        
  186.     }
  187.    
  188.     public void P(){
  189.         JSpinner spinner = new JSpinner();
  190.        
  191.         getContentPane().removeAll();
  192.        
  193.         getContentPane().add(spinner);
  194.         getContentPane().add(b4);
  195.        
  196.         pack();
  197.         setVisible(true);
  198.         CD();
  199.     }
  200.    
  201.     public void R(){
  202.         JComboBox c = new JComboBox();
  203.        
  204.         getContentPane().removeAll();
  205.        
  206.         getContentPane().add(c);
  207.         getContentPane().add(b4);
  208.        
  209.         pack();
  210.         setVisible(true);
  211.         CD();
  212.     }
  213.    
  214.  
  215.     public void X(){
  216.        
  217.         System.out.println("This");
  218.         JLabel l = new JLabel("Wrong Login/Password");
  219.        
  220.         getContentPane().removeAll();
  221.        
  222.         getContentPane().add(back);
  223.         getContentPane().add(l);
  224.         back.addActionListener(this);
  225.        
  226.         pack();
  227.         setVisible(true);
  228.        
  229.     }
  230.    
  231.    
  232.    
  233.    
  234.     //Enter Key
  235.     public void keyTyped(KeyEvent e) {}
  236.     public void keyReleased(KeyEvent e){}
  237.     public void keyPressed(KeyEvent e){
  238.         int key = e.getKeyCode();
  239.         if (key == KeyEvent.VK_ENTER){
  240.         System.out.println("Enter pressed");
  241.         if (textUsername.getText().contains("admin") && textPassword.getText().contains("root")){
  242.         A();       
  243.         }
  244.         else if (textUsername.getText().contains("owner") && textPassword.getText().contains("owner01")){
  245.         U();
  246.             }
  247.         else if (textUsername.getText().contains("customer") && textPassword.getText().contains("customer01")){
  248.         C();
  249.         }
  250.         else {
  251.             X();
  252.         }
  253.        
  254.         }
  255.    
  256.     }
  257.     public void actionPerformed(ActionEvent e){
  258.         if (e.getSource() == cancel)
  259.             dispose();
  260.         else if (e.getSource() == submitButton && textUsername.getText().contains("admin") && textPassword.getText().contains("root"))
  261.         {
  262.             A();
  263.                    
  264.         }
  265.        
  266.         else if (e.getSource() == b4)
  267.             {new loginPage();
  268.             dispose();
  269.         }
  270.                 else if (e.getSource() == submitButton && textUsername.getText().contains("owner") && textPassword.getText().contains("owner01"))
  271.         {
  272.             U();
  273.         }
  274.        
  275.         else if (e.getSource() == submitButton && textUsername.getText().contains("customer") && textPassword.getText().contains("customer01"))
  276.         {C();}
  277.        
  278.         else if (b3 == e.getSource()){
  279.             J();
  280.         }
  281.        
  282.         else if (b2 == e.getSource()){
  283.             P();
  284.         }
  285.         else if (c1 == e.getSource()){
  286.             return;
  287.         }
  288.         else if (b1 == e.getSource()){
  289.             R();
  290.         }
  291.        
  292.         else if (back == e.getSource()){
  293.             dispose();
  294.             new loginPage();
  295.         }
  296.         else{
  297.             X();
  298.         }
  299.            
  300.     }
  301.  
  302.    
  303.     public static void main(String args[]){
  304.         new loginPage();
  305.     }
  306.  
  307.    
  308. }
Add Comment
Please, Sign In to add comment