[Logo]
Forums Register Login
null pointer?
hi. i cant get this applet running. here is the code:-

this applet have 3 JTextField which represents red, green and blue. when a user input 3 values ranging between 0 to 255 and press enter, the applet will draw a fill rectangle(100,100,100,100) on a canvas (with white background). the color of the rectangle corresponds to the value input from the user. the problem is, when enter is pressed the following exception is throwed:-
Hi Syamsul,
The problem is that your Graphics reference is null. In your init() method, if you will change this:

to this:

then it should work. The problem here is that if you call canvas.getGraphics() before adding it to the applet's content pane, then it's graphics has not been set.
Hope this helps,
Michael Morris
thanks!
I have a knack for fixing things like this ... um ... sorry ... here is a consilitory tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database


This thread has been viewed 671 times.

All times above are in ranch (not your local) time.
The current ranch time is
Feb 20, 2019 08:13:30.