Applet. Not Initialized.

Added an audio file. Applet started to not get initialized.

Page 1 of 1

3 Replies - 2935 Views - Last Post: 01 March 2010 - 03:13 PM Rate Topic: -----

#1 MystiqueDragon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 21-February 10

Applet. Not Initialized.

Posted 01 March 2010 - 12:31 PM

Hello.
I'm here and back again to bother some of you about my problem.
I shall go straight to the point now since I don't have much time to dilly-dally.
So here's my code:
//Did I place all of them in the right package?
import javax.swing.JApplet;
import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Font;
import java.net.URL;

public class abscbn extends JApplet
{
	Font a = new Font("Monotype Corsiva", Font.BOLD, 72);
	AudioClip song;
	URL path;
	
        //I am not so sure about this whole audio thing.
        //I tried to follow the instructions step by step in the other topics with the same problem as
        //mine but it seems I made my program worse.
	abscbn(String FoR) //FoR is the filename of my .mid file
	{
		try
		{
			path = new URL(getCodeBase(), "FoR.mid");
                        //tried to remove the quotation marks but, I get an error.
			song = Applet.newAudioClip(path);
		}
		catch(Exception e) {}
	}
	
	public void playSound()
	{
		song.loop();
	}
        //I was also wondering if I should place all class here? The stopSound() and the
        //playSoundOnce()?
	
	public void init()
	{
		abscbn bg = new abscbn("FoR.mid");
		bg.playSound();
	}
        //should I place the init() class somewhere else?	

	public void paint(Graphics g)
	{
		//super.paint(g);
		g.setColor(Color.BLACK);
		g.fillRect(0,0,700,700);
	
		g.setFont(a);
		g.setColor(Color.WHITE);
		g.drawString("A    B    S", 225, 70);
		g.drawString("C    B    N", 210, 553);

		g.setColor(Color.WHITE);
		g.fillRect(154,92,420,406);
		
		g.setColor(Color.BLACK);
		g.fillRect(155,93,418,404);	
		
		g.setColor(Color.RED);
		g.fillOval(170,105,386,377);
		
		g.setColor(Color.BLACK);
		g.fillOval(192,120,342,346);
		
		g.setColor(Color.GREEN);
		g.fillOval(226,162,274,266);
		
		g.setColor(Color.BLACK);
		g.fillOval(242,181,242,228);
			
		g.setColor(Color.BLUE);
		g.fillOval(266,212,193,169);
			
		g.setColor(Color.BLACK);
		g.fillOval(291,231,143,129);
			
		g.setColor(Color.WHITE);
		g.fillRect(343,261,37,237);
	}
}


And here is the html file:
<html>
<applet code="abscbn.class" width="700" height="700">
</applet>
</html>



So like I said, I hopped from one topic to another with the same problem as mine.
The real problem in my codes is that, before I added the codes for the audio, my program was sure running fine. It displays everything I have drawn.
BUT. After I added the codes for the audio file, whenever I run the html file, the applet viewer appears but the status bar states that my applet was not initialized.
I do make sure to compile the .java file first before running the .html file but still, no avail.
I tried opening the .html file in my browser(Firefox) but I get an error (which I could not understand).
Also, I made sure that all my files are saved under the same folder.
So yes, I'm here to ask the question that has been asked so many times. Sorry.
Hope someone could help me?


Is This A Good Question/Topic? 0
  • +

Replies To: Applet. Not Initialized.

#2 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2639
  • View blog
  • Posts: 11,146
  • Joined: 20-September 08

Re: Applet. Not Initialized.

Posted 01 March 2010 - 12:52 PM

Quote

 catch(Exception e) {}



Don't ignore exceptions - that will just lead to bugs that are impossible to find - print the stack trace

Have a look in the applet console after you've made the above change
Was This Post Helpful? 0
  • +
  • -

#3 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2870
  • View blog
  • Posts: 11,021
  • Joined: 15-July 08

Re: Applet. Not Initialized.

Posted 01 March 2010 - 02:27 PM

g00se, when I ran it, it didn't even get that far...You get an Instantiationerror.

java.lang.InstantiationException: abscbn
	at java.lang.Class.newInstance0(Class.java:340)
	at java.lang.Class.newInstance(Class.java:308)
	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)
load: abscbn.class can't be instantiated.



Because the applet STARTS in init(), I'm assuming that you cannot create an instance of one. I caused your program to run correctly with this code:
        public void load( String FoR) 
        {
                try
                {
                        path = new URL(getCodeBase(), FoR); // Referece the String being passed
                        song = Applet.newAudioClip(path);
                }
                catch(Exception e) {System.out.print("No File exists");}
        }
        
        ...
        
        public void init()
        {
                // Call the load() method.
        	load("FoR.mid");
                playSound();
        }



By the way, your terminology is messed up. a class is a blueprint for an object and has the word "class" before it. You keep calling methods classes.

Methods look like this:
public void init().
Was This Post Helpful? 1
  • +
  • -

#4 MystiqueDragon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 21-February 10

Re: Applet. Not Initialized.

Posted 01 March 2010 - 03:13 PM

Quote

By the way, your terminology is messed up. a class is a blueprint for an object and has the word "class" before it. You keep calling methods classes.


Ah yes! I'm sorry.
Thank you for pointing that out.
I keep on remembering my C++ lessons.
*sweatdrops*

---

Thank you so much for this!
It helped me a lot.
Thank you!
And sorry for the mistake yet again.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1