Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hai all
i m using fc6.i wrote 1 simple applet program.code is given below.drawString function is not displaying anything in the applet window. applet is initiated & started.i set background color in init function.its properly set.its entering into paint function.but not displaying the drawString.
import java.awt.Graphics;
import java.applet.*;
import java.awt.*;
public class applet1 extends Applet
{
public void init()
{
setBackground(Color.red);
}
public void paint(Graphics g)
{
System.out.println("inside paint function");
g.drawString("This is a simple java applet!", 100, 200);
}
}
this is my html code
(sample.html)
<html>
<body>
<APPLET CODE="applet1.class" WIDTH=500 HEIGHT=500>
</APPLET>
</body>
</html>
i compiled like this
>javac applet1.java
class file is created
I can't see anything wrong with your code. I've tested in Eclipse and it is working. What happens if you open the html file with a browser? It could also be that, for some odd reason, the String is being draw outside the applet. Try to set the position to 10, 10 instead 100, 200 and see if that helps. Try also setting different colours in the paint method before drawing the String (g.setColor(Color.white), for example).
If that still does not help, I don't know what the problem is. A little on style though: Try to name all classes you create in Java, with the first letter in uppercase (in this case, Applet1). It won't affect your code at all, but it is encouraged to do so in order to keep consistence with the rest of Java classes.
hai
firstof all thanks.
i tried urs.i set the color before drawString.i changed the position to 10,10.now also its not working.
actually i m using mozilla .first i tried to open that html file only.it said some plug in missing.then only i changed 2 appletviewer.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.