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. Paris. Paris offers iconic landmarks,
romantic scenery, and world class art that make it one of the most visited cities
in the world", new ImageIcon(getClass().getResource("/resources/paris.jpg")));
addDestinationNameAndPicture("2. Tokyo. Blends ancient traditions with
futuristic technology, offering vibrant nightlife,cuisine, and culture", new
ImageIcon(getClass().getResource("/resources/tokyo.jpg")));
addDestinationNameAndPicture("3. New York. A global hub of entertainmet,
culture, and skycrappers, attracting millions of visitors each year", new
ImageIcon(getClass().getResource("/resources/newyork.jpg")));
addDestinationNameAndPicture("4. Dubai. It features stunning modern
architecture and luxury attractions, including the world famous Burj Khalifa", new
ImageIcon(getClass().getResource("/resources/dubai.jpg")));
addDestinationNameAndPicture("5. Capetown. It is a known for its
breathtaking landscapes, beaches, and iconic Table mountain", new
ImageIcon(getClass().getResource("/resources/capetown.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) {