This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Applets and the fly likes Can't draw a string even the Graphics object isn't null! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Can Watch "Can New topic
Author

Can't draw a string even the Graphics object isn't null!

Howard Ting
Greenhorn

Joined: Feb 17, 2004
Posts: 19
Hello,
I have an applet that need to read a large image (9200x9200). For not haging the users around, unable to do anything but wait, I use a class extending Thread to load the image so that the users can quit the applet as they want.
My problem is I can't draw a string showing the loading procedure. I'm doing it this way: Getting the Graphics object in the loading class and drawing the loaded data ratio, but it's not working. Here's a part of my code:



"g is not null." is printed during loading, so this is not a question about getGraphics(), but I still get nothing shown on the screen.
What's the problem with it? If this is not a right way, why not?

Any reply is appreciated~
jay kumar
Greenhorn

Joined: Oct 06, 2004
Posts: 12
why dont u use println to print the value u r using in drawString(),
, might be that the value itself is null, and dont forget to check for exceptions !!!


JAY KUMAR CHANDRAN<br />Sun Certified Java Programmer 1.4.2
Howard Ting
Greenhorn

Joined: Feb 17, 2004
Posts: 19
Thanks, jack, you're right. Now I'm printing any messenge in the console window. It's convenient, yet it only works with the appletviewer...
I found the solution to this problem somehow, which is putting the getGraphics() maethod in the reading loop. I don't know why, so I'll appreciate if someone can explain it for me.
Vlado Zajac
Ranch Hand

Joined: Aug 03, 2004
Posts: 245
I don't understand your solution. I would put the painting code in overriden paint method or use Label or JLabel for displaying text.
 
jQuery in Action, 2nd edition
 
subject: Can't draw a string even the Graphics object isn't null!
 
Similar Threads
drawImage not getting the image drawn before printing!
how to use drawImage in an object
Display Image in an Applet
Need help with my game.
using a frame inside an applet