I can't get my applet to run on the web?!?! Help!!!

Whenever I try to run my two .java's on the web, I get the error messages in my java console, I got the two applets to run perfectly in Netbeans but I just can't figure out how to get them to run on the web... HELP!!!

-

Console Error

-

java.lang.ClassCastException: Sales

at sun.applet.AppletPanel.createApplet(Unknown Source)

at sun.plugin.AppletViewer.createApplet(Unknown Source)

at sun.applet.AppletPanel.runLoader(Unknown Source)

at sun.applet.AppletPanel.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

java.lang.ClassCastException: Main

at sun.applet.AppletPanel.createApplet(Unknown Source)

at sun.plugin.AppletViewer.createApplet(Unknown Source)

at sun.applet.AppletPanel.runLoader(Unknown Source)

at sun.applet.AppletPanel.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

Two Applets

// ****************************************************************

// Main.java

//

// Instantiates and starts the Sales class

//

// ****************************************************************

import java.util.*;

public class Main

{

public static void main(String[] args)

{

// instantiate the class

int check = 0;

System.out.println("Enter '1' for part 6 (a)");

System.out.println("Enter '2' for part 6 (b)");

Scanner scan = new Scanner(System.in);

check = scan.nextInt();

if(check == 1){

System.out.println("\nEnter the number of Sales Persons: ");

int number = scan.nextInt();

Sales mySalesInfo = new Sales(number);

mySalesInfo.testMe();

}

else{

Sales mySalesInfo = new Sales(5); //change here for parameter (Q.6. Part . b.)

mySalesInfo.testMe();

}

// and start

}

}

// ****************************************************************

// Sales.java

//

// Reads in and stores sales for each of 5 salespeople. Displays

// sales entered by salesperson id and total sales for all salespeople.

//

// ****************************************************************

import java.util.Scanner;

public class Sales{

int SALESPEOPLE;

int sum;

int sales[];

public Sales(){

this.SALESPEOPLE = 5;

this.sales = new int[SALESPEOPLE];

}

public Sales(int a){

this.SALESPEOPLE = a;

this.sales = new int[SALESPEOPLE];

}

public void testMe(){

getSalesInput();

provideSalesOutput();

provideAverage();

provideMax();

provideMin();

getHigherSales();

getNewID();

}

public void getSalesInput(){

Scanner scan = new Scanner(System.in);

for (int i=0; i<sales.length; i++)

{

System.out.print("Enter sales for salesperson " + i + ": ");

sales = scan.nextInt();

}

}

public void provideSalesOutput(){

System.out.println("\nSalespersonSales");

System.out.println("--");

sum = 0;

for (int i=0; i><sales.length; i++)

{

System.out.println("" + i + " " + sales);

sum += sales;

}

System.out.println("\nTotal sales: " + sum);

System.out.print("");

}

public void provideAverage(){

int average;

average = sum/sales.length;

System.out.println("\nAverage: " + average);

System.out.print("");

}

public void provideMax(){

int maxID = -1;

int maxSale = -1;

for (int i=0; i><sales.length; i++)

{

if(sales > maxSale){

maxID = i;

maxSale = sales;

}

}

System.out.println("\nSales person "+ maxID +" had the highest sale with $" + maxSale);

System.out.print("");

}

public void provideMin(){

int minID = -1;

int minSale = Integer.MAX_VALUE;

for (int i=0; i<sales.length; i++)

{

if(sales >< minSale){

minID = i;

minSale = sales;

}

}

System.out.println("\nSales person "+ minID +" had the lowest sale with $" + minSale);

System.out.print("");

}

public void getHigherSales(){

Scanner scan = new Scanner(System.in);

System.out.print("\nEnter a value for higher sales: ");

int value = scan.nextInt();

System.out.println("\nSales Higher than $"+ value + " are: ");

System.out.println("\nSalespersonSales");

System.out.println("--");

int s = 0;

for (int i=0; i<sales.length; i++)

{

if(sales > value){

System.out.println("" + i + " " + sales);

s++;

}

}

System.out.println("\nTotal Salespeople: " + s);

System.out.print("");

}

public void getNewID(){

System.out.println("\nNew IDs updated are: ");

System.out.println("\nSalespersonSales");

System.out.println("--");

sum = 0;

for (int i=0; i<sales.length; i++)

{

System.out.println("" + (i+1) + " " + sales);

sum += sales;

}

System.out.println("\nTotal sales: " + sum);

System.out.print("");

}

}>

[5289 byte] By [jamocamaca] at [2007-11-27 2:31:16]
# 1
Those don't look like applets to me. I don't see anything that extends Applet or JApplet. And anyway, using System.in and System.out is not the way to communicate with users in an applet. You should spend a few minutes finding out what an applet is before you continue.
DrClapa at 2007-7-12 2:45:54 > top of Java-index,Java Essentials,Java Programming...
# 2

Three major problems with that.

1. Their is no console for an applet to output stuff or take in stuff so you will have to use some GUI stuff.

2. Applets should not have a main method. The use init() start() or run() (if I remember correctly).

For simple purposes any of those methods can be used where you would normally use a main method.

3. That code is not an applet as none of the classes extend Applet

To see the differences in the hook methods (statr, run, init) and how to do applets properly see here: - http://java.sun.com/docs/books/tutorial/reallybigindex.html

look for the section on Applets

JNameNotTakena at 2007-7-12 2:45:55 > top of Java-index,Java Essentials,Java Programming...
# 3

> Three major problems with that.

>

> 1. Their is no console for an applet to output stuff

> or take in stuff so you will have to use some GUI

> stuff.

>

> 2. Applets should not have a main method. The use

> init() start() or run() (if I remember correctly).

> For simple purposes any of those methods can be used

> where you would normally use a main method.

>

Slight correction ... Applets can have a main method ... it's just not needed/used/helpful

> 3. That code is not an applet as none of the classes

> extend Applet

>

> To see the differences in the hook methods (statr,

> run, init) and how to do applets properly see here: -

> http://java.sun.com/docs/books/tutorial/reallybigindex

> .html

> look for the section on Applets

abillconsla at 2007-7-12 2:45:55 > top of Java-index,Java Essentials,Java Programming...
# 4
so is there any hope for this or am i totally screwed?
jamocamaca at 2007-7-12 2:45:55 > top of Java-index,Java Essentials,Java Programming...
# 5
I don't think you're screwed. You just need to find out what an applet is BEFORE you write one, rather than writing random code and hoping it will be an applet.
DrClapa at 2007-7-12 2:45:55 > top of Java-index,Java Essentials,Java Programming...