• 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

Cannot get images when running JNLP and Applet, but does on IDE?

 
Ranch Hand
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay so now I tried building my and setting it up for use on a webpage. When I click the JNLP or the Launch for web and it runs, it gives me an error trying to read in the pictures. The main pictures are all set, but when I try to calculate and change the pictures it gives me this




479 has to do with the location of the image. Originally I changed up my class name and folder(because it wasn't running under main) then I realized there is no main and that there was an option for webstart, which I did. There was an error refactoring which I thought was the issue here, however after fixing my refactoring issues this still persists..... All of my images were imported and are in my class's package. I don't know why the other pictures aren't there if the 3 main ones are there.... Anyone have any idea why I might be having this issue....

creates the main logo and shows it.

479 is it doesn't make any sense why one logo would load, and another wouldn't. It also doesn't make sense that this works when I run it via Netbeans IDE, but doesn't run via the web nor the JNLP launcher....



Is it possible that this could be the case??

Benefits of Separating Core Functionality From the Final Deployment Mechanism

Another way to create an applet is to just remove the layer of abstraction (separate top JPanel) and lay out all the controls in the applet's init method itself. The downside to creating the GUI directly in the applet is that it will now be more difficult to deploy your functionality as a Java Web Start application, if you choose to do so later.

In the Dynamic Tree Demo example, the core functionality resides in the DynamicTreePanel class. It is now trivial to drop the DynamicTreePanel class into a JFrame and deploy as a Java Web Start application.

Hence, to preserve portability and keep deployment options open, follow component-based design as described on this page.

http://docs.oracle.com/javase/tutorial/deployment/applet/developingApplet.html

I have everything coded in 1 JApplet Form in Netbeans, but I actually stumbled upon this today when learning more about applets.... Should I have it in a seperate class then call that class?

EDIT: In the include it shows all the pictures as well.. weird....
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay so I've been hearing the term "Code Base" around for a few days and finally found somthing here

http://docs.oracle.com/javase/tutorial/deployment/applet/data.html it says I should apparently be using one. In Netbeans there is a specification for local, web, etc. When I tried to code based on this I get this error




This is Calculator 34:

Applet.getCodeBase says this



So I'm not sure why I'm getting an Error... Do I have to be running it as an applet on the browser? Doesn't make sense why I'm having issues on the browser/jnlp from running on the IDE... I'm reinstalling Java now because last night when I installed 7.9 it now just keeps saying "install" and wont even let me view without installing...
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An IDE does not emulate a full-blown web server/web browser environment. The applet environment in particular is rather different, so I wouldn't expect any AppletContext/AppletStub methods to work properly.
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:An IDE does not emulate a full-blown web server/web browser environment. The applet environment in particular is rather different, so I wouldn't expect any AppletContext/AppletStub methods to work properly.



Thanks I just ran it and still getting the error... Not sure if I need the codebase, not sure what's going on, do you have any idea why the images aren't being read in, and if I do need the codebase which is what the Oracle doc says, why am I having an error?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you running Tomcat and the applet standalone now, without the help of any IDE? That's what I advocated, but I can't tell from your post whether or not that's what you're doing.
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:Are you running Tomcat and the applet standalone now, without the help of any IDE? That's what I advocated, but I can't tell from your post whether or not that's what you're doing.



No Tomcat, I created the applet and then deployed it via netbeans, and ran it with the browser launcher provided by netbeans. that and the JNLP launcher didn't work.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'll probably continue to have problems with this applet unless you deploy and run it from a web server (like Apache or Tomcat).
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:You'll probably continue to have problems with this applet unless you deploy and run it from a web server (like Apache or Tomcat).



Why is that? Also what entails getting one? I have to pay for it? I thoght I could run it normally without one... Do you have any idea why the images arent being found/ codebase? It's weird that they load up but after the initial init() the resources are gone? Which is why I looked into codebase but tht didn't work either...?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tomcat is free.

An IDE simply is not the same as a JVM running the applet in a browser; just accept it.
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:Tomcat is free.

An IDE simply is not the same as a JVM running the applet in a browser; just accept it.



I accept it and trust you, I'm just curious about the errors I was having in relation to what the applet is actually doing.. When do I need servers for applets? It seems like my code would be fine if I didn't have to get the resoruces... It doesn't make much sense..... I'm trying to learn all about this... Also why didn't the Oracle trail mention using servers? you say it's free but do we have to have a server where it runs or they provide all that, we just need the applet to run via it....

Also I see a lot of talk about Servers and Java EE.... I'm using normal Java SE... I just had to redownload Netbeans since the new patch messed up my location, and under EE had tomcat, so that was easy to get it, now to deploy it!


Any help is appreciated, thanks for your time sir!

Also installing the new EE I found somethinh called "Glassfish?" Seems like something similar?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java tutorials and Java books have always, as far as I can see, assumed that you already knew that an applet was a thing meant to be run in a browser, and therefore it must come from a web server. Although the Oracle server does say right up front

A Java applet is a special kind of Java program that a browser enabled with Java technology can download from the internet and run. An applet is typically embedded inside a web page and runs in the context of a browser.



So it's reasonable to say that you should have known that too. But you just need an ordinary web server which can serve HTML pages and the like, not an application server like Tomcat and definitely not a JEE server like Glassfish.

However if you don't intend to have a web site which serves your applet to the world at large, or at least to other computers, then there isn't much point in writing an applet.
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Java tutorials and Java books have always, as far as I can see, assumed that you already knew that an applet was a thing meant to be run in a browser, and therefore it must come from a web server. Although the Oracle server does say right up front

A Java applet is a special kind of Java program that a browser enabled with Java technology can download from the internet and run. An applet is typically embedded inside a web page and runs in the context of a browser.






So it's reasonable to say that you should have known that too. But you just need an ordinary web server which can serve HTML pages and the like, not an application server like Tomcat and definitely not a JEE server like Glassfish.

However if you don't intend to have a web site which serves your applet to the world at large, or at least to other computers, then there isn't much point in writing an applet.



Well I know that the point of an Applet is to run on the web, and if not then I would just use a normal Java app, but now I'm confused. Ulf is saying I need a Tomcat Server, but now you are saying I do not need one? So what's the point of these application servers then?

This also brings me back to my original question which hasn't; been answered yet. Why is my ImageIcon path having issues finding the resources after the Applet init() has been loaded? The images are found on the initial start up, but afterwards I get a nullpointer exeception. Which is what brought me to the codebase. Now with the codebase I am having errors...

So again, any idea what's going on? Paul? Ulf?

Thanks!
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What you need is a web server (which is what I said in my fist post). I later on mentioned Tomcat because in my experience it's one of the easiest to set up and get going with, but any server that contains a web server component will do - Apache httpd, Tomcat, GlassFish, IIS, etc.
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:What you need is a web server (which is what I said in my fist post). I later on mentioned Tomcat because in my experience it's one of the easiest to set up and get going with, but any server that contains a web server component will do - Apache httpd, Tomcat, GlassFish, IIS, etc.



Yeah it seemed like you meant I needed something like Tomcat or else it wouldn't do what I needed....

I'm creating an applet for a site that is already set up and everything. I would assume that now I don't need anything else? Which again brings me back to why am I getting errors >( :'(.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, are you running the applet off the server now? I can't tell from your post, and as I said, unless and until you do so you should expect problems.
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
using the codebase and running via my server I get




Seems no matter what I try I keep getting this error.... I've tried no codebase, web deploy and Local... I had the getcodeBase code, as well as the other image code and nothing... >(.

In netbeans we have choices for the codebase.

EDIT: Looking at the new error log I noticed it was launching from my own computer; however it launches differently then when I lauch it from the dist folder directly(which works except for the ImageIcon issue)....



http://netbeans.org/kb/docs/java/javase-jws.html

I found this. it says that the server has to be configured to run the files, which mine are not. It doesn't say anything special is needed to be done to deploy... They also use a regular application and run it locally using it's main? Applets don't have mains so I wasn't able to run it properly, according to their example.... I normally do the launches as shown in the link thogh...


Interestingly I made a new JFrame class and set it to the main and ran it. It complied and then ran like it did in the launch and as the netbeans link shows. It then ran the calculator still having the imageicon issue...

I still don't know why the IDE wouldn't have an environment set up to run the applets as if it was on a server, from the choices I assume that it should be able to run under the conditions specified (web, local, etc). I realized normally I was "testing" not "running" the application on the IDE.

The whole "some things might work on the web vs not doesn't really add up. Why would it work in the IDE, then during the a browser launcher it not working, as well as running the JNLP file locally. Then all of a sudden work via the site. I would assume the site would work the same as the launchers, and the same as the IDE. The test shows it running via normal means and the run is how it actually goes, I don't see any other way it could go, unless it just breaks even more...
codest.png
[Thumbnail for codest.png]
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cannot edit so here's my update. I was thinking that since the image base is looked at after the init() I decided to put the image base into the init and it accepted it, however I still got an ImageIcon error wtf....




After "testing" the code I got a codebase error so I know that the applet preview is what it should be, and the test is just a normal look, which will give an error on the codebase. We are getting somewhere, but now I'm going to debug and see WHY my codebase isn't working....

I do

as globals




this is my init. Warp is my logo which is already preset in Netbeans.... So the error occurs when I set P's icon.

@ 496


Netbean's auto generated code which work for Warp and the other Icon is

as stated before this doesn't work afterwords nor would image = new ImageIcon(getResource(warp)));;

Whenever I loook at the getCodeBase() it always talks about AppletStub.... Am I supposed to do something with this "stub?"


I also am trying to see if there is something wrong with what I'm reading from the Codebase...





EDIT: So I realized that during the debug it wasn't getting anything from the codebase as each img was null. I realized the init wasn't setting it, weird because the init setsVisible() for a few things and works... WEIRD.... So now I'm back to the old CodeBase problem...


Now I realized I had my codebase off, so I turned it on and realized where it was set, put all the images there and still having issues... meh.



Okay so I'm not sure WFSDFHSDAFSDAHFSDAH happened but now it works LOL.....

I changed it to setting the pictures at the start and then it turned blank, while the carts turned to what they were supposed to.... I was using [code=java]P.setIcon(image = new ImageIcon(getClass().getResource("/calculator/J.pg"))); /code] before it was new javax.swing etc etc, but I thought I tried the image = already, but it was set for H and worked so I copied it for P and it works. I'm not sure if I'm more angry or konfused LOL


EDIT: I ended up getting another error and realized that my O was supposed to be an 'o'...... Lulz so caps ended up probably messing me up this entire time.. sooo mad LOL.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic