Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 7th, 2009, 06:06 AM
adamsives adamsives is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2009
Posts: 3 adamsives User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 m 4 sec
Reputation Power: 0
Help with viewing Applet

I’m having trouble getting an applet to run. I’ve never programmed in Java before and am getting the instructions from a webpage Sams Teach Yourself Java 2 in 24 Hours

Steps I’m taking
1. I save the following code to a text file named “RootApplet.java”

import java.awt.*;

public class RootApplet extends javax.swing.JApplet {
int number;

public void init() {
number = 225;
}

public void paint(Graphics screen) {
Graphics2D screen2D = (Graphics2D) screen;
screen2D.drawString("The square root of " +
number +
" is " +
Math.sqrt(number), 5, 50);
}
}

2. open a command prompt and compile it with command javac RootApplet.java

3. open a new Word doc and paste the following code into it, save as an HTML

<applet code="RootApplet.class" height=100 width=300>
</applet>

4. open a command prompt and type “RootApplet.html” and the following displays.

<applet code="RootApplet.class" height=100 width=300>
</applet>

I was expecting to see was an HTML page with

"The square root of 225 is 15.0"

on it...



Can someone tell me what is wrong here?

Reply With Quote
  #2  
Old April 7th, 2009, 02:08 PM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
The problem is with step #4. You need to open your html file with a web browser, not by typing its name at the command prompt. Also, make sure your compiled RootApplet.class file is in the same directory as the RootApplet.html file.

Reply With Quote
  #3  
Old April 7th, 2009, 06:16 PM
adamsives adamsives is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2009
Posts: 3 adamsives User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 m 4 sec
Reputation Power: 0
thanks, I tried that but still to no avail!

thanks, I tried that but still to no avail!

1. open IE7, ensuringthat the RootApplet.class is in the same directoy as the RootApplet.html
2. File\Open, browse to RootApplet.html to open
3. get the
"
<applet code="RootApplet.class" height=100 width=300>

</applet>
"
Was expecting to see

"The square root of 225 is 15.0" as an applet in a webpage!

Reply With Quote
  #4  
Old April 8th, 2009, 05:05 PM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
Then your html file must be formatted incorrectly (i.e. it is not ASCII). Try creating it in Notepad instead of Word. After saving it, make sure the extension is ".hml" not ".html.txt".

Reply With Quote
  #5  
Old April 8th, 2009, 09:01 PM
adamsives adamsives is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2009
Posts: 3 adamsives User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 m 4 sec
Reputation Power: 0
Yes you were right. I wrote my HTML in Word and saved as an html, but when I looked at the source code for the newly created socument, it brought accross all the tags etc that you'd normally see on something like a webpage.

To resolve, I copied the text

"<applet code="RootApplet.class" height=100 width=300>

</applet>"

on to a Notepad document and saved as "RootApplet.html" and it worked first go.

Thanks for your help!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Help with viewing Applet


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap