• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Java AWT applet

 
Ranch Hand
Posts: 38
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


The output in applet window is :

Font Name is: Not Found
Font Size is:-1
Leading:0.0
Active: false


Why does it goes in The Exception in every block of code?
 
Saloon Keeper
Posts: 13366
295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because apparently whatever you're passing as fontSize, it's not an integer.
 
Saloon Keeper
Posts: 7162
165
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It works fine for me using Java 8 on OS X. Offhand, I can't think of a reason why it wouldn't work elsewhere, since appletviewer would presumably work the same on all platforms.

As an aside, you should get in the habit of using double quotes around both names and values: <param name="fontName" value="Courier"> rather than <param name = fontName value = Courier>.

And, of course, applets are completely obsolete by now, so you should switch to learning standalone applications (or Java Web Start applications) instead, using JavaFX or Swing rather than AWT.
Screen-Shot-2017-04-10-at-09.49.46.png
[Thumbnail for Screen-Shot-2017-04-10-at-09.49.46.png]
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suspect Tim is correct and it's because of the missing quotes.

Whilst Applets should work the same on all platforms the html that kicks off the Applet is read and processed by the browser and it may be that the browser you are using doesn't understand the param tag with missing quotes whereas Tim's browser has made some correct assumptions about what you intended to write. Can you make the changes he suggested and let us know if that has fixed the problem.

BTW Tim is also correct about Applets being obsolete, I suggest you don't spend too much time learning how to write code for them.
 
Tim Moores
Saloon Keeper
Posts: 7162
165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I suspect Tim is correct and it's because of the missing quotes.


Actually, I tried the unchanged source code and it worked fine for me. So I can't even think of something to try instead.
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you use AppletViewer or your browser?
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suppose there is always the unlikely possibility that the OP's system doesn't have the "Courier" font installed.
 
Tim Moores
Saloon Keeper
Posts: 7162
165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I used appletviewer via "appletviewer Parameter_Passing.java".
 
Rancher
Posts: 4504
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

OP's system doesn't have the "Courier" font installed.


The code doesn't use the values of the parameters for anything but to display some text in the window.
This works for me using appletviewer,  ie  the values are read and shown in the window:
 
VarunS Singh
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I changed as you suggested , but still not working....
 
VarunS Singh
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using Netbeans, and as these Html code is written as comment , does it really matters , regarding the double coutes?
 
Marshal
Posts: 26909
82
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It never hurts to use well-formed HTML. And since your error messages from the original post tell me that your applet parameters are being ignored, it might be that using sloppy HTML is a problem. It might also be that something else is causing Netbeans to fail to notice the parameters.
 
Tim Moores
Saloon Keeper
Posts: 7162
165
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe NetBeans works differently than appletviewer - did you try that one?
 
VarunS Singh
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are  rights guys it is actually working ok in Appletviewer
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic