Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help changing an Application to an Applet

 
Ashley Perry
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to java and programming. (And new to this forum... hi!) I don't have any programming experience at all. I am taking a course in java, but I am only in chapter three. So I don't know very much yet. Instead of making my dad a card for father's day I wrote a little java program. I can execute it in command prompt or eclipse. He loved it, but he wanted to be able to access it in an internet browser. We learned the difference between a java application and a java applet. I know that java applet must be embedded in html code. That's all the detail the book gives on the topic so far.

Can someone give me an example or explain how to edit the code so that it will be displayed in an internet browser? I tried for several hours to do this on my own. I wouldn't ask for help, but I honestly tried everything I could.

Here's the poorly written program (I am just a beginner ) in case you need to see it:

import java.util.Scanner;

public class James
{

public static void main (String[] args)
{ String name;
int age;
int value;

Scanner scan = new Scanner (System.in);

System.out.print ("What is your name? ");

name = scan.nextLine();

System.out.print ("How old are you? ");
value = scan.nextInt();

System.out.print ("How old is your oldest child? ");

age = scan.nextInt();

System.out.println();
System.out.println();

System.out.println ("Happy Father's Day " + name);

System.out.println ("You have been a father for " + age + " years.");

System.out.println();

System.out.println ("Gee you're old!");

System.out.println();

System.out.println (" You're " + value + " and celebrating your " + age
+ "th Father's Day ");
System.out.println();
System.out.println();

System.out.println ("P.S. Everyone knows Ashley's your favorite.");


}
}
 
Steffen Schmitt
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I don't think you will get the Application to work the way you tried, as with Applets there is no command line or Shell to read from.

In your case it would be much easier to write a new Applet using TextFields for information input, "send" Buttons to confirm information, and a couple of Labels to display textual output.

With a modern IDE and RAD tool (personally, I prefer NetBeans but you can do the same using Eclipse) you can do this in minutes.

Hope this helps!


Cheers -

Steffen
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic