• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

problem with parameters

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry....I know I'm supposed to ask this in the applet board, but no one over there is answering me so I thought I'd post my question here to see if anyone can be of help. Here's my original post.
Hi,
I'm just starting to learn applets and I've been reading about passing parameters to an applet to set up a message to be displayed. So, I figured that I could also set up an applet to use the getParameter method for the foreground color, background color, and message to display. However, I'm getting errors when I try to compile it and was wondering if you have to do something special when using the getParameter for the colors? Thanks. Here's my code if it helps clear up what I'm trying to do.


 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what errors are you getting when you try to compile this?
 
tyler jones
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually I changed my code around a bit to this but I'm still getting errors.
I'm getting 3 errors. Here's what they say.
error 1 : has a pointer below n in new
first.Java:11 cannot resolve symbol
symbol : constructor Font (java.lang.String,int,java.lang.String)
location : class java.awt.Font
Font f = new Font(theFontName, Font.BOLD, size);
error 2: this has a pointer for the last line below the n in new
first.Java:12 cannot resolve symbol
symbol : constructor Color (java.lang.String)
location: class java.awt.Color
Color c = new Color(c1);
error 3: this has a pointer for the last line below the n in new
first.Java:13 cannot resolve symbol
symbol : constructor Color (java.lang.String)
location: class java.awt.Color
Color b = new Color(b1);

And finally, here's my new code.

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your problem is not with the parameters or the way you are retrieving them. The errors you are getting are because you are trying to use constructors that aren't there. To create a new Color you will have to pass in some RGB values. To make a new Font you have to pass a string representing the font name, a style, and a size. Check this link for more details. You can read up on Color and Font and decide which constructor you want to use. Good luck!
 
tyler jones
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand that I need to pass strings for the font and rgb values for the colors. That's why I have my parameters in my html set up like:

(I don't remember if these are the actual parameter names I use, but you get the idea)
I thought by pulling these in through the getParameter, that it would work correctly. I appreciate the link you included, but sun's reference is difficult to work with and understand. Could you offer any more insight or explanation? Thank you very much for your time and help!
[This message has been edited by tyler jones (edited December 13, 2000).]
[This message has been edited by tyler jones (edited December 13, 2000).]
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no Color constructor that takes a String as a parameter. You cant do:
Color c = new Color("1,225,34");
You need to do:
Color c = new Color(1, 225, 34);
Since you have defined theFont as an instance variable, the constructor is run before you have loaded anything into theFontName.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two solutions that I see for your RGB problem. The first (and I think the easiest) is to split your parameters into three ( one for R, one for G, and one for B). Then when you get your parameters into three string variables, you can convert each one to an integer using

The other solution is to keep your parameters as they are and parse the string for the three substrings. Then convert these into the integer values that you need. This will probably involve a StringTokenizer and will be more complicated.
Also, as Thomas pointed out, you are calling the constructor for your Font before your init() has loaded the parameter from HTML, so you will have to fix that problem, too.
 
It's a tiny ad only because the water is so cold.
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic