Link to home
Start Free TrialLog in
Avatar of ishcmc
ishcmc

asked on

Make java program created run on the web

My basic program:

/*
 * File: OrderSlip.java
 * Description: This class prints an order slip based on stock
 *  ordered from a warehouse
 */
import java.util.*;

public class OrderSlip
{
    public static void main(String[] args) // Main method
    {
            int ITEMCODE, STOCK;
            double PRICE;
            char OUTLET;
            
            Scanner sc = new Scanner(System.in);
                        
            System.out.println("Enter item code: ");
            ITEMCODE = sc.nextInt();
            System.out.println("Enter item price: ");
            PRICE = sc.nextDouble();
            System.out.println("Enter quantity in stock: ");
            STOCK = sc.nextInt();
            System.out.println("Enter outlet placing order (A,B,C...): ");
            OUTLET = sc.next().charAt(0);
            
            System.out.println("      *** ORDER SLIP ***");
            System.out.println("");
            System.out.println("item code           "+ITEMCODE);
            System.out.println("item price          "+PRICE);
            System.out.println("quantity in stock   "+STOCK);
            System.out.println("");
            System.out.println("");
            System.out.println("TOTAL COST          "+PRICE*STOCK);
            System.out.println("");
            System.out.println("");
            System.out.println("send to base        "+OUTLET);
            
    } //end main
} //end class OrderSlip


I'd like to make this program into an applet, then embed it into an html page and run it via IE.
Please provide step by step, I know NetBeans can do this, but it's too complicated. That's why I need your help.
Avatar of Peter Kwan
Peter Kwan
Flag of Hong Kong image

For a tutorial on applet, please go to the following site:

http://java.sun.com/docs/books/tutorial/deployment/applet/getStarted.html
ASKER CERTIFIED SOLUTION
Avatar of ADSLMark
ADSLMark

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ADSLMark
ADSLMark

Oh, you can remove the line:

import java.util.*;

Not necessary any more (not that it matters, but just a small thing i saw when i scrolled up :-)..)

Mark
Avatar of ishcmc

ASKER

Wow, this is just a simple program but I already have to change alot of stuff inside.
Is there a program that automatically create a simple user interface, add listeners, implement the actionPerformed method for a .java?
Oh by the way, after changing all those stuff, I save it as .class right?
I don't know if there are tools to do this for you, but i just created this layout by hand..

You can probably also simulate the console in an applet, but if you have the ability to use user controls, why not use them? It is a lot easier for people to enter data etc.

You can also solve this by asking the user questions with JOptionPane in the Swing package. Then the user simply gets 4 input messageboxes in sequence and the answer is output as a messagebox. I think the layout solution is way nicer.

You can add the whole code in the file "OrderSlip.java" then from the command line its: "javac OrderSlip.java" (without quotes) for compilation, of course this is on a java developer machine, so you probably have to do a little bit different, anyway.. the compiler will create a .class file. In the same directory create a HTML page with some content and the <applet> tag. Open de HTML page in a browser and voila.

Mark
You can also use a visual java editor, like visual J++, to create a layout. It gives pretty nasty/dirty code so I do not recommend it AT ALL, but if you aren't very good in Java and certainly not in java layout stuff, then that might be a solution.

Most of the time, creating a layout in Java is just a lot of copy-paste work, so if you have the basic ideas then you should be able to make your own layout fairly easy.

Mark