Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I know the code is correct but I am confused on what the assigment is asking Prompt To continue your exploration of the Java programming

I know the code is correct but I am confused on what the assigment is asking

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:

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.

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.

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.

Add images and additional customizations.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.

Finally, add a label with your name on it.

image text in transcribed

CODE:

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.jpg"))); addDestinationNameAndPicture("2. 2nd Top Destination", new ImageIcon(getClass().getResource("/resources/TestImage.jpg"))); addDestinationNameAndPicture("3. 3rd Top Destination", new ImageIcon(getClass().getResource("/resources/TestImage.jpg"))); addDestinationNameAndPicture("4. 4th Top Destination", new ImageIcon(getClass().getResource("/resources/TestImage.jpg"))); addDestinationNameAndPicture("5. 5th Top Destination", new ImageIcon(getClass().getResource("/resources/TestImage.jpg"))); 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) {} }

Top 5 Destination List 1. Top Destination (short sentence description) 2. 2nd Top Destination 3. 3rd Top Destination 4. 4th Top Destination 5. 5th Top Destination

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

2. How should this be dealt with by the organisation?

Answered: 1 week ago

Question

explain what is meant by the term fair dismissal

Answered: 1 week ago