Results 1 to 4 of 4
- 10-28-2011, 01:47 AM #1
Member
- Join Date
- Oct 2011
- Posts
- 20
- Rep Power
- 0
my code works fine but don't know if its the right way
i need to Pass in three integers corresponding to an RGB value and use the appropriate Color constructor to set the background color.
Java Code:import java.applet.*; import java.awt.*; public class AnAppletSubclass2b extends Applet { int r; int g; int b; Color color = new Color (r,g,b); public void init() { String parmStringRED = getParameter("red"); r = Integer.parseInt(parmStringRED); String parmStringGREEN = getParameter("green"); g = Integer.parseInt(parmStringGREEN); String parmStringBLUE = getParameter("blue"); b = Integer.parseInt(parmStringBLUE); Color color = new Color (r,g,b); System.err.println("The parameter are: " + parmStringRED + "," + parmStringGREEN + "," + parmStringBLUE); setBackground(color); } public void paint(Graphics g) { System.out.println("In paint: n = " + n); n++; } int n; }Java Code:<HTML> <HEAD> <TITLE> AnApplet With Parms </TITLE> </HEAD> <BODY> <p>Here is the output of my Program:</p> <APPLET CODE="AnAppletSubclass2b.class" WIDTH=150 HEIGHT=100> <PARAM name="red" value="25" > <PARAM name="green" value="120"> <PARAM name="blue" value="250"> </APPLET> </BODY> </HTML>
- 10-28-2011, 02:50 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Re: my code works fine but don't know if its the right way
There is a lot of unnecessary work. For instance, you don't need to initialize the color variable at the class level, you can simply declare it since it's being initialized in the init method.
You also shouldn't print with an err printstream if it isn't actually an error. Since you aren't printing errors, change System.err.println to System.out.println. The rest seems fine.Java Code:public class .... extends Applet{ int r, g, b; Color color; ... }
- 10-28-2011, 02:57 AM #3
Member
- Join Date
- Oct 2011
- Posts
- 20
- Rep Power
- 0
Re: my code works fine but don't know if its the right way
Thank you !!!!!
- 10-29-2011, 12:39 AM #4
Member
- Join Date
- Oct 2011
- Posts
- 20
- Rep Power
- 0
Similar Threads
-
HELP! Gui is running fine, don't know exactly how to code.
By cc11rocks in forum AWT / SwingReplies: 1Last Post: 02-12-2011, 05:36 PM -
Code runs fine but get compile error
By BillyB in forum New To JavaReplies: 4Last Post: 11-29-2010, 02:18 PM -
JMF works fine with javac BUT same code has problems with NetBeans 6.9.1
By WACman in forum NetBeansReplies: 1Last Post: 11-03-2010, 08:49 AM -
Please explain how this bit of code works.
By Allspark in forum New To JavaReplies: 4Last Post: 09-03-2010, 03:56 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks