Results 1 to 5 of 5
Thread: Java Applet please help!
- 08-06-2011, 06:43 PM #1
Member
- Join Date
- Aug 2011
- Posts
- 1
- Rep Power
- 0
Java Applet please help!
I am a new to Java and I am having problems with Applets.
I am also a Mac OsX Snow Leopard user
when I try to run this applet on Google Chrome, Firefox or any browser,
all it displays is the html that I wrote in the html document... Not the applet itself.
Also, I have checked this numerous times, and I believe that there aren't any errors in the java code.
__________________________________________________ _____
--------------------------------------------------------------------------------------------------------Java Code:import java.awt.*; public class BlankApplet extends javax.swing.JApplet { String parameter1; String parameter2; String parameter3; public void init() { parameter1= getParameter("adjective1") ; parameter2= getParameter("adjective2") ; parameter3= getParameter("adjective3") ; } public void paint(Graphics screen) { screen.drawString("The " + parameter1 + " " + parameter2 + " fox " + "jumped over the " + parameter3 + " dog.", 5, 50); } }
the html file
when I open the html file, it doesn't show 'the quick brown fox leapt over the lazy dog" but showsXML Code:<html> <body> <applet code="BlankApplet.class" height=80 width=500> <param name="adjective1" value="fast"> <param name="adjective2" value="brown"> <param name="adjective3" value="lazy"> </applet> </body> </html>
the html code
<html>
<body>
<applet.....
instead
in other words, it doesn't work.
PLEASE HELPLast edited by Fubarable; 08-06-2011 at 06:58 PM. Reason: code tags added
-
Your code as posted works for me suggesting that it's not a code problem but rather how you're using it. Is the Java class in a package or in the default package? Is your Java class file (not the .java file) located in the same directory as your html files? Does your HTML file have the ".html" extension? Are you opening it with an internet browser?
- 08-06-2011, 08:11 PM #3
Also look in the browser's java console for any error messages.
Some browsers look for the class.class file in the BlankApplet folder with this code=. Try removing the .classJava Code:code="BlankApplet[COLOR="red"].class[/COLOR]"
- 08-06-2011, 08:38 PM #4
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
It won't solve this problem, but you should never override the paint() method like that. Forgetting the super.paint() can cause problems.
You shold use a JLabel and add the label to the applet.
If you really need custom painting the extend JPanel or JComponent and override the paintComponent() method.
- 08-06-2011, 09:01 PM #5
It looks like you've saved the html as a text file. Does the filename have the correct extension (MacOS does identify file types by extension, doesn't it?)when I open the html file, it doesn't show 'the quick brown fox leapt over the lazy dog" but shows
the html code
<html>
<body>
<applet.....
instead
db
Similar Threads
-
need help converting java program into a java applet
By i'mhighdef in forum Java AppletsReplies: 3Last Post: 05-04-2011, 11:55 PM -
Java Applet to Applet communication
By jsman in forum Java AppletsReplies: 3Last Post: 04-05-2011, 02:23 PM -
applet class inside java.applet.* or java.awt.*
By Manish87 in forum Java AppletsReplies: 1Last Post: 09-27-2010, 02:15 PM -
What're the differences between JSP, Java Script, and Java Applet?
By meili100 in forum New To JavaReplies: 3Last Post: 07-23-2008, 08:07 AM -
Applet, To center text and To open I engage in a dialog in an Applet
By Marcus in forum Java AppletsReplies: 4Last Post: 06-08-2007, 06:15 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks