Results 1 to 11 of 11
- 10-11-2009, 09:49 AM #1
Member
- Join Date
- Mar 2009
- Posts
- 11
- Rep Power
- 0
Applet Errors runs in jGrasp/ not in Eclipse and not in browser
I have been using jGrasp to code mostly and this applet runs fine with jGrasp. When I try to use Eclipse or run in IE, Netscape, Safari, or Chrome.
Thanks for any help.
Java Code:// packages import java.awt.*; import java.applet.*; import java.awt.event.*; import java.util.Random; import javax.swing.JApplet; // parent class public class Sorter extends Applet{ // declare variables private Button push; // declare 2 arrays with 20 empty elements int [] selectSort = new int [20]; int [] insertSort = new int [20]; // declare a new random generator Random partyInt = new Random(); int xQue, height, yQue, yHeight; int count, f, g, i = 0 , k = 0; boolean foo = true; boolean bar = false; boolean terminar = false; public Sorter(){ for(int b = 0; b< selectSort.length; b++){ int bonkers =(int) ( Math.random()*20 ); selectSort[b] = bonkers; insertSort[b] = bonkers; } } // sets up init which will set up a blue background and //place a button on the screen public void init() { setBackground(Color.cyan); push = new Button("Sort"); push.addActionListener (new ButtonListener()); add (push); } public void paint(Graphics g) { if (foo){ g.setColor(Color.red); rectMaker(g, selectSort, 150); g.setColor(Color.yellow); rectMaker(g, insertSort, 300); foo=false; } else if(bar){ g.setColor(Color.red); rectMaker(g, selectSort, 150); g.setColor(Color.yellow); rectMaker(g, insertSort, 300); } if(count == selectSort.length && count == insertSort.length){ terminar = true; } if(terminar){ g.drawString("Done", 150, 125); } } private class ButtonListener implements ActionListener{ public void actionPerformed(ActionEvent event) { k++; i++; selectionSort(selectSort); insertionSort(insertSort); count +=1; bar=true; String str = "Pass " + count; push.setLabel(str); repaint(); } } // selection sort method public void selectionSort(int[] list){ int min; int temp; if( i < list.length-1){ min = i; for (int j = i+1; j < list.length; j++) if (list[j]>list[min]){ min = j; } // Swap the values temp = list[min]; list[min] = list[i]; list[i] = temp; } } // insertion sort method public void insertionSort(int[] list){ if(k < list.length){ int key = list[k]; int position = k; // Shift larger values to the right while (position > 0 && list[position-1] >= key ){ list[position] = list[position-1]; position--; } list[position] = key; } } public void rectMaker(Graphics g, int [] list, int height ){ // defaults +2 height and x variables int xBox, yBox, wBox, hBox, xBox2, hBox2; xBox = 10; yBox = height; wBox = 10; // iterate threw the array giving out Height attributes for (int q = 0; q < list.length; q++){ xBox = xBox+10; hBox = list[q]; g.drawRect(xBox, yBox, wBox, hBox); } } }
-
- 10-11-2009, 06:15 PM #3
Member
- Join Date
- Mar 2009
- Posts
- 11
- Rep Power
- 0
Errors
java.lang.NoClassDefFoundError: /Applets/Sorter (wrong name: Sorter)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknow n Source)
at sun.plugin2.applet.Applet2ClassLoader.findClass(Un known Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unk nown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unk nown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.lang.NoClassDefFoundError: /Applets/Sorter (wrong name: Sorter)
I thought that usually that was because the class name and the filename didn't match but I have tried several times to make sure and that isn't the case :(
-
You may be packaging the applet wrong. What package is it in? Applets?
- 10-11-2009, 06:27 PM #5
Member
- Join Date
- Mar 2009
- Posts
- 11
- Rep Power
- 0
Yes. it is in a folder named C:\Users\Kevin\Desktop\Recent Web\ComputerScience\Applets
-
Right, but what package declaration are you using? I see none in the current code you've posted.
- 10-11-2009, 06:29 PM #7
Member
- Join Date
- Mar 2009
- Posts
- 11
- Rep Power
- 0
Shit I totally forgot that this is going to make an extra class automatically for me :P
-
????? what ?????
- 10-11-2009, 06:39 PM #9
Member
- Join Date
- Mar 2009
- Posts
- 11
- Rep Power
- 0
Sure when I compile that it will make two extra class files for me yeah I don't have a package declaration all the files are in the same folder in /Applets/Sorter.class, Sorter$1.class, and Sorter$ButtonListner.class
do i need to declare a package if so what should i name it
-
You shouldn't use the default package (no package), so yes, you should declare a package and place your code in the correct directory to correspond to that package. What you name it is up to you and your directory structure. Have you read the Sun tutorial on packages?
- 10-11-2009, 07:07 PM #11
Member
- Join Date
- Mar 2009
- Posts
- 11
- Rep Power
- 0
Similar Threads
-
Problem: program runs with eclipse not with dat file
By livnihai in forum EclipseReplies: 0Last Post: 10-04-2009, 02:47 PM -
errors for a java applet
By darren345 in forum Java AppletsReplies: 3Last Post: 04-24-2009, 10:41 AM -
Eclipse failing to start on Vista 64bit Home Prem.. while i got no prob runnin JGrasp
By kendy in forum EclipseReplies: 0Last Post: 02-01-2009, 08:43 AM -
applet won't run in browser...
By shwein in forum Java AppletsReplies: 6Last Post: 10-17-2008, 06:24 PM -
Q:App development that runs in a browser, also as a desktop on all platforms
By gsmurthy30 in forum New To JavaReplies: 2Last Post: 09-12-2008, 06:10 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks