I'm new and have a stupid question...
Hi,
Im new to JAVA and have a probably stupid question wich my study books don't say anything about...
When I use
System.out.print("");
to show some text on screen I just get a grey box without text.
Im using Internet Explorer 5
JAVA 2 IDE
Forte 2.0
Please help me out!
When nothing shows on screen I don't know what I'm donig is right or wrong!
[418 byte] By [
omegaxxx] at [2007-9-26 2:14:03]

Is this in an applet or an application? In applets System.out is redirected to a java console that is invisible by default in most browsers and nothing appears on screen.
It's an Applet.(.java and then compiled to .class)What do I need to type to get text to appear in my browser?Thanks for helping out!
Hi,
You can use the drawString method to draw on the canvas of the applet. The good place to do this is in the paint method of the applet:
public void paint(Graphics g) {
g.drawString("your text here", 20, 20);
}
Hope this helps,
Kurt.
Thanks you guys for helping me out!Greetings,Menno.
I tried System.out.print("");andpublic void paint(Graphics g) {g.drawString("your text here", 20, 20);}But I still can't get any text to appear in my browser!Can someone sent me the exact code with some explanation ?Please help !
What about settinng foreground color to something distinctive from gray background?And how big is your applet canvas? ( if it's 10x10, then drawing text at 20x20 would not lead to anything...
Let me guess... you are extending javax.swing.JApplet instead of java.applet.Applet, aren't you?
Here's the complete code for a browser-friendly "Hello World"-applet:import java.applet.Applet;
import java.awt.Graphics;
public class HelloWorld extends Applet {
public void paint(Graphics g) {
g.drawString("Hello World!", 10, 20);
}
}
And HTML for it:
<applet code=HelloWorld height=50 width=100>
</applet>
If you are using swing (which is not supported in the browsers' default VM), you can enable your browser to use the plugin jre by converting your html page with the html converter. You can download this from http://java.sun.com/products/plugin/1.3/converter.html
Also be aware that your browser might have cached older versions of your .class files. You might need to delete them first.
I recommend using the appletviewer to test your applet first. Open a command line and run:
appletviewer your_page.html
I would like to thank you all for helping me out !I'll try everything and when it's done I'll give you the Duke Dollars.Thanks!Menno.
Well now I know what was wrong,
It wasn't the JAVA but the HTML !
The correct code =
<applet code=HelloWorld height=50 width=100>
</applet>
But I used HelloWorld.CLASS
No errors appear but you don't get any text neither.
Thanks to you all !!!
Actually, whether you use .class in the html or not makes no difference - and if the applet doesn't work you should still get an error printed in the console (and, if logging is enabled, in IE's javalog file).
If you say so.But that's all I changed, only the HTML file...Well thanks !!!!!
Actually, it does NOT matter if you use ".class" or not, BUT ***IMPORTANT** you cannot use ".CLASS". Java is case-sensitive, so .CLASS will be wrong, .class is ok.
If your program is an application then the text would appear. But as it is an applet use the [CODE]drawString[/CODE] method:drawString("Your text here", xAxis, yAxis);And that even doesn't work with me sometimes!