Overview
This assignment will help you continue your exploration of the Java programming language and the Eclipse environment. This will help prepare you for the tasks you need to complete when you assume the role of developer in Module Five. You will be asked to run an existing program and then make small changes to customize it.
Prompt
To continue your exploration of the Java programming language and the Eclipse environment, you will modify an existing program to fulfill a user story. To do this, run the program provided and then make your changes by completing the following steps:
I. Modify an existing program to fulfill a user story.
A. Review the following user story from the Product Owner for the SNHU Travel project:
B. Download the SampleListView ZIP file to your computer. Right-click on the folder and select “Extract All…”. In the unzipped folder, find and run the BasicListViewControl JAR file. This will allow you to see the template before you make customizations.
C. Import the BasicListViewControl ZIP file to a new project in your Eclipse IDE. For help with importing a ZIP file to Eclipse, review the
Uploading Files to Eclipse Tutorial Word Document
.
D. Using the source code given, update the simple list to your top five chosen destinations. Include the destination title, a short description, and a small image for each. This will help ensure that you have fulfilled the acceptance criteria of the user story. Refer to the
Developing Basic ListView Control Tutorial
to help you with this task.
II. Add images and additional customizations.
A. Add images for each destination and at least one additional customization, color scheme, or the like to make the control as elaborate as you want. Be sure to include clear and concise comments to explain your changes.
·
Wikimedia Commons
is an excellent source for copyright-free images. Be sure to credit the author or creator.
· For additional information on adding images to a Java project, watch this video:
Loading Resources in Java Using Eclipse IDE
(4:01). A transcript is available here:
CS 250 Loading Resources in Java Using Eclipse IDE Video Transcript Word Document
.
B. Finally, add a label with your name on it.
Guidelines for Submission
Export your Eclipse Java Project to a runnable JAR file. This will include the source code and the image files so the full basic ListView control can run. Next, compress (zip) your JAR file and Java project. Submit your zipped file to Brightspace.
Note: For additional instructions on how to create a runnable JAR file, use the following instructions:
Export Java Files to Runnable Jar File PDF
. For additional instructions on how to compress (zip) files, review the
Compressing Files in Windows tutorial PDF
.
·
· Reference
· Prehn, R. (2016, Jun 1).
As a team member, I want better user stories… Revelry. Retrieved from https://revelry.co/better-user-stories/.
https://web-s-ebscohost-com.ezproxy.snhu.edu/ehost/detail/detail?vid=0&sid=ad3e376a-914a-450c-b5b4-6dc0ba053fdc%40redis&bdata=JnNpdGU9ZWhvc3QtbGl2ZQ%3d%3d#AN=937009&db=nlebk
image1
Basic List View Control/.classpath
Basic List View Control/.project
Basic List View Control
org.eclipse.jdt.core.javabuilder
org.eclipse.jdt.core.javanature
Basic List View Control/.settings/org.eclipse.jdt.core.prefs
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
Basic List View Control/bin/TextAndIcon.class
synchronized
class TextAndIcon {
private String
text;
private javax.swing.Icon
icon;
public void TextAndIcon(String, javax.swing.Icon);
public String
getText();
public javax.swing.Icon
getIcon();
public void
setText(String);
public void
setIcon(javax.swing.Icon);
}
Basic List View Control/bin/TextAndIconListCellRenderer.class
synchronized
class TextAndIconListCellRenderer
extends javax.swing.JLabel
implements javax.swing.ListCellRenderer {
private
static
final javax.swing.border.Border
NO_FOCUS_BORDER;
private javax.swing.border.Border
insideBorder;
static void
public void TextAndIconListCellRenderer();
public void TextAndIconListCellRenderer(int);
public void TextAndIconListCellRenderer(int, int, int, int);
public java.awt.Component
getListCellRendererComponent(javax.swing.JList, Object, int, boolean, boolean);
public void
validate();
public void
invalidate();
public void
repaint();
public void
revalidate();
public void
repaint(long, int, int, int, int);
public void
repaint(java.awt.Rectangle);
}
Basic List View Control/bin/TopDestinationListFrame.class
synchronized
class TopDestinationListFrame
extends javax.swing.JFrame {
private javax.swing.DefaultListModel
listModel;
public void TopDestinationListFrame();
private void
addDestinationNameAndPicture(String, javax.swing.Icon);
}
Basic List View Control/bin/TopFiveDestinationList$1.class
synchronized
class TopFiveDestinationList$1
implements Runnable {
void TopFiveDestinationList$1();
public void
run();
}
Basic List View Control/bin/TopFiveDestinationList.class
public
synchronized
class TopFiveDestinationList {
public void TopFiveDestinationList();
public
static void
main(String[]);
}
Basic List View Control/bin/resources/TestImage
Basic List View Control/src/TopFiveDestinationList.java
Basic List View Control/src/TopFiveDestinationList.java
import
java
.
awt
.
*
;
import
javax
.
swing
.
*
;
import
javax
.
swing
.
border
.
*
;
public
class
TopFiveDestinationList
{
public
static
void
main
(
String
[]
args
)
{
SwingUtilities
.
invokeLater
(
new
Runnable
()
{
public
void
run
()
{
TopDestinationListFrame
topDestinationListFrame
=
new
TopDestinationListFrame
();
topDestinationListFrame
.
setTitle
(
“Top 5 Destination List”
);
topDestinationListFrame
.
setVisible
(
true
);
}
});
}
}
class
TopDestinationListFrame
extends
JFrame
{
private
DefaultListModel
listModel
;
public
TopDestinationListFrame
()
{
super
(
“Top Five Destination List”
);
setDefaultCloseOperation
(
WindowConstants
.
EXIT_ON_CLOSE
);
setSize
(
900
,
750
);
listModel
=
new
DefaultListModel
();
//Make updates to your top 5 list below. Import the new image files to resources directory.
addDestinationNameAndPicture
(
“1. Top Destination (short sentence description)”
,
new
ImageIcon
(
getClass
().
getResource
(
“/resources/TestImage ”
)));
addDestinationNameAndPicture
(
“2. 2nd Top Destination”
,
new
ImageIcon
(
getClass
().
getResource
(
“/resources/TestImage ”
)));
addDestinationNameAndPicture
(
“3. 3rd Top Destination”
,
new
ImageIcon
(
getClass
().
getResource
(
“/resources/TestImage ”
)));
addDestinationNameAndPicture
(
“4. 4th Top Destination”
,
new
ImageIcon
(
getClass
().
getResource
(
“/resources/TestImage ”
)));
addDestinationNameAndPicture
(
“5. 5th Top Destination”
,
new
ImageIcon
(
getClass
().
getResource
(
“/resources/TestImage ”
)));
JList
list
=
new
JList
(
listModel
);
JScrollPane
scrollPane
=
new
JScrollPane
(
list
);
TextAndIconListCellRenderer
renderer
=
new
TextAndIconListCellRenderer
(
2
);
list
.
setCellRenderer
(
renderer
);
getContentPane
().
add
(
scrollPane
,
BorderLayout
.
CENTER
);
}
private
void
addDestinationNameAndPicture
(
String
text
,
Icon
icon
)
{
TextAndIcon
tai
=
new
TextAndIcon
(
text
,
icon
);
listModel
.
addElement
(
tai
);
}
}
class
TextAndIcon
{
private
String
text
;
private
Icon
icon
;
public
TextAndIcon
(
String
text
,
Icon
icon
)
{
this
.
text
=
text
;
this
.
icon
=
icon
;
}
public
String
getText
()
{
return
text
;
}
public
Icon
getIcon
()
{
return
icon
;
}
public
void
setText
(
String
text
)
{
this
.
text
=
text
;
}
public
void
setIcon
(
Icon
icon
)
{
this
.
icon
=
icon
;
}
}
class
TextAndIconListCellRenderer
extends
JLabel
implements
ListCellRenderer
{
private
static
final
Border
NO_FOCUS_BORDER
=
new
EmptyBorder
(
1
,
1
,
1
,
1
);
private
Border
insideBorder
;
public
TextAndIconListCellRenderer
()
{
this
(
0
,
0
,
0
,
0
);
}
public
TextAndIconListCellRenderer
(
int
padding
)
{
this
(
padding
,
padding
,
padding
,
padding
);
}
public
TextAndIconListCellRenderer
(
int
topPadding
,
int
rightPadding
,
int
bottomPadding
,
int
leftPadding
)
{
insideBorder
=
BorderFactory
.
createEmptyBorder
(
topPadding
,
leftPadding
,
bottomPadding
,
rightPadding
);
setOpaque
(
true
);
}
public
Component
getListCellRendererComponent
(
JList
list
,
Object
value
,
int
index
,
boolean
isSelected
,
boolean
hasFocus
)
{
// The object from the combo box model MUST be a TextAndIcon.
TextAndIcon
tai
=
(
TextAndIcon
)
value
;
// Sets text and icon on ‘this’ JLabel.
setText
(
tai
.
getText
());
setIcon
(
tai
.
getIcon
());
if
(
isSelected
)
{
setBackground
(
list
.
getSelectionBackground
());
setForeground
(
list
.
getSelectionForeground
());
}
else
{
setBackground
(
list
.
getBackground
());
setForeground
(
list
.
getForeground
());
}
Border
outsideBorder
;
if
(
hasFocus
)
{
outsideBorder
=
UIManager
.
getBorder
(
“List.focusCellHighlightBorder”
);
}
else
{
outsideBorder
=
NO_FOCUS_BORDER
;
}
setBorder
(
BorderFactory
.
createCompoundBorder
(
outsideBorder
,
insideBorder
));
setComponentOrientation
(
list
.
getComponentOrientation
());
setEnabled
(
list
.
isEnabled
());
setFont
(
list
.
getFont
());
return
this
;
}
// The following methods are overridden to be empty for performance
// reasons. If you want to understand better why, please read:
//
// http://java.sun.com/javase/6/docs/api/javax/swing/DefaultListCellRenderer.html#override
public
void
validate
()
{}
public
void
invalidate
()
{}
public
void
repaint
()
{}
public
void
revalidate
()
{}
public
void
repaint
(
long
tm
,
int
x
,
int
y
,
int
width
,
int
height
)
{}
public
void
repaint
(
Rectangle
r
)
{}
}
Basic List View Control/src/resources/TestImage
BasicListViewControl.jar
META-INF/MANIFEST.MF
Manifest-Version: 1.0
Class-Path: .
Main-Class: TopFiveDestinationList
TextAndIcon.class
synchronized
class TextAndIcon {
private String
text;
private javax.swing.Icon
icon;
public void TextAndIcon(String, javax.swing.Icon);
public String
getText();
public javax.swing.Icon
getIcon();
public void
setText(String);
public void
setIcon(javax.swing.Icon);
}
TextAndIconListCellRenderer.class
synchronized
class TextAndIconListCellRenderer
extends javax.swing.JLabel
implements javax.swing.ListCellRenderer {
private
static
final javax.swing.border.Border
NO_FOCUS_BORDER;
private javax.swing.border.Border
insideBorder;
static void
public void TextAndIconListCellRenderer();
public void TextAndIconListCellRenderer(int);
public void TextAndIconListCellRenderer(int, int, int, int);
public java.awt.Component
getListCellRendererComponent(javax.swing.JList, Object, int, boolean, boolean);
public void
validate();
public void
invalidate();
public void
repaint();
public void
revalidate();
public void
repaint(long, int, int, int, int);
public void
repaint(java.awt.Rectangle);
}
TopDestinationListFrame.class
synchronized
class TopDestinationListFrame
extends javax.swing.JFrame {
private javax.swing.DefaultListModel
listModel;
public void TopDestinationListFrame();
private void
addDestinationNameAndPicture(String, javax.swing.Icon);
}
TopFiveDestinationList$1.class
synchronized
class TopFiveDestinationList$1
implements Runnable {
void TopFiveDestinationList$1();
public void
run();
}
TopFiveDestinationList.class
public
synchronized
class TopFiveDestinationList {
public void TopFiveDestinationList();
public
static void
main(String[]);
}
resources/TestImage