Staff Attendance Details

Login

Above UI we are going to create by Awt for Staff Attendance Details Window in our Attendance Management System desktop application. For that first we create a window and configure its title, size and color. Here we are creating a window at Top Level so we can add this window at the top of any other window.

    
        
        dashboardFrame = new JFrame();
	    Utils.centeredFrame(dashboardFrame, windowWidth, windowHeight, "Staff Attendence Details");
        Container frameContainer = dashboardFrame.getContentPane();
		frameContainer.setBackground(Color.gray);

		int containerWidth = windowWidth * 94 / 100;
		int containerHeight = windowHeight * 90 / 100;

		int panelWidth = containerWidth * 98 / 100;
		int panelHeight = containerHeight * 96 / 100;
		int posX = windowWidth / 2 - panelWidth / 2 - frameControllerSize / 5;
		int posY = windowHeight / 2 - panelHeight / 2 - frameControllerSize / 2;

		// frame without control options
		JPanel panel = new JPanel();
		panel.setLayout(null);
		panel.setBackground(Color.decode("#FFFFFF"));
		panel.setSize(new Dimension(panelWidth, panelHeight));
		panel.setLocation(posX, posY);
		frameContainer.add(panel);

		// for Rounded Background
		posX = windowWidth / 2 - containerWidth / 2 - frameControllerSize / 5;
		posY = windowHeight / 2 - containerHeight / 2 - frameControllerSize / 2;
		JComponent jcomponent = new Background(posX, posY, containerWidth, containerHeight);
		jcomponent.setLayout(null);
		frameContainer.add(jcomponent, BorderLayout.CENTER);

    

Here we create heading Labels.

    
        // for heading Layout
		posY = panelHeight * 2 / 100;
		Font headingFont = new Font("Serif", Font.PLAIN, 30);
		// header
		// borderline = BorderFactory.createLineBorder(Color.black);

		JLabel heading_text = new JLabel("Staff Attendance Details");
		heading_text.setHorizontalAlignment(JLabel.CENTER);
		heading_text.setVerticalAlignment(JLabel.CENTER);
		heading_text.setBackground(Color.decode("#80c2b2"));
		heading_text.setForeground(Color.black);
		heading_text.setFont(headingFont);
		heading_text.setBounds(0, 0, panelWidth, panelHeight / 9);
		panel.add(heading_text);

		panel.add(Utils.getSeparator(0, panelHeight / 7, panelWidth, 5, "000000"));

		JPanel leftside = Utils.createPanel(panelWidth, panelHeight * 83 / 100, new Point(0, panelHeight / 6), true,
				"Attendance");
		panel.add(leftside, BorderLayout.CENTER);
		leftside.setLayout(null);
		
		search = new JLabel();
		search.setText("Staff Id : " + selectedStaffDetailsList1.get(0).getId());
		search.setForeground(Color.black);
		search.setFont(new Font("Lucida", Font.PLAIN, 18));
		search.setSize(new Dimension(panelWidth / 3, panelHeight / 10));
		search.setLocation(30, 20);
		leftside.add(search);

    

here we create our table.

    
        table = new JTable();
		displaylistToTable(table, selectedStaffDetailsList1);
		table.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

		JTableHeader tableHeader21 = table.getTableHeader();
		tableHeader21.setDefaultRenderer(new KeepSortIconHeaderRenderer(tableHeader21.getDefaultRenderer()));

		JScrollPane pane = new JScrollPane(table);
		pane.setLocation(30, panelHeight / 7 + panelHeight / 70);
		pane.setSize(new Dimension(panelWidth - 60, panelHeight * 6 / 10));
		leftside.add(pane);
		table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
			public void valueChanged(ListSelectionEvent event) {

				ArrayList selectedStaffDetailsList = getSelectedStaffDetails(
						table.getValueAt(table.getSelectedRow(), 0).toString());

				if (selectedStaffDetailsList.isEmpty()) {
					JOptionPane.showMessageDialog(dashboardFrame, "No Data Found");
				} else {

				}

			}
		});

		dashboardFrame.setVisible(true);
		panel.revalidate();
		panel.repaint();
    

After table creation we fetch data from database.

    
public void displaylistToTable(JTable table, ArrayList productList) {

    defaultdataModel = new DefaultTableModel();

    Object[] row = new Object[4];

    defaultdataModel.setColumnIdentifiers(new Object[] { "Staff Id", "Staff Name", "Status", "Date", });

    for (int i = 0; i < productList.size(); i++) {

        row[0] = productList.get(i).getId();
        row[1] = productList.get(i).getStaffName();
        row[2] = productList.get(i).getStatus();
        row[3] = productList.get(i).getDateString();

        defaultdataModel.addRow(row);

    }
    defaultdataModel.isCellEditable(0, 0);

    table.setModel(defaultdataModel);
    DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
    centerRenderer.setHorizontalAlignment(JLabel.CENTER);
    table.getColumnModel().getColumn(0).setCellRenderer(centerRenderer);
    table.getColumnModel().getColumn(1).setCellRenderer(centerRenderer);
    table.getColumnModel().getColumn(2).setCellRenderer(centerRenderer);
    table.getColumnModel().getColumn(3).setCellRenderer(centerRenderer);

    table.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    table.setRowHeight(30);

    }


    

At last we will manage closing of window

    
    dashboardFrame.addWindowListener(new java.awt.event.WindowAdapter() {
			@Override
			public void windowClosing(java.awt.event.WindowEvent windowEvent) {
				dashboardFrame.dispose();
				staffAttendanceFrame.setVisible(true);
			}
		});
                       

Programmer Mirta is for learning and training. Projects might be simple to improve learning. Projects are constantly reviewed to avoid errors, but we cannot assure full correctness of all content. While using Programmer Mitra, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 2021 by Programmer Mitra. All Rights Reserved.