Assignment6/~$signment6.docx
Assignment6/Assignment6.docx
Assignment #6
Important: This is an individual assignment. Please do not collaborate.
No late assignment will be accepted.
Make sure that you write every line of your code. Using code written by someone else will be considered a violation of the academic integrity and will result in a report to the Dean's office.
Requirements to get full credits in Documentation
1. The assignment number, your name, student ID, lecture number, and a class/file description need to be included at the top of each file/class.
2. A description of each method is also needed.
3. Some additional comments inside of methods to explain code that are hard to follow should be written.
You can look at the Java programs in the text book to see how comments are added to programs.
Minimal Submitted Files
You are required, but not limited, to turn in the following source files:
Assignment6.java (The Assignment6 class extends JApplet)
Project.java
Budget.javaCreatePanel.java - to be completed (it extends JPanel and contains ButtonListener nested class)
ProjectSpendingPanel.java - to be completed (it extends JPanel and contains ButtonListener nested class)
You can download the above files and use them to complete this assignment. You might need to add more methods than the specified ones.
Skills to be Applied:
Swing/AWT, Vector (very similar to ArrayList class)
Classes may be needed:
JApplet, JButton, JTextField, JTextArea, JLabel, Container, JPanel, JTabbedPane, JList, and ActionListener. You may use other classes.
How to run an applet program:
-Create an html file, say "hw6.html" with the following content:
--------------------------------------------------------
<html>
<head>
<title>Assignment 6 Applet</title>
</head>
<body>
<applet code="Assignment6.class" width=900 height=350>
</applet>
</body>
</html>
------------------------------------------------------
-Compile your java program as usual.
-In a console, type:
appletviewer hw6.html
(instead of typing "java Assignment6").
-In the TextPad, choose Tool->Run Java Applet or
press Ctrl-3 (press control key and 3 at the same time).
-In the jGrasp,
choose Run->Run as Applet.
To test to see if your machine is set to view an applet, please go to the following site:
Click this page
Program Description
Suggested Class Diagram:
Write a Java program that constructs an Applet. Your program should provide labels and textfields to a user to enter information regarding projects.
The Applet (JApplet) of your program should contain two tabs. The first tab is labeled "Project creation" and the second tab is labeled "Project spending".
(The size of the applet here is approximately 900 X 350).
The section under the first tab should be divided into two parts:
The left part contains labels, textfields, and a button for a user to enter some project information. The right part shows "No project" at the beginning (it is done usingJTextArea).
A user can enter some project ...
1. Assignment6/~$signment6.docx
Assignment6/Assignment6.docx
Assignment #6
Important: This is an individual assignment. Please do not
collaborate.
No late assignment will be accepted.
Make sure that you write every line of your code. Using code
written by someone else will be considered a violation of the
academic integrity and will result in a report to the Dean's
office.
Requirements to get full credits in Documentation
1. The assignment number, your name, student ID, lecture
number, and a class/file description need to be included at the
top of each file/class.
2. A description of each method is also needed.
3. Some additional comments inside of methods to explain code
that are hard to follow should be written.
You can look at the Java programs in the text book to see how
comments are added to programs.
Minimal Submitted Files
You are required, but not limited, to turn in the following
source files:
Assignment6.java (The Assignment6 class extends JApplet)
Project.java
Budget.javaCreatePanel.java - to be completed (it
extends JPanel and contains ButtonListener nested class)
ProjectSpendingPanel.java - to be completed (it
extends JPanel and contains ButtonListener nested class)
You can download the above files and use them to complete this
assignment. You might need to add more methods than the
2. specified ones.
Skills to be Applied:
Swing/AWT, Vector (very similar to ArrayList class)
Classes may be needed:
JApplet, JButton, JTextField, JTextArea, JLabel,
Container, JPanel, JTabbedPane, JList, and ActionListener. You
may use other classes.
How to run an applet program:
-Create an html file, say "hw6.html" with the following
content:
--------------------------------------------------------
<html>
<head>
<title>Assignment 6 Applet</title>
</head>
<body>
<applet code="Assignment6.class" width=900 height=350>
</applet>
</body>
</html>
------------------------------------------------------
-Compile your java program as usual.
-In a console, type:
appletviewer hw6.html
(instead of typing "java Assignment6").
-In the TextPad, choose Tool->Run Java Applet or
press Ctrl-3 (press control key and 3 at the same time).
3. -In the jGrasp,
choose Run->Run as Applet.
To test to see if your machine is set to view an applet, please go
to the following site:
Click this page
Program Description
Suggested Class Diagram:
Write a Java program that constructs an Applet. Your program
should provide labels and textfields to a user to enter
information regarding projects.
The Applet (JApplet) of your program should contain two tabs.
The first tab is labeled "Project creation" and the second tab is
labeled "Project spending".
(The size of the applet here is approximately 900 X 350).
The section under the first tab should be divided into two parts:
The left part contains labels, textfields, and a button for a user
to enter some project information. The right part shows "No
project" at the beginning (it is done usingJTextArea).
A user can enter some project information, and push "Create a
project" button.
Then the project information should appear on the right hand
side panel (note that the format of the project information can
be using toString() method of the Project class). A message
"Project added" should also appear with red color at the top of
the panel.
Error handling:
1. If a user forgets to enter some field and pushes "Create a
project" button, show a message "Please fill all fields" with red
color, and nothing should be added to the right hand side panel.
2. If a user enters a non-numeric value for project number or
initial funding, and push "Create a project" button, show a
4. message "Please enter a numeric value for project number and
initial funding" with red color, and nothing should be added to
the right hand side panel.
After entering several projects, the applet will have the
following appearance. Note that a scroll pane needs to be added
to show multiple projects.
Under the "Project spending" tab, a user can choose a project to
specify spending. There should be a JList containing all projects
created by Project creation panel and a user can choose a
project within it by clicking it. Below the JList, there should be
a JTextField where a user can enter some spending and a button
to add some spending.
The list of projects in the JList should be exactly same as the
list under "Project creation" tab. A user can choose a project
and specify its spending, then push " Submit Budget " button.
After pushing the button, it should update the spending and
current balance of the project as follows. Note that a scroll pane
needs to be added to show the entire project information.
Another user can add spending for other projects as well:
A user should be able to go back and forth between "Project
creation" tab and "Project spending" tab, and these two panels
need to have consistent information, i.e., the same list of
projects. Note that the list of projects created in
the CreatePanel needs to be consistent in the list
in ProjectSpendingPanel, but the spending and current balance
updated in the ProjectSpendingPanel do not need to be reflected
5. in CreatePanel.
Class description
ProjectSpendingPanel
ProjectSpendingPanel class extends JPanel defined
in javax.swing package. It should contain at least the following
instance variable:
Attribute name
Attribute type
Description
projectList
Vector
a list of project objects.
This class should have a constructor:
public ProjectSpendingPanel(Vector projectList)
where the parameter "projectList" is passed from the
Assignment6 class. The constructor layouts and organizes
components in this panel. You will be adding more variables
(components) than what is listed here, including JList, labels, a
textfield, and a button. The JList should be instantiated using
the "projectList" vector. Then whenever the vector is updated,
the JList will be updated as well by calling its updateUI()
method. They will utilize the toString( ) method of the Project
class to display each item.
public void updateProjectList()
This method calls updateUI() method for the JList that you will
be creating. You need to instantiate your JList using
the projectList in the constructor. The projectList will be
constantly updated under the "Project creation" tab and when it
is updated, this method should be called from
the actionPerformed method in the ButtonListener of
theCreatePanel class so that the JList under the "Project
spending" will have the same update project list in them.
This class contains a nested class
called ButtonListener class that
implements ActionListener interface. Thus you need to define
its actionPerformed method that is supposed to update the
6. spending and current balance, and display them when the "Add
Spending" button is pushed.
CreatePanel
CreatePanel extends JPanel defined in the javax.swing package.
It should contain at least the following instance variable:
Attribute name
Attribute type
Description
projectList
Vector
a list of Project objects.
spendingPanel
ProjectSpendingPanel
an object of ProjectSpendingPanel.
This class should have a constructor:
public CreatePanel(Vector projectList, ProjectSpendingPanel sp
endingPanel)
where the parameter "projectList" is passed from the
Assignment6 class and the second parameter is an object
of ProjectSpendingPanel. The constructor layouts and organizes
components in this panel. You will be adding more variables
(components) than what is listed here, including
labels, textfields, a button, and a text area.
This class contains a nested class
called ButtonListener class that
implements ActionListener interface. Thus
the ButtonListener needs to have a definition
foractionPerformed method that adds some project information
to the list and does error handling. See the UML class diagram
for the parameter and return type of this method. In
the actionPerformed, you need to extract the information from
the two textfields for the title and publisher. Then you can
instantiate an object of the Project class using the information.
You can use the toString( ) method of the Project object to
display the information on the textarea on the right hand side
and also add the Project object to the "projectList".
7. Assignment6 class
Assignment6 class extends JApplet defined
in javax.swing package. It contains at least init() method (see
UML diagram for its return type) to instantiate all instance
variables and adds its components to itself. It also sets its size.
It contains at least following instance variables:
Attribute name
Attribute type
Description
projectList
Vector
a list of project objects. It will be used in
both createPanel and spendingPanel.
spendingPanel
ProjectSpendingPanel
an object of ProjectSpendingPanel.
createPanel
CreatePanel
an object of CreatePanel.
tPane
JTabbedPane
an object of JTabbedPane. It will
contain createPanel and spendingPanel under each tab.
Grading Policy:
· submit assignment on time
· indicate assignment number, name, lecture number, and
description of each class clearly in each submitted java file
· your program minimally has the following functionalities:
1. 2 points: Appropriate components such as textfields, labels,
etc. are shown under the "Project creation" and "Project
spending" tabs. JScrollPane is added to display the entire
information on each Panel.
2. 1 point: When the "Create a project" button is pushed, the
project information from textfields is added on the right panel
in the correct order and the message of "project added" shows
up.
8. 3. 1 point: Error handing in case some field is not filled.
4. 1 point: Error handing in case a non-numeric value is entered
for projNumber or funding.
5. 1 point: The same list of projects is shown under the "Project
creation" tab and under the "Project spending" tab.
6. 2 point: When the add spending button is pushed, the
spending and current balance are updated correctly.
Assignment6/Assignment6.javaAssignment6/Assignment6.java//
Assignment #: 6
// Name: your name
// StudentID: your id
// Lecture: your lecture days/time
// Description: The Assignment 6 class creates a Tabbed Pane
with
// two tabs, one for Project creation and one for
// Project spending. and adds it as its Applet content
// and also sets its size.
import javax.swing.*;
import java.util.*;
publicclassAssignment6extendsJApplet
{
privateint APPLET_WIDTH =900, APPLET_HEIGHT =350;
privateJTabbedPane tPane;
privateCreatePanel createPanel;
privateProjectSpendingPanel spendingPanel;
privateVector projectList;
//The method init initializes the Applet with a Pane with two tab
s
publicvoid init()
{
9. //list of projects to be used in every panel
projectList =newVector();
//review panel uses the list of projects
spendingPanel =newProjectSpendingPanel(projectList);
createPanel =newCreatePanel(projectList, spendingPanel);
//create a tabbed pane with two tabs
tPane =newJTabbedPane();
tPane.addTab("Project creation", createPanel);
tPane.addTab("Project spending", spendingPanel);
getContentPane().add(tPane);
setSize (APPLET_WIDTH, APPLET_HEIGHT);//set Applet
size
}
}
Assignment6/Budget.javaAssignment6/Budget.java// Assignmen
t #:
// Name:
// StudentID:
// Lecture:
// Description: The class Budget represents a budget of a projec
t
import java.text.NumberFormat;
publicclassBudget
{
privatedouble initialFunding;
privatedouble spending;
10. privatedouble currentBalance;
//Constructor to initialize all member variables
publicBudget(double funding)
{
initialFunding = funding;
spending =0.0;
currentBalance = initialFunding - spending;
}
//add some additional spending
publicboolean addSpending(double additionalSpending)
{
if(additionalSpending >0&& additionalSpending <= currentBala
nce)
{
spending += additionalSpending;
currentBalance = initialFunding - spending;
returntrue;
}
else
returnfalse;
}
//toString() method returns a string containg its initial funding
//spending and current balance
publicString toString()
{
NumberFormat fmt =NumberFormat.getCurrencyInstance();
String result ="Budget:"
+"nInitial Fundingtt"+ fmt.format(initialFunding)
+"nSpendingtt"+ fmt.format(spending)
+"nCurrent Balancet"+ fmt.format(currentBalance);
return result;
}
}
11. Assignment6/CreatePanel.javaAssignment6/CreatePanel.java//
Assignment #: 6
// Name: your name
// StudentID: your id
// Lecture: your lecture days/time
// Description: It needs to be filled
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
publicclassCreatePanelextendsJPanel
{
privateVector projectList;
privateJButton button1;
privateProjectSpendingPanel spendingPanel;
//Constructor initializes components and organize them using ce
rtain layouts
publicCreatePanel(Vector projectList,ProjectSpendingPanel spe
ndingPanel)
{
this.projectList = projectList;
this.spendingPanel = spendingPanel;
//organize components here
button1 =newJButton("Create a project");
add(button1);
}
12. //ButtonListener is a listener class that listens to
//see if the buttont "Create a project" is pushed.
//When the event occurs, it adds a project information from
//the text fields to the text area. It also creates a Project object
//using theinformation and add it to the projectList.
//It also does error checking.
privateclassButtonListenerimplementsActionListener
{
publicvoid actionPerformed(ActionEvent event)
{
// if there is no error, add a project to project list
// otherwise, show an error message
}//end of actionPerformed method
}//end of ButtonListener class
}//end of CreatePanel class
Assignment6/Project.javaAssignment6/Project.java// Assignmen
t #:
// Name:
// StudentID:
// Lecture:
// Description: The class Project represents a project .
publicclassProject
{
privateString projName;
privateint projNumber;
privateString projLocation;
privateBudget projBudget;
//Constructor to initialize all member variables
publicProject(double funding)
{
14. }
publicvoid setLocation(String aLocation)
{
projLocation = aLocation;
}
//Add a new expenditure to the budget
publicboolean addExpenditure(double amount)
{
boolean success = projBudget.addSpending(amount);
return success;
}
//toString() method returns a string containg its name, number, l
ocation and budget
publicString toString()
{
String result ="nProject Name:tt"+ projName
+"nProject Number:t"+ projNumber
+"nProject Location:t"+ projLocation
+"n"
+ projBudget.toString()+"nn";
return result;
}
}
Assignment6/ProjectSpendingPanel.javaAssignment6/ProjectSp
endingPanel.java// Assignment #: 6
// Name: your name
// StudentID: your id
// Lecture: your lecture days/time
15. // Description: It needs to be filled
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
publicclassProjectSpendingPanelextendsJPanel
{
privateVector projectList;
//Constructor initialize each component and arrange them using
//certain layouts
publicProjectSpendingPanel(Vector projectList)
{
this.projectList = projectList;
//organize components for spending panel
}
//This method refreshes the JList with
//updated vector information
publicvoid updateProjectList()
{
//call updateUI() for the JList object
}
//ButtonListener class listens to see the button "Add Spending" i
s pushed.
//A user can choose which project to add spending, and that will
update the
//spending and current balance of such project.
privateclassButtonListenerimplementsActionListener
{
16. publicvoid actionPerformed(ActionEvent event)
{
//get some additional spending from the textfield,
//update the spending and current balance
//for the chosen project in the JList.
}
}//end of ButtonListener class
}//end of ProjectSpendingPanel class
Similarities and Differences
Discuss the similarities and differences between organisms in
the domains Bacteria and Archaea.
Your assignment should be 250-500 words in length
Please include all references and site in paper