Results 1 to 11 of 11
  1. #1
    Wallsurfer is offline Member
    Join Date
    Mar 2009
    Posts
    11
    Rep Power
    0

    Default 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);
           } 
    	  
    	  }
         }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  3. #3
    Wallsurfer is offline Member
    Join Date
    Mar 2009
    Posts
    11
    Rep Power
    0

    Default 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 :(

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  5. #5
    Wallsurfer is offline Member
    Join Date
    Mar 2009
    Posts
    11
    Rep Power
    0

    Default

    Yes. it is in a folder named C:\Users\Kevin\Desktop\Recent Web\ComputerScience\Applets

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  7. #7
    Wallsurfer is offline Member
    Join Date
    Mar 2009
    Posts
    11
    Rep Power
    0

    Default

    Shit I totally forgot that this is going to make an extra class automatically for me :P

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    ????? what ?????

  9. #9
    Wallsurfer is offline Member
    Join Date
    Mar 2009
    Posts
    11
    Rep Power
    0

    Default

    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

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    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?

  11. #11
    Wallsurfer is offline Member
    Join Date
    Mar 2009
    Posts
    11
    Rep Power
    0

    Default

    So I can make a folder named Sorter and put the 3 files in there and then type the code

    package Sorter;

    import java.awt.*;
    etc

    ?

Similar Threads

  1. Replies: 0
    Last Post: 10-04-2009, 03:47 PM
  2. errors for a java applet
    By darren345 in forum Java Applets
    Replies: 3
    Last Post: 04-24-2009, 11:41 AM
  3. Replies: 0
    Last Post: 02-01-2009, 09:43 AM
  4. applet won't run in browser...
    By shwein in forum Java Applets
    Replies: 6
    Last Post: 10-17-2008, 07:24 PM
  5. Replies: 2
    Last Post: 09-12-2008, 07:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •