SlideShare a Scribd company logo
1 of 11
Download to read offline
1. Section1.- Populating the list of persons on the person listing form, and put functionality in the
Add Person button (1 mark)
a. In PersonListing: The starting code places only one item in the list of persons. Discussions
with the original developer have yielded that the method showTable in PersonListing is
responsible for populating the table. The addToTable method which accepts one person and adds
information regarding that person to the table should NOT be modified. Complete showTable so
that an entry is placed in the table for each row in the file person.dat.
b. In PersonEntry: Modify PersonEntry so that it is able to store an instance of PersonListing.
c. In PersonEntry: Modify the Constructor of PersonEntry so that it accepts an instance of
PersonListing, and then sets the local instance variable to the value accepted by the constructor.
d. In PersonListing: Add a listener to the Add Person button so that when it is clicked, an
instance of PersonEntry is displayed. When invoking the instance of PersonEntry, a reference to
the current instance of PersonListing should be passed as an argument to the constructor. //Hint a
listener is already included in the starting code that adds functionality to the Close button.
2. Section 2. Implementing functionality in the PersonEntry. (1.5 marks)
a. Modify the PersonEntry object so that the interface looks like that presented in Figure 3
Hints:
i. You may need to add a JLabel and a JCheckBox
ii. The layout from the previous developer for the panel displays data on two rows.
b. Add functionality to the Close button of the PersonEntry form so that it is no longer visible
when it is clicked.
Hint: one way to do it is to
i. Store a reference to a PersonEntry as an instance variable
ii. Set the instance of PersonEntry to this in the constructor
iii. In the appropriate listener, invoke setVisible on the instance of PersonEntry with an
argument of false.
c. Implement functionality in the Save button of PersonEntry so that when it is clicked, the data
is first validated to ensure both first and last names have been entered, and that the age is
an integer. If data is valid, the addPerson method of PersonListing is called, and the person
entry form disappears. Note that the addPerson method effectively adds a person to
the arraylist holding person list data, and updates the data in the list.
Hints/Questions
i. Have we already met a method to split a string into parts?
ii. What functionality can tell if a value can be converted to an Integer?
iii. Remember the getText() method of a jTextField returns the value of the text it currently
displays.
3. Section 3 Complete functionality on listing screen (1.5 marks)
a. The starting code includes the definition of a JButton named cmdSortAge, but it is not
shown on the PersonListing screen. Modify the PersonListingScreen to allow it to be shown
b. Add a listener which implements the functionality to sort the list in ascending order of age.
Hints:
i. You should already know how to sort data
ii. Presenting information in a specific order in the table may involve removing all the data
and then re-adding it iii. Data in the table is removed with the command
model.setRowCount(0);- model is an object name that was declared with the starting code. Ie.
model is an object of the class DefaultTableModel.
c. Add a button and an associated listener to sort the list in order of first name .
4. Change the colors of the form to implement a custom colour scheme. (1 mark) Figure 4
shows an example of a custom colour scheme. You should come up with your own and then set
the colours on the Person Listing screen appropriately.
starter code:
public abstract class BasePerson {
protected String name;
private boolean publish;
private int age;
private int id;
public BasePerson(String name,int age, boolean pub)
{
this.name =name;
this.age=age;
publish = pub;
}
public int getAge()
{
return age;
}
public abstract String getName();
protected void setId(int id)
{
this.id = id;
}
public int getId()
{
return id;
}
public boolean getPublish()
{
return publish;
}
}
public class Person extends BasePerson implements Comparable
{
private static int nextId=0;
public Person(String name, int age, boolean willPublish)
{
super(name, age, willPublish);
super.setId(nextId);
nextId++;
}
public String getName()
{
return name;
}
public static String getPHeader()
{
String returnval = "IDtNametAgetWillPublish";
returnval+="n---------------------------------";
return returnval;
}
public String toString()
{
return(getId()+"t"+getName()+"t"+getAge()+"t"+getPublish());
}
public static void resetId()
{
nextId=0;
}
public int compareTo(Person other)
{
return other.getId() - this.getId();
}
}
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class PersonEntry extends JFrame
{
private JTextField txtName; //name
private JTextField txtAge; //age
private JButton cmdSave;
private JButton cmdClose;
private JButton cmdClearAll;
private JPanel pnlCommand;
private JPanel pnlDisplay;
public PersonEntry()
{
setTitle("Entering new person");
pnlCommand = new JPanel();
pnlDisplay = new JPanel();
pnlDisplay.add(new JLabel("Name:"));
txtName = new JTextField(20);
pnlDisplay.add(txtName);
pnlDisplay.add(new JLabel("Age:"));
txtAge = new JTextField(3);
pnlDisplay.add(txtAge);
pnlDisplay.setLayout(new GridLayout(2,4));
cmdSave = new JButton("Save");
cmdClose = new JButton("Close");
pnlCommand.add(cmdSave);
pnlCommand.add(cmdClose);
add(pnlDisplay, BorderLayout.CENTER);
add(pnlCommand, BorderLayout.SOUTH);
pack();
setVisible(true);
}
}
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Scanner;
import java.util.ArrayList;
import java.io.File;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.table.*;
import javax.swing.table.DefaultTableModel;
import java.util.Comparator;
import java.util.Collections;
import java.awt.Color;
public class PersonListing extends JPanel {
private JButton cmdAddPerson;
private JButton cmdClose;
private JButton cmdSortAge;
private JPanel pnlCommand;
private JPanel pnlDisplay;
private ArrayList plist;
private PersonListing thisForm;
private JScrollPane scrollPane;
private JTable table;
private DefaultTableModel model;
public PersonListing() {
super(new GridLayout(2,1));
thisForm = this;
pnlCommand = new JPanel();
pnlDisplay = new JPanel();
plist= loadPersons("person.dat");
String[] columnNames= {"First Name",
"Last Name",
"Age",
"Will Publish"};
model=new DefaultTableModel(columnNames,0);
table = new JTable(model);
showTable(plist);
table.setPreferredScrollableViewportSize(new Dimension(500, plist.size()*15 +50));
table.setFillsViewportHeight(true);
scrollPane = new JScrollPane(table);
add(scrollPane);
cmdAddPerson = new JButton("Add Person");
cmdSortAge = new JButton("Sort by Age");
cmdClose = new JButton("Close");
cmdClose.addActionListener(new CloseButtonListener());
pnlCommand.add(cmdAddPerson);
pnlCommand.add(cmdClose);
add(pnlCommand);
}
private void showTable(ArrayList plist)
{
if (plist.size()>0)
addToTable(plist.get(0));
}
private void addToTable(Person p)
{
String[] name= p.getName().split(" ");
String[] item={name[0],name[1],""+ p.getAge(),""+p.getPublish()};
model.addRow(item);
}
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("List of persons who are requesting a vaccine");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
PersonListing newContentPane = new PersonListing();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);
//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
public void addPerson(Person p)
{
plist.add(p);
addToTable(p);
}
private ArrayList loadPersons(String pfile)
{
Scanner pscan = null;
ArrayList plist = new ArrayList();
try
{
pscan = new Scanner(new File(pfile));
while(pscan.hasNext())
{
String [] nextLine = pscan.nextLine().split(" ");
String name = nextLine[0]+ " " + nextLine[1];
int age = Integer.parseInt(nextLine[2]);
boolean publish = false;
if (nextLine[3].equals("0"))
publish = false;
else
publish =true;
Person p = new Person(name, age, publish);
plist.add(p);
}
pscan.close();
}
catch(IOException e)
{}
return plist;
}
private class CloseButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0); }
}
Please help its due tomorrow could u write the code where it should be in the starter code? After
the initial deployment of Vaccinator Prime(see Lab 5 description), it has become evident that a
large number of users may need to interact with the person registration process on the front lines.
As a result it has been decided that a GUI is needed for that part of the system. Your immediate
tasks are 1. to complete a prototype that demonstrates basic functionality of displaying a list of
persons, adding a person and sorting the list as required, and 2. then describe the effort required
to implement a fully functional CRUD (Create/Read/Update/Delete) application. Your entry
point to the project comes at a time when a junior developer has completed a basic mockup of
the appearance of the system, which has been approved by top management. Specific objectives
of the lab are: - Integrating a GUI with an application - Adding components to a GUI - Writing
listeners for GUI components NON-FUNCTIONAL ASSESSMENT CRITERIA
LAB EXERCISES (5 MARKS FOR DEMONSTRATED FUNCTIONALITY) Java code for
four classes are provided. The classes are: - BasePerson:Abstract person class - Exact replica of
class used as a starter code for Lab 5 - Person: Defines a person - Exact replica of class used as a
starter code for Lab 5 - PersonListing: Starter code for screen that should list persons -
PersonEntry : Starter code for a screen that should allow entry into the list of persons. Please
download these classes and load them into a project for this lab. Spend a few moments to get
acquainted with the code. PersonListing.java exposes a public static main method that presents
the screen shown in Figure 1. In addition, PersonListing.java also includes several attributes and
methods that are used to implement basic functionality, some of which are presented in Table 1.
Figure 1 Person Listing Screen
Figure 2. Result of executing starting code for PersonEntry. RADEABLE ACTIVITIES 1.
Section1.- Populating the list of persons on the person listing form, and put functionality in the
"Add Person" button (1 mark) a. In PersonListing: The starting code places only one item in the
list of persons. Discussions with the original developer have yielded that the method
"showTable" in PersonListing is responsible for populating the table. The addToTable method
which accepts one person and adds information regarding that person to the table should NOT be
modified. Complete showTable so that an entry is placed in the table for each row in the file
person.dat. b. In PersonEntry: Modify PersonEntry so that it is able to store an instance of
PersonListing. c. In PersonEntry: Modify the Constructor of PersonEntry so that it accepts an
instance of PersonListing, and then sets the local instance variable to the value accepted by the
constructor. d. In PersonListing: Add a listener to the "Add Person" button so that when it is
clicked, an instance of PersonEntry is displayed. When invoking the instance of PersonEntry, a
reference to the current instance of PersonListing should be passed as an argument to the
constructor. //Hint... a listener is already included in the starting code that adds functionality to
the Close button. 2. Section 2. Implementing functionality in the PersonEntry. (1.5 marks) a.
Modify the PersonEntry object so that the interface looks like that presented in Figure 3 Figure
3.Expected Appearance of Person Entry Screen Hints: i. You may need to add a JLabel and a
JCheckBox ii. The layout from the previous developer for the panel displays data on two rows. b.
Add functionality to the Close button of the PersonEntry form so that it is no longer visible when
it is clicked. Hint: one way to do it is to i. Store a reference to a PersonEntry as an instance
variable ii. Set the instance of PersonEntry to this in the constructor
iii. In the appropriate listener, invoke setVisible on the instance of PersonEntry with an argument
of false. c. Implement functionality in the Save button of PersonEntry so that when it is clicked,
the data is first validated to ensure both first and last names have been entered, and that the age is
an integer. If data is valid, the addPerson method of PersonListing is called, and the person entry
form disappears. Note that the addPerson method effectively adds a person to the arraylist
holding person list data, and updates the data in the list. Hints/Questions i. Have we already met
a method to split a string into parts? ii. What functionality can tell if a value can be converted to
an Integer? iii. Remember the get Text0 method of a jTextField returns the value of the text it
currently displays. 3. Section 3 - Complete functionality on listing screen (1.5 marks) a. The
starting code includes the definition of a JButton named cmdSortAge, but it is not shown on the
PersonListing screen. Modify the PersonListingScreen to allow it to be shown b. Add a listener
which implements the functionality to sort the list in ascending order of age. Hints: i. You should
already know how to sort data ii. Presenting information in a specific order in the table may
involve removing all the data and then re-adding it iii. Data in the table is removed with the
command modelsetRowCount(0); model is an object name that was declared with the starting
code. le. model is an object of the class DefaultTableModel c. Add a button and an associated
listener to sort the list in order of first name. 4. Change the colors of the form to implement a
custom colour scheme. (1 mark) Figure 4 shows an example of a custom colour scheme. You
should come up with your own and then set the colours on the Person Listing screen
appropriately. Figure 4. An example of a custom color scheme after two more persons have been
entered, sorted in order of age. 5. Compress the .java files into a .zip and submit to OurVLE.

More Related Content

Similar to 1. Section1.- Populating the list of persons on the person listing f.pdf

Cis 407 i lab 4 of 7
Cis 407 i lab 4 of 7Cis 407 i lab 4 of 7
Cis 407 i lab 4 of 7helpido9
 
I need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdfI need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdffantoosh1
 
project2.classpathproject2.project project2 .docx
project2.classpathproject2.project  project2 .docxproject2.classpathproject2.project  project2 .docx
project2.classpathproject2.project project2 .docxbriancrawford30935
 
This is a java lab assignment. I have added the first part java re.pdf
This is a java lab assignment. I have added the first part java re.pdfThis is a java lab assignment. I have added the first part java re.pdf
This is a java lab assignment. I have added the first part java re.pdffeetshoemart
 
So Far I have these two classes but I need help with my persontest c.pdf
So Far I have these two classes but I need help with my persontest c.pdfSo Far I have these two classes but I need help with my persontest c.pdf
So Far I have these two classes but I need help with my persontest c.pdfarihantgiftgallery
 
Having a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdfHaving a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdfNicholasflqStewartl
 
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdfThis is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdfjillisacebi75827
 
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdfAssignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdfformicreation
 
Collections 1 Insert an element at desired location Take th.pdf
Collections 1 Insert an element at desired location Take th.pdfCollections 1 Insert an element at desired location Take th.pdf
Collections 1 Insert an element at desired location Take th.pdfaggarwalcollection1
 
Needs to be solved with Visual C# from the book Starting oout .pdf
Needs to be solved with Visual C# from the book Starting oout .pdfNeeds to be solved with Visual C# from the book Starting oout .pdf
Needs to be solved with Visual C# from the book Starting oout .pdffoottraders
 
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfNeed done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfinfo114
 
please code in c#- please note that im a complete beginner- northwind.docx
please code in c#- please note that im a complete beginner-  northwind.docxplease code in c#- please note that im a complete beginner-  northwind.docx
please code in c#- please note that im a complete beginner- northwind.docxAustinaGRPaigey
 
define a class name Employee whose objects are records for employee..pdf
define a class name Employee whose objects are records for employee..pdfdefine a class name Employee whose objects are records for employee..pdf
define a class name Employee whose objects are records for employee..pdffashioncollection2
 
Creating a Facebook Clone - Part X - Transcript.pdf
Creating a Facebook Clone - Part X - Transcript.pdfCreating a Facebook Clone - Part X - Transcript.pdf
Creating a Facebook Clone - Part X - Transcript.pdfShaiAlmog1
 
PLEASE HELP IN C++For this test, you will need to create the follo.pdf
PLEASE HELP IN C++For this test, you will need to create the follo.pdfPLEASE HELP IN C++For this test, you will need to create the follo.pdf
PLEASE HELP IN C++For this test, you will need to create the follo.pdfaioils
 
Adapt your code from Assignment 2 to use both a Java API ArrayList a.pdf
Adapt your code from Assignment 2 to use both a Java API ArrayList a.pdfAdapt your code from Assignment 2 to use both a Java API ArrayList a.pdf
Adapt your code from Assignment 2 to use both a Java API ArrayList a.pdfalbarefqc
 

Similar to 1. Section1.- Populating the list of persons on the person listing f.pdf (20)

Cis 407 i lab 4 of 7
Cis 407 i lab 4 of 7Cis 407 i lab 4 of 7
Cis 407 i lab 4 of 7
 
I need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdfI need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdf
 
project2.classpathproject2.project project2 .docx
project2.classpathproject2.project  project2 .docxproject2.classpathproject2.project  project2 .docx
project2.classpathproject2.project project2 .docx
 
This is a java lab assignment. I have added the first part java re.pdf
This is a java lab assignment. I have added the first part java re.pdfThis is a java lab assignment. I have added the first part java re.pdf
This is a java lab assignment. I have added the first part java re.pdf
 
So Far I have these two classes but I need help with my persontest c.pdf
So Far I have these two classes but I need help with my persontest c.pdfSo Far I have these two classes but I need help with my persontest c.pdf
So Far I have these two classes but I need help with my persontest c.pdf
 
Tutorial 6.docx
Tutorial 6.docxTutorial 6.docx
Tutorial 6.docx
 
Having a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdfHaving a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdf
 
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdfThis is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
 
Oop lecture8
Oop lecture8Oop lecture8
Oop lecture8
 
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdfAssignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
 
01 list using array
01 list using array01 list using array
01 list using array
 
Collections 1 Insert an element at desired location Take th.pdf
Collections 1 Insert an element at desired location Take th.pdfCollections 1 Insert an element at desired location Take th.pdf
Collections 1 Insert an element at desired location Take th.pdf
 
Needs to be solved with Visual C# from the book Starting oout .pdf
Needs to be solved with Visual C# from the book Starting oout .pdfNeeds to be solved with Visual C# from the book Starting oout .pdf
Needs to be solved with Visual C# from the book Starting oout .pdf
 
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfNeed done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
 
please code in c#- please note that im a complete beginner- northwind.docx
please code in c#- please note that im a complete beginner-  northwind.docxplease code in c#- please note that im a complete beginner-  northwind.docx
please code in c#- please note that im a complete beginner- northwind.docx
 
define a class name Employee whose objects are records for employee..pdf
define a class name Employee whose objects are records for employee..pdfdefine a class name Employee whose objects are records for employee..pdf
define a class name Employee whose objects are records for employee..pdf
 
Creating a Facebook Clone - Part X - Transcript.pdf
Creating a Facebook Clone - Part X - Transcript.pdfCreating a Facebook Clone - Part X - Transcript.pdf
Creating a Facebook Clone - Part X - Transcript.pdf
 
Dotnet 18
Dotnet 18Dotnet 18
Dotnet 18
 
PLEASE HELP IN C++For this test, you will need to create the follo.pdf
PLEASE HELP IN C++For this test, you will need to create the follo.pdfPLEASE HELP IN C++For this test, you will need to create the follo.pdf
PLEASE HELP IN C++For this test, you will need to create the follo.pdf
 
Adapt your code from Assignment 2 to use both a Java API ArrayList a.pdf
Adapt your code from Assignment 2 to use both a Java API ArrayList a.pdfAdapt your code from Assignment 2 to use both a Java API ArrayList a.pdf
Adapt your code from Assignment 2 to use both a Java API ArrayList a.pdf
 

More from aniljain719651

1. THE UNITED STATES has all biomes except ____.Group of answer ch.pdf
1. THE UNITED STATES has all biomes except ____.Group of answer ch.pdf1. THE UNITED STATES has all biomes except ____.Group of answer ch.pdf
1. THE UNITED STATES has all biomes except ____.Group of answer ch.pdfaniljain719651
 
1. The market reacted poorly to Credit Suisses announcement regardi.pdf
1. The market reacted poorly to Credit Suisses announcement regardi.pdf1. The market reacted poorly to Credit Suisses announcement regardi.pdf
1. The market reacted poorly to Credit Suisses announcement regardi.pdfaniljain719651
 
1. The information and material that forms the heart of your project.pdf
1. The information and material that forms the heart of your project.pdf1. The information and material that forms the heart of your project.pdf
1. The information and material that forms the heart of your project.pdfaniljain719651
 
1. Scope Objectives of IBM�s Stretch Project (IBM 7030) detail- .pdf
1. Scope Objectives of IBM�s Stretch Project (IBM 7030) detail- .pdf1. Scope Objectives of IBM�s Stretch Project (IBM 7030) detail- .pdf
1. Scope Objectives of IBM�s Stretch Project (IBM 7030) detail- .pdfaniljain719651
 
1. Suppose two people, Jake and Jill, have different prior beliefs a.pdf
1. Suppose two people, Jake and Jill, have different prior beliefs a.pdf1. Suppose two people, Jake and Jill, have different prior beliefs a.pdf
1. Suppose two people, Jake and Jill, have different prior beliefs a.pdfaniljain719651
 
1. Rara vez se utilizan equipos multifuncionales para desarrollar un.pdf
1. Rara vez se utilizan equipos multifuncionales para desarrollar un.pdf1. Rara vez se utilizan equipos multifuncionales para desarrollar un.pdf
1. Rara vez se utilizan equipos multifuncionales para desarrollar un.pdfaniljain719651
 
1. Si el candidato de un presidente a la Corte Suprema es un constru.pdf
1. Si el candidato de un presidente a la Corte Suprema es un constru.pdf1. Si el candidato de un presidente a la Corte Suprema es un constru.pdf
1. Si el candidato de un presidente a la Corte Suprema es un constru.pdfaniljain719651
 
1. Sulfate- or sulfur-reducing bacteria would most likely be found i.pdf
1. Sulfate- or sulfur-reducing bacteria would most likely be found i.pdf1. Sulfate- or sulfur-reducing bacteria would most likely be found i.pdf
1. Sulfate- or sulfur-reducing bacteria would most likely be found i.pdfaniljain719651
 
1. Sketch a kinetics curve for the movement of lactose into E. coli .pdf
1. Sketch a kinetics curve for the movement of lactose into E. coli .pdf1. Sketch a kinetics curve for the movement of lactose into E. coli .pdf
1. Sketch a kinetics curve for the movement of lactose into E. coli .pdfaniljain719651
 
1. Seg�n la hip�tesis m�s aceptada, el origen del genoma nuclear inv.pdf
1. Seg�n la hip�tesis m�s aceptada, el origen del genoma nuclear inv.pdf1. Seg�n la hip�tesis m�s aceptada, el origen del genoma nuclear inv.pdf
1. Seg�n la hip�tesis m�s aceptada, el origen del genoma nuclear inv.pdfaniljain719651
 
1. Seg�n Darwin, si un grupo muestra un comportamiento m�s moral que.pdf
1. Seg�n Darwin, si un grupo muestra un comportamiento m�s moral que.pdf1. Seg�n Darwin, si un grupo muestra un comportamiento m�s moral que.pdf
1. Seg�n Darwin, si un grupo muestra un comportamiento m�s moral que.pdfaniljain719651
 
1. Section1.- Populating the list of persons on the person listing.pdf
1. Section1.- Populating the list of persons on the person listing.pdf1. Section1.- Populating the list of persons on the person listing.pdf
1. Section1.- Populating the list of persons on the person listing.pdfaniljain719651
 
1. �Cu�l de las siguientes estructuras hace que las cianobacterias s.pdf
1. �Cu�l de las siguientes estructuras hace que las cianobacterias s.pdf1. �Cu�l de las siguientes estructuras hace que las cianobacterias s.pdf
1. �Cu�l de las siguientes estructuras hace que las cianobacterias s.pdfaniljain719651
 
1. �Cu�l de los siguientes debe evitarse al motivar a los miembros d.pdf
1. �Cu�l de los siguientes debe evitarse al motivar a los miembros d.pdf1. �Cu�l de los siguientes debe evitarse al motivar a los miembros d.pdf
1. �Cu�l de los siguientes debe evitarse al motivar a los miembros d.pdfaniljain719651
 
1. �Cu�l de las siguientes es una raz�n para la descentralizaci�n.pdf
1. �Cu�l de las siguientes es una raz�n para la descentralizaci�n.pdf1. �Cu�l de las siguientes es una raz�n para la descentralizaci�n.pdf
1. �Cu�l de las siguientes es una raz�n para la descentralizaci�n.pdfaniljain719651
 
1. �Cu�l de las siguientes afirmaciones no es verdadera a. Los an.pdf
1. �Cu�l de las siguientes afirmaciones no es verdadera a. Los an.pdf1. �Cu�l de las siguientes afirmaciones no es verdadera a. Los an.pdf
1. �Cu�l de las siguientes afirmaciones no es verdadera a. Los an.pdfaniljain719651
 
1. �Cu�l de las siguientes afirmaciones es verdadera sobre los siste.pdf
1. �Cu�l de las siguientes afirmaciones es verdadera sobre los siste.pdf1. �Cu�l de las siguientes afirmaciones es verdadera sobre los siste.pdf
1. �Cu�l de las siguientes afirmaciones es verdadera sobre los siste.pdfaniljain719651
 
1. You are an analyst reviewing the impact of currency translation.pdf
1. You are an analyst reviewing the impact of currency translation.pdf1. You are an analyst reviewing the impact of currency translation.pdf
1. You are an analyst reviewing the impact of currency translation.pdfaniljain719651
 
1. X tiene una ventaja comparativa sobre Y en la producci�n de un bi.pdf
1. X tiene una ventaja comparativa sobre Y en la producci�n de un bi.pdf1. X tiene una ventaja comparativa sobre Y en la producci�n de un bi.pdf
1. X tiene una ventaja comparativa sobre Y en la producci�n de un bi.pdfaniljain719651
 
1. Would a court determine destroying evidence to be spoliation2..pdf
1. Would a court determine destroying evidence to be spoliation2..pdf1. Would a court determine destroying evidence to be spoliation2..pdf
1. Would a court determine destroying evidence to be spoliation2..pdfaniljain719651
 

More from aniljain719651 (20)

1. THE UNITED STATES has all biomes except ____.Group of answer ch.pdf
1. THE UNITED STATES has all biomes except ____.Group of answer ch.pdf1. THE UNITED STATES has all biomes except ____.Group of answer ch.pdf
1. THE UNITED STATES has all biomes except ____.Group of answer ch.pdf
 
1. The market reacted poorly to Credit Suisses announcement regardi.pdf
1. The market reacted poorly to Credit Suisses announcement regardi.pdf1. The market reacted poorly to Credit Suisses announcement regardi.pdf
1. The market reacted poorly to Credit Suisses announcement regardi.pdf
 
1. The information and material that forms the heart of your project.pdf
1. The information and material that forms the heart of your project.pdf1. The information and material that forms the heart of your project.pdf
1. The information and material that forms the heart of your project.pdf
 
1. Scope Objectives of IBM�s Stretch Project (IBM 7030) detail- .pdf
1. Scope Objectives of IBM�s Stretch Project (IBM 7030) detail- .pdf1. Scope Objectives of IBM�s Stretch Project (IBM 7030) detail- .pdf
1. Scope Objectives of IBM�s Stretch Project (IBM 7030) detail- .pdf
 
1. Suppose two people, Jake and Jill, have different prior beliefs a.pdf
1. Suppose two people, Jake and Jill, have different prior beliefs a.pdf1. Suppose two people, Jake and Jill, have different prior beliefs a.pdf
1. Suppose two people, Jake and Jill, have different prior beliefs a.pdf
 
1. Rara vez se utilizan equipos multifuncionales para desarrollar un.pdf
1. Rara vez se utilizan equipos multifuncionales para desarrollar un.pdf1. Rara vez se utilizan equipos multifuncionales para desarrollar un.pdf
1. Rara vez se utilizan equipos multifuncionales para desarrollar un.pdf
 
1. Si el candidato de un presidente a la Corte Suprema es un constru.pdf
1. Si el candidato de un presidente a la Corte Suprema es un constru.pdf1. Si el candidato de un presidente a la Corte Suprema es un constru.pdf
1. Si el candidato de un presidente a la Corte Suprema es un constru.pdf
 
1. Sulfate- or sulfur-reducing bacteria would most likely be found i.pdf
1. Sulfate- or sulfur-reducing bacteria would most likely be found i.pdf1. Sulfate- or sulfur-reducing bacteria would most likely be found i.pdf
1. Sulfate- or sulfur-reducing bacteria would most likely be found i.pdf
 
1. Sketch a kinetics curve for the movement of lactose into E. coli .pdf
1. Sketch a kinetics curve for the movement of lactose into E. coli .pdf1. Sketch a kinetics curve for the movement of lactose into E. coli .pdf
1. Sketch a kinetics curve for the movement of lactose into E. coli .pdf
 
1. Seg�n la hip�tesis m�s aceptada, el origen del genoma nuclear inv.pdf
1. Seg�n la hip�tesis m�s aceptada, el origen del genoma nuclear inv.pdf1. Seg�n la hip�tesis m�s aceptada, el origen del genoma nuclear inv.pdf
1. Seg�n la hip�tesis m�s aceptada, el origen del genoma nuclear inv.pdf
 
1. Seg�n Darwin, si un grupo muestra un comportamiento m�s moral que.pdf
1. Seg�n Darwin, si un grupo muestra un comportamiento m�s moral que.pdf1. Seg�n Darwin, si un grupo muestra un comportamiento m�s moral que.pdf
1. Seg�n Darwin, si un grupo muestra un comportamiento m�s moral que.pdf
 
1. Section1.- Populating the list of persons on the person listing.pdf
1. Section1.- Populating the list of persons on the person listing.pdf1. Section1.- Populating the list of persons on the person listing.pdf
1. Section1.- Populating the list of persons on the person listing.pdf
 
1. �Cu�l de las siguientes estructuras hace que las cianobacterias s.pdf
1. �Cu�l de las siguientes estructuras hace que las cianobacterias s.pdf1. �Cu�l de las siguientes estructuras hace que las cianobacterias s.pdf
1. �Cu�l de las siguientes estructuras hace que las cianobacterias s.pdf
 
1. �Cu�l de los siguientes debe evitarse al motivar a los miembros d.pdf
1. �Cu�l de los siguientes debe evitarse al motivar a los miembros d.pdf1. �Cu�l de los siguientes debe evitarse al motivar a los miembros d.pdf
1. �Cu�l de los siguientes debe evitarse al motivar a los miembros d.pdf
 
1. �Cu�l de las siguientes es una raz�n para la descentralizaci�n.pdf
1. �Cu�l de las siguientes es una raz�n para la descentralizaci�n.pdf1. �Cu�l de las siguientes es una raz�n para la descentralizaci�n.pdf
1. �Cu�l de las siguientes es una raz�n para la descentralizaci�n.pdf
 
1. �Cu�l de las siguientes afirmaciones no es verdadera a. Los an.pdf
1. �Cu�l de las siguientes afirmaciones no es verdadera a. Los an.pdf1. �Cu�l de las siguientes afirmaciones no es verdadera a. Los an.pdf
1. �Cu�l de las siguientes afirmaciones no es verdadera a. Los an.pdf
 
1. �Cu�l de las siguientes afirmaciones es verdadera sobre los siste.pdf
1. �Cu�l de las siguientes afirmaciones es verdadera sobre los siste.pdf1. �Cu�l de las siguientes afirmaciones es verdadera sobre los siste.pdf
1. �Cu�l de las siguientes afirmaciones es verdadera sobre los siste.pdf
 
1. You are an analyst reviewing the impact of currency translation.pdf
1. You are an analyst reviewing the impact of currency translation.pdf1. You are an analyst reviewing the impact of currency translation.pdf
1. You are an analyst reviewing the impact of currency translation.pdf
 
1. X tiene una ventaja comparativa sobre Y en la producci�n de un bi.pdf
1. X tiene una ventaja comparativa sobre Y en la producci�n de un bi.pdf1. X tiene una ventaja comparativa sobre Y en la producci�n de un bi.pdf
1. X tiene una ventaja comparativa sobre Y en la producci�n de un bi.pdf
 
1. Would a court determine destroying evidence to be spoliation2..pdf
1. Would a court determine destroying evidence to be spoliation2..pdf1. Would a court determine destroying evidence to be spoliation2..pdf
1. Would a court determine destroying evidence to be spoliation2..pdf
 

Recently uploaded

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 

Recently uploaded (20)

9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 

1. Section1.- Populating the list of persons on the person listing f.pdf

  • 1. 1. Section1.- Populating the list of persons on the person listing form, and put functionality in the Add Person button (1 mark) a. In PersonListing: The starting code places only one item in the list of persons. Discussions with the original developer have yielded that the method showTable in PersonListing is responsible for populating the table. The addToTable method which accepts one person and adds information regarding that person to the table should NOT be modified. Complete showTable so that an entry is placed in the table for each row in the file person.dat. b. In PersonEntry: Modify PersonEntry so that it is able to store an instance of PersonListing. c. In PersonEntry: Modify the Constructor of PersonEntry so that it accepts an instance of PersonListing, and then sets the local instance variable to the value accepted by the constructor. d. In PersonListing: Add a listener to the Add Person button so that when it is clicked, an instance of PersonEntry is displayed. When invoking the instance of PersonEntry, a reference to the current instance of PersonListing should be passed as an argument to the constructor. //Hint a listener is already included in the starting code that adds functionality to the Close button. 2. Section 2. Implementing functionality in the PersonEntry. (1.5 marks) a. Modify the PersonEntry object so that the interface looks like that presented in Figure 3 Hints: i. You may need to add a JLabel and a JCheckBox ii. The layout from the previous developer for the panel displays data on two rows. b. Add functionality to the Close button of the PersonEntry form so that it is no longer visible when it is clicked. Hint: one way to do it is to i. Store a reference to a PersonEntry as an instance variable ii. Set the instance of PersonEntry to this in the constructor iii. In the appropriate listener, invoke setVisible on the instance of PersonEntry with an argument of false. c. Implement functionality in the Save button of PersonEntry so that when it is clicked, the data is first validated to ensure both first and last names have been entered, and that the age is an integer. If data is valid, the addPerson method of PersonListing is called, and the person entry form disappears. Note that the addPerson method effectively adds a person to the arraylist holding person list data, and updates the data in the list. Hints/Questions i. Have we already met a method to split a string into parts?
  • 2. ii. What functionality can tell if a value can be converted to an Integer? iii. Remember the getText() method of a jTextField returns the value of the text it currently displays. 3. Section 3 Complete functionality on listing screen (1.5 marks) a. The starting code includes the definition of a JButton named cmdSortAge, but it is not shown on the PersonListing screen. Modify the PersonListingScreen to allow it to be shown b. Add a listener which implements the functionality to sort the list in ascending order of age. Hints: i. You should already know how to sort data ii. Presenting information in a specific order in the table may involve removing all the data and then re-adding it iii. Data in the table is removed with the command model.setRowCount(0);- model is an object name that was declared with the starting code. Ie. model is an object of the class DefaultTableModel. c. Add a button and an associated listener to sort the list in order of first name . 4. Change the colors of the form to implement a custom colour scheme. (1 mark) Figure 4 shows an example of a custom colour scheme. You should come up with your own and then set the colours on the Person Listing screen appropriately. starter code: public abstract class BasePerson { protected String name; private boolean publish; private int age; private int id; public BasePerson(String name,int age, boolean pub) { this.name =name; this.age=age; publish = pub; } public int getAge() { return age; }
  • 3. public abstract String getName(); protected void setId(int id) { this.id = id; } public int getId() { return id; } public boolean getPublish() { return publish; } } public class Person extends BasePerson implements Comparable { private static int nextId=0; public Person(String name, int age, boolean willPublish) { super(name, age, willPublish); super.setId(nextId); nextId++; } public String getName() { return name; } public static String getPHeader() { String returnval = "IDtNametAgetWillPublish";
  • 4. returnval+="n---------------------------------"; return returnval; } public String toString() { return(getId()+"t"+getName()+"t"+getAge()+"t"+getPublish()); } public static void resetId() { nextId=0; } public int compareTo(Person other) { return other.getId() - this.getId(); } } import java.awt.*; import javax.swing.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class PersonEntry extends JFrame { private JTextField txtName; //name private JTextField txtAge; //age private JButton cmdSave; private JButton cmdClose; private JButton cmdClearAll; private JPanel pnlCommand;
  • 5. private JPanel pnlDisplay; public PersonEntry() { setTitle("Entering new person"); pnlCommand = new JPanel(); pnlDisplay = new JPanel(); pnlDisplay.add(new JLabel("Name:")); txtName = new JTextField(20); pnlDisplay.add(txtName); pnlDisplay.add(new JLabel("Age:")); txtAge = new JTextField(3); pnlDisplay.add(txtAge); pnlDisplay.setLayout(new GridLayout(2,4)); cmdSave = new JButton("Save"); cmdClose = new JButton("Close"); pnlCommand.add(cmdSave); pnlCommand.add(cmdClose); add(pnlDisplay, BorderLayout.CENTER); add(pnlCommand, BorderLayout.SOUTH); pack(); setVisible(true); } } import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import java.awt.Dimension; import java.awt.GridLayout;
  • 6. import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.util.Scanner; import java.util.ArrayList; import java.io.File; import java.io.IOException; import javax.swing.JButton; import javax.swing.table.*; import javax.swing.table.DefaultTableModel; import java.util.Comparator; import java.util.Collections; import java.awt.Color; public class PersonListing extends JPanel { private JButton cmdAddPerson; private JButton cmdClose; private JButton cmdSortAge; private JPanel pnlCommand; private JPanel pnlDisplay; private ArrayList plist; private PersonListing thisForm; private JScrollPane scrollPane; private JTable table; private DefaultTableModel model; public PersonListing() { super(new GridLayout(2,1)); thisForm = this; pnlCommand = new JPanel(); pnlDisplay = new JPanel();
  • 7. plist= loadPersons("person.dat"); String[] columnNames= {"First Name", "Last Name", "Age", "Will Publish"}; model=new DefaultTableModel(columnNames,0); table = new JTable(model); showTable(plist); table.setPreferredScrollableViewportSize(new Dimension(500, plist.size()*15 +50)); table.setFillsViewportHeight(true); scrollPane = new JScrollPane(table); add(scrollPane); cmdAddPerson = new JButton("Add Person"); cmdSortAge = new JButton("Sort by Age"); cmdClose = new JButton("Close"); cmdClose.addActionListener(new CloseButtonListener()); pnlCommand.add(cmdAddPerson); pnlCommand.add(cmdClose); add(pnlCommand); } private void showTable(ArrayList plist) { if (plist.size()>0) addToTable(plist.get(0));
  • 8. } private void addToTable(Person p) { String[] name= p.getName().split(" "); String[] item={name[0],name[1],""+ p.getAge(),""+p.getPublish()}; model.addRow(item); } private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("List of persons who are requesting a vaccine"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Create and set up the content pane. PersonListing newContentPane = new PersonListing(); newContentPane.setOpaque(true); //content panes must be opaque frame.setContentPane(newContentPane); //Display the window. frame.pack(); frame.setVisible(true); } public static void main(String[] args) { //Schedule a job for the event-dispatching thread: //creating and showing this application's GUI. javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } public void addPerson(Person p) {
  • 9. plist.add(p); addToTable(p); } private ArrayList loadPersons(String pfile) { Scanner pscan = null; ArrayList plist = new ArrayList(); try { pscan = new Scanner(new File(pfile)); while(pscan.hasNext()) { String [] nextLine = pscan.nextLine().split(" "); String name = nextLine[0]+ " " + nextLine[1]; int age = Integer.parseInt(nextLine[2]); boolean publish = false; if (nextLine[3].equals("0")) publish = false; else publish =true; Person p = new Person(name, age, publish); plist.add(p); } pscan.close(); } catch(IOException e) {} return plist; } private class CloseButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) { System.exit(0); } }
  • 10. Please help its due tomorrow could u write the code where it should be in the starter code? After the initial deployment of Vaccinator Prime(see Lab 5 description), it has become evident that a large number of users may need to interact with the person registration process on the front lines. As a result it has been decided that a GUI is needed for that part of the system. Your immediate tasks are 1. to complete a prototype that demonstrates basic functionality of displaying a list of persons, adding a person and sorting the list as required, and 2. then describe the effort required to implement a fully functional CRUD (Create/Read/Update/Delete) application. Your entry point to the project comes at a time when a junior developer has completed a basic mockup of the appearance of the system, which has been approved by top management. Specific objectives of the lab are: - Integrating a GUI with an application - Adding components to a GUI - Writing listeners for GUI components NON-FUNCTIONAL ASSESSMENT CRITERIA LAB EXERCISES (5 MARKS FOR DEMONSTRATED FUNCTIONALITY) Java code for four classes are provided. The classes are: - BasePerson:Abstract person class - Exact replica of class used as a starter code for Lab 5 - Person: Defines a person - Exact replica of class used as a starter code for Lab 5 - PersonListing: Starter code for screen that should list persons - PersonEntry : Starter code for a screen that should allow entry into the list of persons. Please download these classes and load them into a project for this lab. Spend a few moments to get acquainted with the code. PersonListing.java exposes a public static main method that presents the screen shown in Figure 1. In addition, PersonListing.java also includes several attributes and methods that are used to implement basic functionality, some of which are presented in Table 1. Figure 1 Person Listing Screen Figure 2. Result of executing starting code for PersonEntry. RADEABLE ACTIVITIES 1. Section1.- Populating the list of persons on the person listing form, and put functionality in the "Add Person" button (1 mark) a. In PersonListing: The starting code places only one item in the list of persons. Discussions with the original developer have yielded that the method "showTable" in PersonListing is responsible for populating the table. The addToTable method which accepts one person and adds information regarding that person to the table should NOT be modified. Complete showTable so that an entry is placed in the table for each row in the file person.dat. b. In PersonEntry: Modify PersonEntry so that it is able to store an instance of PersonListing. c. In PersonEntry: Modify the Constructor of PersonEntry so that it accepts an instance of PersonListing, and then sets the local instance variable to the value accepted by the constructor. d. In PersonListing: Add a listener to the "Add Person" button so that when it is clicked, an instance of PersonEntry is displayed. When invoking the instance of PersonEntry, a reference to the current instance of PersonListing should be passed as an argument to the
  • 11. constructor. //Hint... a listener is already included in the starting code that adds functionality to the Close button. 2. Section 2. Implementing functionality in the PersonEntry. (1.5 marks) a. Modify the PersonEntry object so that the interface looks like that presented in Figure 3 Figure 3.Expected Appearance of Person Entry Screen Hints: i. You may need to add a JLabel and a JCheckBox ii. The layout from the previous developer for the panel displays data on two rows. b. Add functionality to the Close button of the PersonEntry form so that it is no longer visible when it is clicked. Hint: one way to do it is to i. Store a reference to a PersonEntry as an instance variable ii. Set the instance of PersonEntry to this in the constructor iii. In the appropriate listener, invoke setVisible on the instance of PersonEntry with an argument of false. c. Implement functionality in the Save button of PersonEntry so that when it is clicked, the data is first validated to ensure both first and last names have been entered, and that the age is an integer. If data is valid, the addPerson method of PersonListing is called, and the person entry form disappears. Note that the addPerson method effectively adds a person to the arraylist holding person list data, and updates the data in the list. Hints/Questions i. Have we already met a method to split a string into parts? ii. What functionality can tell if a value can be converted to an Integer? iii. Remember the get Text0 method of a jTextField returns the value of the text it currently displays. 3. Section 3 - Complete functionality on listing screen (1.5 marks) a. The starting code includes the definition of a JButton named cmdSortAge, but it is not shown on the PersonListing screen. Modify the PersonListingScreen to allow it to be shown b. Add a listener which implements the functionality to sort the list in ascending order of age. Hints: i. You should already know how to sort data ii. Presenting information in a specific order in the table may involve removing all the data and then re-adding it iii. Data in the table is removed with the command modelsetRowCount(0); model is an object name that was declared with the starting code. le. model is an object of the class DefaultTableModel c. Add a button and an associated listener to sort the list in order of first name. 4. Change the colors of the form to implement a custom colour scheme. (1 mark) Figure 4 shows an example of a custom colour scheme. You should come up with your own and then set the colours on the Person Listing screen appropriately. Figure 4. An example of a custom color scheme after two more persons have been entered, sorted in order of age. 5. Compress the .java files into a .zip and submit to OurVLE.