Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-04-2007, 09:46 AM
Member
 
Join Date: Jun 2007
Posts: 92
Daniel is on a distinguished road
Create a Applet in the page HTML
It was about time to start with this things but i don't even know how to create any applet that will run on my site even saying "hello" in JOptionPane box when you press button... Can you refer me to sites or give some starting tips on how to create my first JApplet and to embeed it in my site?

P.S.: I tried something but it doesnt load : Untitled Document

Thanks

Daniel
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-04-2007, 09:50 AM
Senior Member
 
Join Date: Jun 2007
Posts: 114
Albert is on a distinguished road
Have you had a look at Sun Tutorials on Applets. Very good starting point if you have just starting programming in Java.

Here is an example of a very very basic applet, that will demonstrate the various methods and when try are called once you have opened the page.

Please save in a file MyApplet.java

Code:
import java.awt.*; import java.awt.event.*; import javax.swing.*; // simple applet public class MyApplet extends JApplet { private String name; /* * Constructor for MyApplet extends JApplet */ public MyApplet(){ } //-- ends class constructor public void init() { this.name = new String(); this.name = JOptionPane.showInputDialog( null, "What is your name? " ); System.out.println("+++++++++++++ Applet INITIALIZED +++++++++++++"); System.out.println("You said that your name was: " + this.name ); } //-- ends instance method init // runs when you pages opens or when you refresh page public void start() { System.out.println("*************** Applet is START ***************"); } //-- ends instnce method start // runs every time your referesh page...or when you try and // and resizes browser public void paint( Graphics g ) { System.out.println("--------------- Applet is PAINTING ---------------"); g.drawString( "You said your name was: " + this.name, 10, 10 ); } //-- ends instance method paint // runs when user minimizes browser or when navigates away from page public void stop() { System.out.println(" _________ Applet STOPPED _______"); } //-- ends instance method stop // runs when applet is destroyed...or when user navigates to another page public void destroy() { System.out.println("%%%%%%%%%%%% Applet DESTORYED %%%%%%%%%%%%"); } //-- ends instance method destroy } //-- ends class definition
Once you have done that, then please create HTML page...and dump the following contents inside it. I have called it MyApplet.html
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"/> <title>My Applet</title> </head> <body> <h1>My Applet</h1> <applet code="MyApplet.class" CODEBASE="" width=500 height=500> <p>Sorry, but you need a java enabled browser in order to view the applet.</p> </applet> </body> </html>
Instead of viewing the applet in a web browser, please view it using the appletviewer command...so that you can see how all the methods are run...etc

Of course, you should compile the applet first.
Code:
javac *.java
and then run the appletviewer by executing the following command
Code:
appletviewer MyApplet.html
You should see from the command console..the sequence of all the methods and how they are executed. play around with the appletviewer...by minimizing, maximinzing, etc...just to see how all the methods are fired...and in what sequence...etc

Greetings
Albert
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-04-2007, 09:52 AM
Member
 
Join Date: Jun 2007
Posts: 92
Daniel is on a distinguished road
Thanks much! It works and i got (at least i think so) the point...

But... What about implementing chat in java and putting it as applet on my site so i'll have java chat?

I have one chat in java but i don't know if possible to embeed it on my site as applet?

Thanks!

Daniel
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Applet - Displaying an HTML page with a selected resolution Java Tip Java Tips 0 03-10-2008 04:36 PM
How to view applet from html page. jwzumwalt Java Applets 2 11-24-2007 06:21 AM
Fetching HTML content of a Web Page JavaForums Java Blogs 0 11-05-2007 10:00 PM
HTML page bbq New To Java 1 07-05-2007 05:46 AM
html web page parsing/scraping orchid Advanced Java 1 05-02-2007 05:35 AM


All times are GMT +3. The time now is 08:12 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org