PDA

View Full Version : Lists in Java Applets!


UrbanTwitch
02-03-2010, 02:32 AM
I am using TextPad, not notepad. Anyway... when compiling I get:
Note: C:\Users\Dan\Documents\Java\school\RockPaperScissors.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

Tool completed successfully


But when I run it the FIRST TIME... I get the error:

load: class .class not found.
java.lang.ClassNotFoundException: .class
at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:194)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:127)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:603)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:785)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:714)
at sun.applet.AppletPanel.run(AppletPanel.java:368)
at java.lang.Thread.run(Thread.java:619)

When I run it AGAIN ... it works.

Hre's my code:
/**
Program: Rock Paper Scirros
Programmer:
Date: 02.01.2010

**/

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.awt.Graphics;
import java.util.Random;


public class RockPaperScissors extends java.applet.Applet implements ActionListener
{

Image Rock, Scissors, Paper;
String outText;
int userRoll, compRoll, randomInt;

TextField test = new TextField(10);
Button rollButton = new Button("Roll!");
Button statsButton = new Button("More Stats!");
List selectChoice = new List();
TextArea status = new TextArea(null, 5,25, TextArea.SCROLLBARS_VERTICAL_ONLY);

Random randomGenerator = new Random();

public void init()
{
setLayout( new BorderLayout() );
add("North",rollButton);
add("East", statsButton);
add("South", status);
selectChoice.addItem("Rock");
selectChoice.addItem("Paper");
selectChoice.addItem("Scissors");
add("West",selectChoice);

status.setText("Welcome to Rock Paper Scissors!\nIf you don't know how to play... ask someone near you. If there is no one near you, stop living under a rock.");
status.setEditable(false);
rollButton.addActionListener(this);
statsButton.addActionListener(this);
Rock = getImage(getDocumentBase(), "rock.PNG");
Scissors = getImage(getDocumentBase(), "scissors.PNG");
Paper = getImage(getDocumentBase(), "paper.PNG");
}

public void actionPerformed(ActionEvent e)
{

if (e.getSource() == statsButton) {
status.append("\nChecking stats...");
}else{
repaint();
}



}

public void paint( Graphics g ) {
int randomInt = randomGenerator.nextInt(4);
int compRoll = randomGenerator.nextInt(4);
String intToStr = Integer.toString(randomInt);
test.setText(intToStr);

int x1 = 60;
int y1 = 80;

int x2 = 170;
int y2 = 80;

if (randomInt == 3) {
g.drawImage(Rock,x1,y1,this);
}else if (randomInt == 2) {
g.drawImage(Paper,x1,y1,this);
}else {
g.drawImage(Scissors,x1,y1,this);
}
if (compRoll == 3) {
g.drawImage(Rock,x2,y2,this);
}else if (compRoll == 2) {
g.drawImage(Paper,x2,y2,this);
}else {
g.drawImage(Scissors,x2,y2,this);
}
}



}

It has to do with my list box... anyone know a up-to-date method to listbox?

Thank you.

Fou-Lu
02-03-2010, 07:08 PM
I didn't even know that List was a class before!
I started learning java with java5, so it must have been removed by then. List itself is an interface, not a class. List is a type of Collection and you can store any type of known list inside of a List.

List l = new LinkedList();


Common lists to use are LinkedList, Vector, Stack, ArrayList.
I assume this has probably been removed from you're other code (I copied the other and never noticed a compilation issue aside from serial whines), but its good to know what the issue is (I assume this is the issue).