Results 1 to 4 of 4
  1. #1
    Iam_Sam is offline Member
    Join Date
    Nov 2013
    Location
    USA
    Posts
    4
    Rep Power
    0

    Default Need help converting a program to an applet

    Hey guys...as you can see i'm new to this forum, i started learning Java few months ago and i found it really interesting...i created this program called paint with a swing.JoptionPane, and i was wondering if i can convert this program into an applet???

    below is the code that i did so far:

    Java Code:
    package paint;
    
    [B]import javax.swing.JOptionPane;[/B] (I wanna convert this(program) to an applet)
    
    public class Paint {
    
     
    	private static int AREA_UNIT = 115;           // Cost calculated per 115 squared feet
    	private static int GALLONS_PER_UNIT = 1;   // 1 gallon of paint used per 115
    
    	private static int LABOR_UNIT = 8; // 8 hours to paint per 115 squared feet
    	private static int PER_HOUR_COST = 18; // Labor cot per hour
    
    	public static void main(String[] args) {
    		
    		// Get the user input of room count
    		int roomCount = getInteger("Enter number of rooms: ");
    
    		// Get the user's input on gallons of paint needed
    		double paintPricePerGallons = getDouble("Enter price of paint per gallon: ");
    
    		double totalRoomSize = 0;
    		for (int i = 0; i < roomCount; i++) {
    			// Get the user input of square feet for each room
    			totalRoomSize = totalRoomSize
    					+ getDouble("Enter size of room " + (i + 1)
    							+ " (in squared feet): ");
    		}
    
    		// The number of gallons of paint required
    		double totalPaintUnitUsed = getGallonsOfPaintNeeded(totalRoomSize);
    
    		// The hours of labor required
    		double totalLaborUnitUsed = getHoursOfLaborRequired(totalRoomSize);
    
    		//  The cost of the paint
    		double totalPaintCost = getCostOfPaint(totalPaintUnitUsed, paintPricePerGallons);
    
    		// The labor charges
    		double totalLaborCost = getLaborCharges(totalLaborUnitUsed);
    
    		// The total cost of the paint job
    		double totalJobCost = getTotalCost(totalPaintCost, totalLaborCost);
    
    		// -Results-
    		String message = String.format("The number of gallons of paint required = %.2f\n"
    				+ "The hours of labor required = %.2f\n"
    				+ "The cost of the paint = %.2f\n"
    				+ "The labor charges = %.2f\n"
    				+ "The total cost of the paint job = %.2f",totalPaintUnitUsed,totalLaborUnitUsed,totalPaintCost,totalLaborCost,totalJobCost);
    		JOptionPane.showMessageDialog(null, message);
    	}
    
    	private static double getGallonsOfPaintNeeded(double totalRoomSize) 
    
    		// Calculate how many of 115 sq. feet blocks is there
    		double roomCountUnit = totalRoomSize / AREA_UNIT;
    
    		// The number of gallons of paint required
    		double totalPaintUnitUsed = GALLONS_PER_UNIT * roomCountUnit;
    		return totalPaintUnitUsed;
    	}
    
    	private static double getHoursOfLaborRequired(double totalRoomSize) {
    		// Calculate how many of 115 sq. feet blocks is there
    		double roomCountUnit = totalRoomSize / AREA_UNIT;
    
    		// The number of hours of labor required
    		double totalLaborUnitUsed = LABOR_UNIT * roomCountUnit;
    		return totalLaborUnitUsed;
    	}
    
    	private static double getCostOfPaint(double totalPaintUnitUsed,double paintPricePerGallons) {
    		return totalPaintUnitUsed * paintPricePerGallons;
    	}
    	private static double getLaborCharges(double totalLaborUnitUsed) {
    		return totalLaborUnitUsed * PER_HOUR_COST;
    	}
    	private static double getTotalCost(double totalPaintCost,double totalLaborCost) {
    		return totalPaintCost + totalLaborCost;
    	}
    	private static double getDouble(String prompt) {
    		String userInput = JOptionPane.showInputDialog(prompt);
    		return Double.parseDouble(userInput);
    	}
    
    	private static int getInteger(String prompt) {
    		String userInput = JOptionPane.showInputDialog(prompt);
    		return Integer.parseInt(userInput);
    	}
    }
    Can someone please help me ?? or at least show me how to start
    Thank you guys...i appreciate your help

    PS: I'm a beginner at Java and i like to learn from other people
    Last edited by Norm; 11-30-2013 at 01:09 PM. Reason: quote tag changed to code

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,309
    Blog Entries
    7
    Rep Power
    20

    Default Re: Need help converting a program to an applet

    Of course you have already read the API documentation for the Applet and JApplet classes, so you already know the structure of the control flow for an applet; so, what's your trouble?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Iam_Sam is offline Member
    Join Date
    Nov 2013
    Location
    USA
    Posts
    4
    Rep Power
    0

    Default Re: Need help converting a program to an applet

    My problem is how to start...that's my problem! I need help like someone who can show me how to start, give me a push not write for me the whole program.
    And yes, i'm not comfortable yet with creating applet; i just started learning java

    Thank you for your answer Jos

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,309
    Blog Entries
    7
    Rep Power
    20

    Default Re: Need help converting a program to an applet

    Well, by now you should know that an Applet or a JApplet needs an init() method as well as start() and stop() methods; read the API docs for those classes for a description when and why those methods are called. Also, an Applet (or JApplet) doesn't have (nor needs) a main( ... ) method; you have to restructure your program accordingly.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. converting java(APPLET) into exe
    By hemanth0226 in forum Java Gaming
    Replies: 7
    Last Post: 07-03-2012, 06:47 PM
  2. need help converting java program into a java applet
    By i'mhighdef in forum Java Applets
    Replies: 3
    Last Post: 05-04-2011, 11:55 PM
  3. Need Help Converting This to Applet Plz
    By RecursiveEndUserFromMars in forum Java Applets
    Replies: 2
    Last Post: 01-19-2011, 04:10 AM
  4. Converting an App to Applet
    By josephdcoleman in forum New To Java
    Replies: 1
    Last Post: 02-21-2009, 07:07 AM
  5. Converting netbeans app to applet
    By paulious in forum New To Java
    Replies: 3
    Last Post: 10-23-2008, 11:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •