Initial upload

Upload my classwork to Github.
This commit is contained in:
didyouexpectthat 2023-06-17 15:15:27 -07:00 committed by GitHub
commit 7d37fcb1d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
49 changed files with 359 additions and 0 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

View file

@ -0,0 +1,170 @@
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();
// show the top 5 destinations with a short description and a picture
// image dimensions 193 x 145
// last modified 2023/05/21
// File:Mountain Goat at Hidden Lake.jpg. (2022, March 17). Wikimedia Commons. Retrieved 17:57, May 21, 2023 from https://commons.wikimedia.org/w/index.php?title=File:Mountain_Goat_at_Hidden_Lake.jpg&oldid=640186430.
// Resized and renamed to glacier.jpg
addDestinationNameAndPicture("1. Glacier National Park - All of Nature under the Big Sky", new ImageIcon(getClass().getResource("/resources/glacier.jpg")));
// File:Keanae Road to Hana. Maui. (11106935413).jpg. (2023, May 8). Wikimedia Commons. Retrieved 17:58, May 21, 2023 from https://commons.wikimedia.org/w/index.php?title=File:Keanae_Road_to_Hana._Maui._(11106935413).jpg&oldid=760888382.
// Resized and renamed to maui.jpg
addDestinationNameAndPicture("2. Maui - Paradise in the Pacific", new ImageIcon(getClass().getResource("/resources/maui.jpg")));
// File:Grand Canyon Hopi Point with rainbow 2013.jpg. (2023, April 11). Wikimedia Commons. Retrieved 17:59, May 21, 2023 from https://commons.wikimedia.org/w/index.php?title=File:Grand_Canyon_Hopi_Point_with_rainbow_2013.jpg&oldid=749321666.
// Resized and renamed to grandcanyon.jpg
addDestinationNameAndPicture("3. Grand Canyon National Park - Natural Wonder of the World", new ImageIcon(getClass().getResource("/resources/grandcanyon.jpg")));
// File:Sand Island Beach, Oahu, Hawaii.jpg. (2022, March 27). Wikimedia Commons. Retrieved 17:59, May 21, 2023 from https://commons.wikimedia.org/w/index.php?title=File:Sand_Island_Beach,_Oahu,_Hawaii.jpg&oldid=644361941.
// Resized and renamed to honolulu.jpg
addDestinationNameAndPicture("4. Oahu - Tropical Bliss and Cultural Delights", new ImageIcon(getClass().getResource("/resources/honolulu.jpg")));
// File:Yellowstone national park waterfall.jpg. (2022, May 26). Wikimedia Commons. Retrieved 18:00, May 21, 2023 from https://commons.wikimedia.org/w/index.php?title=File:Yellowstone_national_park_waterfall.jpg&oldid=659127234.
// Resized and renamed to yellowstone.jpg
addDestinationNameAndPicture("5. Yellowstone National Park - Geothermal Marvel and Wildlife Haven", new ImageIcon(getClass().getResource("/resources/yellowstone.jpg")));
JList list = new JList(listModel);
JScrollPane scrollPane = new JScrollPane(list);
// reduce padding from 2 to 1 for better looking pictures
TextAndIconListCellRenderer renderer = new TextAndIconListCellRenderer(1);
list.setCellRenderer(renderer);
// add developer attribution; added 2023/05/21
JLabel nameLabel = new JLabel("Developer: Cody Cook");
getContentPane().add(nameLabel, BorderLayout.NORTH);
// show scrollPane
getContentPane().add(scrollPane, BorderLayout.CENTER);
// change scrollPane colors; added 2023/05/21
scrollPane.getVerticalScrollBar().setBackground(Color.BLUE);
}
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());
// Adjust color scheme. Set unselected option to gray to make image pop more. On selection, darken text.
if (isSelected) {
setBackground(list.getSelectionBackground());
setForeground(Color.BLACK);
} else {
setBackground(list.getBackground());
setForeground(Color.GRAY);
}
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) {}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB