Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

//This is a Java Netbeans GUI App with ERRORS..cannot figure out 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;

//This is a Java Netbeans GUI App with ERRORS..cannot figure out

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

Students also viewed these Databases questions

Question

What are 3 resources, 3 capabilities and 2 priorities of Samsung?

Answered: 1 week ago

Question

What is Centrifugation?

Answered: 1 week ago

Question

To find integral of ?a 2 - x 2

Answered: 1 week ago

Question

To find integral of e 3x sin4x

Answered: 1 week ago

Question

To find the integral of 3x/(x - 1)(x - 2)(x - 3)

Answered: 1 week ago

Question

What are Fatty acids?

Answered: 1 week ago