This code defines a class called "VeterinarianHospitalManagement" which is a...

December 8, 2023 at 02:49 AM

import javax.swing.*; import java.awt.*; import java.awt.event.ActionListener; import java.util.ArrayList; public class VeterinarianHospitalManagement { // Define the main frame and components private JFrame frame; private JPanel loginPanel, dashboardPanel; // Login Panel Components private JLabel lblUsername, lblPassword; private JTextField txtUsername; private JPasswordField txtPassword; private JButton btnLogin; // Dashboard Panel Components private JButton btnAddPet, btnDeletePet, btnSearchPet; private JTextArea txtPets; // List of pets private ArrayList<String> pets; public VeterinarianHospitalManagement() { // Initialize the main frame and components frame = new JFrame("Veterinary Hospital Management"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400, 300); frame.setLayout(new CardLayout()); // Create the login panel createLoginPanel(); // Create the dashboard panel createDashboardPanel(); // Add panels to the frame frame.add(loginPanel); frame.add(dashboardPanel); // Initialize the list of pets pets = new ArrayList<>(); } public void show() { frame.setVisible(true); } private void createLoginPanel() { loginPanel = new JPanel(); lblUsername = new JLabel("Username:"); lblPassword = new JLabel("Password:"); txtUsername = new JTextField(20); txtPassword = new JPasswordField(20); btnLogin = new JButton("Login"); loginPanel.setLayout(new BorderLayout()); JPanel formPanel = new JPanel(new GridLayout(2, 2)); formPanel.add(lblUsername); formPanel.add(txtUsername); formPanel.add(lblPassword); formPanel.add(txtPassword); JPanel btnPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); btnPanel.add(btnLogin); loginPanel.add(formPanel, BorderLayout.CENTER); loginPanel.add(btnPanel, BorderLayout.SOUTH); } private void createDashboardPanel() { dashboardPanel = new JPanel(); btnAddPet = new JButton("Add Pet"); btnDeletePet = new JButton("Delete Pet"); btnSearchPet = new JButton("Search Pet"); txtPets = new JTextArea(10, 30); txtPets.setEditable(false); JScrollPane scrollPane = new JScrollPane(txtPets); dashboardPanel.setLayout(new BorderLayout()); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); buttonPanel.add(btnAddPet); buttonPanel.add(btnDeletePet); buttonPanel.add(btnSearchPet); dashboardPanel.add(scrollPane, BorderLayout.CENTER); dashboardPanel.add(buttonPanel, BorderLayout.SOUTH); } public void addPet(String pet) { pets.add(pet); updatePetsList(); } public void deletePet(String pet) { pets.remove(pet); updatePetsList(); } public String searchPet(String pet) { String result = ""; for (String p : pets) { if (p.equalsIgnoreCase(pet)) { result = p; break; } } return result; } private void updatePetsList() { txtPets.setText(""); for (String pet : pets) { txtPets.append(pet + "\n"); } } public void setLoginButtonListener(ActionListener listener) { btnLogin.addActionListener(listener); } public void setAddPetButtonListener(ActionListener listener) { btnAddPet.addActionListener(listener); } public void setDeletePetButtonListener(ActionListener listener) { btnDeletePet.addActionListener(listener); } public void setSearchPetButtonListener(ActionListener listener) { btnSearchPet.addActionListener(listener); } public String getUsername() { return txtUsername.getText(); } public String getPassword() { return new String(txtPassword.getPassword()); } public void clearUsername() { txtUsername.setText(""); } public void clearPassword() { txtPassword.setText(""); } public void showMessage(String message) { JOptionPane.showMessageDialog(frame, message); } }

This code defines a class called "VeterinarianHospitalManagement" which is a GUI application for managing a veterinary hospital.

The code imports necessary packages and libraries for GUI components and event handling.

The class has instance variables for the main frame and panels, as well as components for the login panel and dashboard panel.

The login panel contains labels, text fields for username and password, and a login button.

The dashboard panel contains buttons for adding, deleting, and searching pets, as well as a text area for displaying a list of pets.

There is also an ArrayList to store the list of pets.

The class has methods for creating the login panel and dashboard panel, adding, deleting, and searching pets, updating the list of pets, setting button listeners, getting username and password, clearing the username and password fields, and showing messages using JOptionPane.

The class also has a main method that creates an instance of the class and shows the GUI.

Generate your own explanations
Download our vscode extension
Read other generated explanations

Built by @thebuilderjr
Sponsored by beam analytics
Read our terms and privacy policy
Forked from openai-quickstart-node