OK so I'm doing an ArrayList into a (awt) List and I'm getting the following errors when compiling.
C:\Users\Dan\Documents\DanJavaGen\ArrayList_INV.java:29: cannot find symbol
symbol : constructor List(java.lang.Object[])
location: class java.awt.List
list = new java.awt.List(arr.toArray());
^
C:\Users\Dan\Documents\DanJavaGen\ArrayList_INV.java:50: cannot find symbol
symbol : method getSelectedValue()
location: class java.awt.List
System.out.println("You have selected: " + list.getSelectedValue());
^
2 errors
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.*;
public class ArrayList_INV extends JApplet implements MouseListener {
public static String newline;
public static java.awt.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 java.awt.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) {
System.out.println("You have selected: " + list.getSelectedValue());
}
public void mouseEntered(MouseEvent e) { }
public void mouseExited(MouseEvent e) { }
public void mouseClicked(MouseEvent e) { }
/**
public void paint(Graphics g) {
}**/
}
What is wrong? Thanks.