Linux - Newbie This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
10-24-2007, 04:01 AM
|
#1
|
Member
Registered: Oct 2007
Posts: 66
Rep:
|
paint function in java not working
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
to run i used like this
i used
>appletviewer sample.html
i dont know the problem.
thanks in advance.
|
|
|
10-24-2007, 05:52 AM
|
#2
|
LQ Guru
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,337
Rep:
|
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.
Good luck!
|
|
|
10-24-2007, 06:45 AM
|
#3
|
Member
Registered: Oct 2004
Location: UK
Distribution: Ubuntu/Kubuntu
Posts: 249
Rep:
|
I can't see a problem either, I did exactly as you described, used javac and appletviewer and it works for me.
What Java version are you using?
|
|
|
10-24-2007, 03:31 PM
|
#4
|
Moderator
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696
|
The original poster replied:
Quote:
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.
|
|
|
|
10-26-2007, 06:36 AM
|
#5
|
Member
Registered: Oct 2004
Location: UK
Distribution: Ubuntu/Kubuntu
Posts: 249
Rep:
|
Can you post the output of running java -version in a console/command prompt please?
Do any of the other Graphics class methods work, i.e. drawLine, drawRect, etc??
|
|
|
All times are GMT -5. The time now is 08:29 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|