This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Faster Way to load resources?  RSS feed

 
Jose Kreif
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am running the code found here: http://home.aubg.edu/students/GGG120/stuff/java/DanielLianghtml/FlagAnthemWithLineNumber.html

It comes from my Java Textbook I got 4 years ago. There is a folder with 7 songs in it and this program will load all of them.
It takes roughly 1 or more seconds per song. This makes the program take up to 10 seconds to load.

This is the line of code that takes all the time


Is there another method to speed this up?

It may be a poor example, but we all heard of Minecraft, yes? That uses java and uses way more resources than this program.
 
Les Morgan
Rancher
Posts: 768
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you need to load all of them before you start? Can you load one and have it playing while you load another? Take a lesson from most of the OS's, especially Windows, and load enough to get going then load everything else in the background--if you can.

Jose Kreif wrote:I am running the code found here: http://home.aubg.edu/students/GGG120/stuff/java/DanielLianghtml/FlagAnthemWithLineNumber.html

It comes from my Java Textbook I got 4 years ago. There is a folder with 7 songs in it and this program will load all of them.
It takes roughly 1 or more seconds per song. This makes the program take up to 10 seconds to load.

This is the line of code that takes all the time


Is there another method to speed this up?

It may be a ppor example, but we all heard of Minecraft, yes? That uses java and uses way more resources than this program.
 
Jose Kreif
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Les Morgan wrote:Do you need to load all of them before you start? Can you load one and have it playing while you load another? Take a lesson from most of the OS's, especially Windows, and load enough to get going then load everything else in the background--if you can.


Thanks. I figured it out.


I removed the for loop at the start and just loaded the first song in the index. Then I created a method with



That loads the rest. Then at the end of main method I call that method



This allows the songs to load after the frame pops up, leaving you waiting only 1-2 seconds.

Now, if the user tries to play a song that has not loaded yet, it will crash the program.
So I wrapped the code in the event listener with this





Thanks for the tip, mate!
 
Campbell Ritchie
Marshal
Posts: 55745
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Are you still using applets? Most people regard them as obsolete and most web browsers won't open them any more.
 
Jose Kreif
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Welcome to the Ranch

Are you still using applets? Most people regard them as obsolete and most web browsers won't open them any more.


It's not a true applet. It does not run in the browser. I run it from command line "java className" or turn it into a .jar and run it that way.

It extends JApplet, but that's it. I was discussing it a couple weeks ago with my department, I understand running java in the browser is frowned upon and is becoming obsolete.


I'd also add, it has a main method, which isnt typically something applets have.
 
Campbell Ritchie
Marshal
Posts: 55745
163
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jose Kreif wrote:. . . I'd also add, it has a main method, which isnt typically something applets have.
That is why you can run it with the java tool; you would normally load an applet in an html file and use the appletviewer tool.
 
Jose Kreif
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
Jose Kreif wrote:. . . I'd also add, it has a main method, which isnt typically something applets have.
That is why you can run it with the java tool; you would normally load an applet in an html file and use the appletviewer tool.


Correct. I remember doing it years ago when taking Java in college. It's been a long time, so I'm not as good as I once was in Java. Trying to relearn it on my own. I might just take an online course to refresh my skills in it and get upto date.
While Java isn't a language I work with in my job, it's not frowned upon if I was to build some stuff to automate and make thing easier for our people.


Ontopic
I'm glad to have found a semi-good solution to loading the program without needing to sit through 10 seconds of waiting.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!