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]
# 1
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.
jsalonen at 2007-6-29 9:09:27 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 2
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!
omegaxxx at 2007-6-29 9:09:27 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 3

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.

leukbr at 2007-6-29 9:09:27 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 4
Thanks you guys for helping me out!Greetings,Menno.
omegaxxx at 2007-6-29 9:09:27 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 5
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 !
omegaxxx at 2007-6-29 9:09:27 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 6
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...
ko5tik at 2007-6-29 9:09:27 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 7
Let me guess... you are extending javax.swing.JApplet instead of java.applet.Applet, aren't you?
jsalonen at 2007-6-29 9:09:27 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 8

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>

jsalonen at 2007-6-29 9:09:27 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 9

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

leukbr at 2007-6-29 9:09:27 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 10
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.
omegaxxx at 2007-6-29 9:09:27 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 11

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 !!!

omegaxxx at 2007-6-29 9:09:27 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 12
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).
jsalonen at 2007-6-29 9:09:27 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 13
If you say so.But that's all I changed, only the HTML file...Well thanks !!!!!
omegaxxx at 2007-6-29 9:09:27 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 14
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.
6tr6tr at 2007-6-29 9:09:27 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 15
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!
rufy_dude at 2007-7-1 1:39:44 > top of Java-index,Archived Forums,New To Java Technology Archive...