SlideShare una empresa de Scribd logo
1 de 11
Descargar para leer sin conexión
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.
4. Lint of peryony

Más contenido relacionado

Similar a 1. Section1.- Populating the list of persons on the person listing.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 7
helpido9
 
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
fantoosh1
 
project2.classpathproject2.project project2 .docx
project2.classpathproject2.project  project2 .docxproject2.classpathproject2.project  project2 .docx
project2.classpathproject2.project project2 .docx
briancrawford30935
 
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
feetshoemart
 
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
arihantgiftgallery
 
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
NicholasflqStewartl
 
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
jillisacebi75827
 
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
formicreation
 
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
aggarwalcollection1
 
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
foottraders
 
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
info114
 
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
AustinaGRPaigey
 
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
fashioncollection2
 
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
aioils
 
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
albarefqc
 

Similar a 1. Section1.- Populating the list of persons on the person listing.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
 

Más de aniljain719651

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
aniljain719651
 
1. Section1.- Populating the list of persons on the person listing f.pdf
1. Section1.- Populating the list of persons on the person listing f.pdf1. Section1.- Populating the list of persons on the person listing f.pdf
1. Section1.- Populating the list of persons on the person listing f.pdf
aniljain719651
 

Más de 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. Section1.- Populating the list of persons on the person listing f.pdf
1. Section1.- Populating the list of persons on the person listing f.pdf1. Section1.- Populating the list of persons on the person listing f.pdf
1. Section1.- Populating the list of persons on the person listing f.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. �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
 

Último

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Último (20)

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 

1. Section1.- Populating the list of persons on the person listing.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
  • 2. 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() {
  • 3. 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()
  • 4. { 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;
  • 5. 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;
  • 6. 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();
  • 7. 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));
  • 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
  • 11. 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. 4. Lint of peryony