0% found this document useful (0 votes)
222 views

Assa

This Java code defines a PayrollSystem class that creates a login frame with username and password fields. It checks the credentials and opens a main menu frame if authenticated. The main menu frame contains File and Employees Data menus, with menu items for adding, editing and deleting employees, though the functionality is not yet implemented. The code sets up the login and main menu frames with Swing components and basic event handling.

Uploaded by

anushka patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
222 views

Assa

This Java code defines a PayrollSystem class that creates a login frame with username and password fields. It checks the credentials and opens a main menu frame if authenticated. The main menu frame contains File and Employees Data menus, with menu items for adding, editing and deleting employees, though the functionality is not yet implemented. The code sets up the login and main menu frames with Swing components and basic event handling.

Uploaded by

anushka patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

import javax.swing.

*;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

public class PayrollSystem extends JFrame {

private JTextField usernameField;

private JPasswordField passwordField;

public PayrollSystem() {

// Login Frame

setTitle("Login");

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setSize(300, 150);

setLocationRelativeTo(null);

JPanel loginPanel = new JPanel(new GridLayout(3, 2, 10, 10));

loginPanel.add(new JLabel("Username:"));

usernameField = new JTextField();

loginPanel.add(usernameField);

loginPanel.add(new JLabel("Password:"));
passwordField = new JPasswordField();

loginPanel.add(passwordField);

JButton loginButton = new JButton("Login");

loginButton.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

login();

});

loginPanel.add(loginButton);

add(loginPanel);

setVisible(true);

private void login() {

// Implement your authentication logic here

// For simplicity, let's assume username=admin and password=admin

String username = usernameField.getText();

char[] passwordChars = passwordField.getPassword();

String password = new String(passwordChars);

if ("admin".equals(username) && "admin".equals(password)) {


openMainMenu();

} else {

JOptionPane.showMessageDialog(this, "Invalid username or password", "Login Failed",


JOptionPane.ERROR_MESSAGE);

// Clear password field for security

passwordField.setText("");

private void openMainMenu() {

// Destroy login frame and create main menu

dispose();

JFrame mainMenuFrame = new JFrame("Payroll Management System");

mainMenuFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

mainMenuFrame.setSize(500, 300);

mainMenuFrame.setLocationRelativeTo(null);

JMenuBar menuBar = new JMenuBar();

mainMenuFrame.setJMenuBar(menuBar);

JMenu fileMenu = new JMenu("File");

JMenuItem exitMenuItem = new JMenuItem("Exit");

exitMenuItem.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {

System.exit(0);

});

fileMenu.add(exitMenuItem);

menuBar.add(fileMenu);

JMenu employeesMenu = new JMenu("Employees Data");

JMenuItem addEmployeeMenuItem = new JMenuItem("Add Employee");

JMenuItem editEmployeeMenuItem = new JMenuItem("Edit Employee");

JMenuItem deleteEmployeeMenuItem = new JMenuItem("Delete Employee");

addEmployeeMenuItem.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

// Implement add employee functionality

JOptionPane.showMessageDialog(mainMenuFrame, "Add Employee functionality to be


implemented");

});

editEmployeeMenuItem.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

// Implement edit employee functionality


JOptionPane.showMessageDialog(mainMenuFrame, "Edit Employee functionality to be
implemented");

});

deleteEmployeeMenuItem.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

// Implement delete employee functionality

JOptionPane.showMessageDialog(mainMenuFrame, "Delete Employee functionality to be


implemented");

});

employeesMenu.add(addEmployeeMenuItem);

employeesMenu.add(editEmployeeMenuItem);

employeesMenu.add(deleteEmployeeMenuItem);

menuBar.add(employeesMenu);

mainMenuFrame.setVisible(true);

public static void main(String[] args) {

SwingUtilities.invokeLater(new Runnable() {

@Override

public void run() {


new PayrollSystem();

});

You might also like