• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how can i run an applet as an application?

 
Greenhorn
Posts: 3
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dears,
I have an Applet class, and I want to make it run as an application, so I wrote to following code:

public static void main(String args[]) {
JFrame app = new JFrame("Applet Container");
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
app.setSize(200, 100);
Hangman applet = new Hangman();
applet.init();
app.setLayout(new BorderLayout());
app.setSize(500,500);
app.getContentPane().add(applet, BorderLayout.CENTER);
app.setVisible(true);
}


Note: Hangman is the applet class. And if i run it, it work fine, but what I am tring to do, is to make it run as an application
When I run the above main, I got the following error:

Exception in thread "main" java.lang.NullPointerException
at java.applet.Applet.getCodeBase(Applet.java:152)
at Me.Hangman.init(Hangman.java:138)
at Me.Client.main(Client.java:54)
Java Result: 1


This error is came from this line in the Hangman class:

danceMusic = getAudioClip(getCodeBase(), "../../audio/dance.au");

GetCodeBase() method returns null, I need help on how can I make this method work properly, or maybe replace it with another method that may access my files to get resources?
Thank you in advance
 
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Despite what various articles claim, there's a lot more to running an applet as an application than sticking it in a JFrame. But you're in luck: the AppletsFaq answers this exact question.
 
mostafa darwiche
Greenhorn
Posts: 3
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much, you saved my life , I owe you man ... have a nice day
 
There's a way to do it better - find it. -Edison. A better tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic