Beispiel #1
0
  protected void createComponents() {
    main = new JPanel();
    main.setLayout(null);

    int divY = 42;

    BackgroundPanel div = new BackgroundPanel(hLine);
    div.setBounds(0, divY, 1920, 2);
    div.setStyle(BackgroundPanel.SCALED_X);

    JPanel tools = new JPanel(null);
    tools.setBounds(0, 0, 800, divY);

    bNew = new JButton("");
    bNew.setIcon(new ImageIcon(newButtonImage));
    bNew.setBorderPainted(false);
    bNew.setBounds(10, 10, newButtonImage.getWidth(null), newButtonImage.getHeight(null));

    search = new SearchTextField(searchHint, ElephantWindow.fontMedium);
    search.setBorder(BorderFactory.createEmptyBorder(0, 22, 0, 20));
    search.setBounds(newButtonImage.getWidth(null) + 10, 8, 160, 26);
    search.setFont(ElephantWindow.fontMedium);
    search.setFixedColor(Color.decode("#e9e9e9"));
    search.useV2();
    search.windowFocusGained();

    trash = new JButton("");
    trash.setBorderPainted(false);
    trash.setContentAreaFilled(false);
    trash.setIcon(new ImageIcon(noteToolsTrash));
    trash.setVisible(this instanceof Notebooks);
    trash.setBounds(
        newButtonImage.getWidth(null) + 177,
        10,
        noteToolsTrash.getWidth(null),
        noteToolsTrash.getHeight(null));

    tools.add(bNew);
    tools.add(search);
    tools.add(trash);

    scroll = new JScrollPane(main);
    scroll.setBorder(ElephantWindow.emptyBorder);
    scroll.getHorizontalScrollBar().setUnitIncrement(5);
    scroll.getVerticalScrollBar().setUnitIncrement(5);

    add(tools);
    add(div);
    add(scroll);

    addComponentListeners();
  }
Beispiel #2
0
  // *********************************************CONSTRUCTOR METHOD
  public EPoverty() throws IOException {
    UIManager.put("Button.select", Color.BLACK);

    // ******************************************CREATE MAIN PANEL
    setTitle("|||E-Poverty || V-0.1 (SKELETON)|||");
    setSize(500, 275);
    setLocation(500, 200);
    setVisible(true);
    setResizable(false);
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    mainPanel = new JPanel();
    setContentPane(mainPanel);
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));
    // ******************************************END OF CREATING MAIN PANEL

    /* CREATE THE TOP AND BOTTOM PANELS, ADDING BACKGROUND IMAGES
     *
     * BackgroundPanel is an extension to JPanel that makes it easy to
     * paint images as a background on the panel, or add a gradient
     * fill as the background (this is what you currently see on the
     * back of all the tabs.  The constructors can be seen in the
     * BackgroundPanel.java class if you need or want to use them.
     */
    BackgroundPanel topPanel = new BackgroundPanel(background);
    Dimension top = new Dimension(500, 125);
    topPanel.setPreferredSize(top);
    GradientPaint paintTop = new GradientPaint(0, 0, Color.DARK_GRAY, 100, 100, Color.BLACK);
    topPanel.setPaint(paintTop);

    BackgroundPanel bottomPanel = new BackgroundPanel(null, BackgroundPanel.ACTUAL, 1.0f, 0.5f);
    Dimension bottom = new Dimension(500, 75);
    bottomPanel.setPreferredSize(bottom);
    GradientPaint paintBottom = new GradientPaint(50, 200, Color.WHITE, 100, 50, Color.BLACK);
    bottomPanel.setPaint(paintBottom);

    // *******************************************ADD PANELS TO THE MAIN
    mainPanel.add(topPanel);
    mainPanel.add(bottomPanel);

    // ******************************************ADD COMPONENTS TO THE BOTTOM PANEL
    bottomPanel.setLayout(new GridBagLayout());
    GridBagConstraints gBC = new GridBagConstraints();
    gBC.fill = GridBagConstraints.HORIZONTAL;

    // *****************************************FIRST ROW (BLANK)
    JLabel blank = new JLabel("");
    gBC.weightx = 1;
    gBC.weighty = 1;
    gBC.gridx = 0;
    gBC.gridy = 0;
    bottomPanel.add(blank, gBC);

    blank = new JLabel("");
    gBC.gridx = 1;
    gBC.gridy = 0;
    bottomPanel.add(blank, gBC);

    blank = new JLabel("");
    gBC.gridx = 2;
    gBC.gridy = 0;
    bottomPanel.add(blank, gBC);

    blank = new JLabel("");
    gBC.gridx = 3;
    gBC.gridy = 0;
    bottomPanel.add(blank, gBC);

    blank = new JLabel("");
    gBC.gridx = 4;
    gBC.gridy = 0;
    bottomPanel.add(blank, gBC);

    blank = new JLabel("");
    gBC.gridx = 5;
    gBC.gridy = 0;
    bottomPanel.add(blank, gBC);

    // *****************************************SECOND ROW (LOGIN)
    blank = new JLabel("LOGIN");
    gBC.gridx = 1;
    gBC.gridy = 1;
    gBC.gridheight = 2;
    gBC.gridwidth = 2;
    blank.setForeground(Color.WHITE);
    blank.setFont(new Font("Serif", Font.PLAIN, 16));
    bottomPanel.add(blank, gBC);
    blank.setHorizontalTextPosition(SwingConstants.RIGHT);

    login_TF = new JTextField("*****@*****.**");
    gBC.gridx = 3;
    gBC.gridy = 1;
    login_TF.setEditable(true);
    login_TF.setBackground(Color.WHITE);
    login_TF.setFont(new Font("Serif", Font.PLAIN, 16));
    login_TF.setForeground(Color.LIGHT_GRAY);
    bottomPanel.add(login_TF, gBC);
    login_TF.requestFocusInWindow();

    // ******************************************THIRD ROW (PASSWORD)
    blank = new JLabel("PASSWORD");
    gBC.gridx = 1;
    gBC.gridy = 3;
    blank.setForeground(Color.WHITE);
    blank.setFont(new Font("Serif", Font.PLAIN, 16));
    blank.setHorizontalTextPosition(JLabel.RIGHT);
    bottomPanel.add(blank, gBC);

    password_TF = new JPasswordField("password");
    gBC.gridx = 3;
    gBC.gridy = 3;
    password_TF.setEditable(true);
    password_TF.setForeground(Color.WHITE);
    password_TF.setFont(new Font("Serif", Font.PLAIN, 16));
    bottomPanel.add(password_TF, gBC);

    // *****************************************FOURTH ROW (BLANK)
    blank = new JLabel("");
    gBC.gridx = 1;
    gBC.gridy = 3;
    gBC.gridheight = 1;
    bottomPanel.add(blank, gBC);

    // *****************************************FIFTH ROW (BUTTONS)
    JButton login_BTN = new JButton("");
    gBC.gridx = 3;
    gBC.gridy = 5;
    gBC.gridwidth = 1;
    login_BTN.setIcon(new ImageIcon(login));
    login_BTN.setMargin(new Insets(0, 0, 0, 0));
    login_BTN.setBackground(Color.LIGHT_GRAY);
    login_BTN.setRolloverEnabled(false);
    login_BTN.setFocusPainted(false);
    login_BTN.setContentAreaFilled(false);
    bottomPanel.add(login_BTN, gBC);

    JButton settings_BTN = new JButton("Settings");
    gBC.gridx = 5;
    gBC.gridy = 5;
    gBC.gridheight = 3;
    settings_BTN.setIcon(new ImageIcon(settings));
    settings_BTN.setMargin(new Insets(0, 0, 0, 0));
    settings_BTN.setHorizontalAlignment(SwingConstants.RIGHT);
    settings_BTN.setVerticalTextPosition(SwingConstants.CENTER);
    settings_BTN.setHorizontalTextPosition(SwingConstants.LEFT);
    settings_BTN.setBackground(Color.LIGHT_GRAY);
    settings_BTN.setBorderPainted(false);
    settings_BTN.setRolloverEnabled(false);
    settings_BTN.setFocusPainted(false);
    settings_BTN.setContentAreaFilled(false);
    bottomPanel.add(settings_BTN, gBC);

    // *****************************************SIXTH ROW (BLANK)
    blank = new JLabel("");
    gBC.gridx = 1;
    gBC.gridy = 5;
    bottomPanel.add(blank, gBC);

    // This makes sure all components are painted on the screen correctly
    mainPanel.validate();

    // ADD AN ACTION LISTENER TO THE BUTTON THAT WILL CHECK THE LOGIN INFO AND LOG INTO THE DATABASE
    login_BTN.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            String passwordHash = "";
            // Hash the password for comparison
            try {
              passwordHash = SimpleSHA1.SHA1(password_TF.getText());
            } catch (NoSuchAlgorithmException ex) {
              Logger.getLogger(EPoverty.class.getName()).log(Level.SEVERE, null, ex);
            } catch (UnsupportedEncodingException ex) {
              Logger.getLogger(EPoverty.class.getName()).log(Level.SEVERE, null, ex);
            }

            String checkAdminSQL =
                "SELECT p.password FROM persons AS p, admins AS a "
                    + "WHERE p.personId = a.personId "
                    + "AND p.emailAddress = \""
                    + login_TF.getText()
                    + "\" ";

            try {
              // *********************************CHECK LOGIN AND PASSWORD
              new DBconnection(url, driver, dbLogin, dbPassword);
              conn = DBconnection.getConnection();
              PreparedStatement stmt = (PreparedStatement) conn.prepareStatement(checkAdminSQL);
              ResultSet rs = (ResultSet) stmt.executeQuery();

              // IF THERE IS NO NEXT RECORD, E-MAIL IS NOT THAT OF AN ADMIN
              if (!rs.next()) {
                new Warnings("You do not have login rights.");
              } else {
                String dbPass = rs.getObject(1).toString();

                // CHECK VALUE OF RETURNED PASSWORD TO VALUE ENTERED
                if (dbPass.equals(passwordHash)) {
                  try {
                    new EPovertyMain();
                    EPovertyMain.updateStatus("Logged in");
                    dispose();

                  } catch (IOException ex) {
                    Logger.getLogger(EPoverty.class.getName()).log(Level.SEVERE, null, ex);
                  }
                } else {
                  new Warnings("Incorrect Password.");
                }
              }

              rs.close();
              stmt.close();
              DBconnection.closeConnection();

            } catch (ClassNotFoundException ex) {
              Logger.getLogger(EPoverty.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
              Logger.getLogger(EPoverty.class.getName()).log(Level.SEVERE, null, ex);
            }
          }
        }); // END OF LOGIN BUTTON LISTENER

    settings_BTN.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              new Settings();
            } catch (ClassNotFoundException ex) {
              Logger.getLogger(EPoverty.class.getName()).log(Level.SEVERE, null, ex);
            }
          }
        }); // END OF SETTINGS BUTTON LISTENER
  }