Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you please correct this java netbeans code? package com.mycompany.newassign; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import

Can you please correct this java netbeans code?

package com.mycompany.newassign;

import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList;

import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JTextField;

public class NewAssign extends JFrame {

private JLabel nicLabel; private JTextField nicTextField; private JLabel firstNameLabel; private JTextField firstNameTextField; private JLabel lastNameLabel; private JTextField lastNameTextField; private JLabel ageLabel; private JTextField ageTextField; private JButton saveButton; private JButton searchButton; private JTextField searchTextField; private ArrayList staffList;

public NewAssign() { super("Staff Details"); setLayout(new FlowLayout());

nicLabel = new JLabel("NIC"); add(nicLabel);

nicTextField = new JTextField(20); add(nicTextField);

firstNameLabel = new JLabel("First Name"); add(firstNameLabel);

firstNameTextField = new JTextField(20); add(firstNameTextField);

lastNameLabel = new JLabel("Last Name"); add(lastNameLabel);

lastNameTextField = new JTextField(20); add(lastNameTextField);

ageLabel = new JLabel("Age"); add(ageLabel);

ageTextField = new JTextField(20); add(ageTextField);

saveButton = new JButton("Save"); add(saveButton);

searchTextField = new JTextField(20); add(searchTextField);

searchButton = new JButton("Search"); add(searchButton);

staffList = new ArrayList();

saveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String nic = nicTextField.getText(); String firstName = firstNameTextField.getText(); String lastName = lastNameTextField.getText(); int age = Integer.parseInt(ageTextField.getText()); staffList.add(new Staff(nic, firstName, lastName, age)); JOptionPane.showMessageDialog(null, "Staff details saved!"); } });

searchButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String searchNIC = searchTextField.getText(); boolean found = false; for (Staff staff : staffList) { if (staff.getNic().equals(searchNIC)) { JOptionPane.showMessageDialog(null, "NIC: " + staff.getNic() + " First Name: " + staff.getFirstName() + " Last Name: "); nic().equals(searchNIC)) { JOptionPane.showMessageDialog(null, "NIC: " + staff.getNic() + " First Name: " + staff.getFirstName() + " Last Name: " + staff.getLastName() + " Age: " + staff.getAge()); found = true; break; } } if (!found) { JOptionPane.showMessageDialog(null, "Staff not found!"); } } }

public static void main(String[] args) { new NewAssign(); }

class Staff { private String nic; private String firstName; private String lastName; private int age;

public Staff(String nic, String firstName, String lastName, int age) { this.nic = nic; this.firstName = firstName; this.lastName = lastName; this.age = age; }

public String getNic() { return nic; }

public void setNic(String nic) { this.nic = nic; }

public String getFirstName() { return firstName; }

public void setFirstName(String firstName) { this.firstName = firstName; }

public String getLastName() { return lastName; }

public void setLastName(String lastName) { this.lastName = lastName; }

public int getAge() { return age; }

public void setAge(int age) { this.age = age; } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications 15th International Conference Dasfaa 2010 International Workshops Gdm Benchmarx Mcis Snsmw Diew Udm Tsukuba Japan April 2010 Revised Selected Papers Lncs 6193

Authors: Masatoshi Yoshikawa ,Xiaofeng Meng ,Takayuki Yumoto ,Qiang Ma ,Lifeng Sun ,Chiemi Watanabe

2010th Edition

3642145884, 978-3642145889

More Books

Students also viewed these Databases questions