OK so I switched from JList to List because
1.) It doesn't overlap my drawn images 2.) It can have focus disabled yet track what's selected
Anyway, here's the error I get when I try to compile:
C:\Users\Dan\Documents\DanJavaGen\inventory.java:30: cannot find symbol
symbol : constructor List(java.lang.Object[])
location: class java.awt.List
list = new List(arr.toArray());
^
C:\Users\Dan\Documents\DanJavaGen\inventory.java:50: cannot find symbol
symbol : method getSelectedValue()
location: class java.awt.List
Object index = list.getSelectedValue();
^
The code:
import java.applet.Applet;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.io.*;
import java.util.*;
import java.awt.List;
public class inventory extends JApplet implements MouseListener {
public static String newline;
public static List list;
int gold = 123;
public void init() {
ArrayList<String> arr = new ArrayList<String>();
arr.add("Hatchet");
arr.add("Sword");
arr.add("Shield");
arr.add(gold + " Gold");
System.out.println("You have " + arr.size() + " items in your inventory.");
showInventory(arr);
list = new List(arr.toArray());
add(list);
list.addMouseListener(this);
list.setVisible(true);
}
public static void showInventory (ArrayList<String> theList) {
for (int i = 0; i < theList.size(); i++) {
System.out.println(theList.get(i));
}
}
public void mousePressed(MouseEvent e) { }
public void mouseReleased(MouseEvent e) {
Object index = list.getSelectedValue();
System.out.println("You have selected: " + index);
}
public void mouseEntered(MouseEvent e) { }
public void mouseExited(MouseEvent e) { }
public void mouseClicked(MouseEvent e) { }
public void paint(Graphics g) {
}
}