Results 1 to 4 of 4
  1. #1
    mark.7100 is offline Member
    Join Date
    Jul 2008
    Posts
    2
    Rep Power
    0

    Default Please check my java applet

    i don't understand why i am able to compile it but not to run it. Here's my code:
    import javax.swing.*;

    public class ASampleGUIProgram
    {
    public static void main(String[] args)
    {
    String appleString;
    appleString = JOptionPane.showInputDialog("Enter number of apples:");

    int appleCount;
    appleCount = Integer.parseInt(appleString);

    String orangeString;
    orangeString = JOptionPane.showInputDialog("Enter number of oranges:");
    int orangeCount;
    orangeCount = Integer.parseInt(orangeString);

    int totalFruitCount;
    totalFruitCount = appleCount + orangeCount;

    JOptionPane.showMessageDialog(null, "The total number of fruit = " + totalFruitCount);

    System.exit(0);
    }
    }

    and this is the html code:

    <html>
    <head>
    <title>ASampleGUIProgram</title>
    </head>

    <body>

    <center>
    <H1 >Applet Title</H1>
    <applet code="ASampleGUIProgram.class" width="200" height="200"> </applet>
    </center>
    </body>
    </html>

    please check it. thanks!!!

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,412
    Rep Power
    25

    Default

    Are there any error messages in the Java Console when you load the html into a browser? Copy and paste them here.

    You need to read up on writing Applets:
    Applets extend the Applet class
    The main() method is NOT used.
    System.exit(0); is NOT allowed in applets.

    What you've written should be executed by:
    java ASampleGUIProgram

  3. #3
    mark.7100 is offline Member
    Join Date
    Jul 2008
    Posts
    2
    Rep Power
    0

    Default hi

    thanks! it did work just by running it using:
    java ASampleGUIProgram

    i just copied it from a book. anyway, how can you change it so that it will run the way i want it to be? That is by using the appletviewer command

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,412
    Rep Power
    25

    Default

    If you want to convert the program to an Applet, you need to read about how to write an applet. Sun's tutorial would be one place to start. For code sample, use Google or search on this forum.

Similar Threads

  1. Java Applet Help
    By Nuluvius in forum New To Java
    Replies: 0
    Last Post: 03-01-2008, 03:04 PM
  2. New to JAVA Applet
    By kazitula in forum Java Applets
    Replies: 2
    Last Post: 10-31-2007, 08:11 PM
  3. how to check available resources in java program
    By lealea in forum New To Java
    Replies: 3
    Last Post: 08-13-2007, 08:35 PM
  4. Java 3d in applet
    By carl in forum Java Applets
    Replies: 1
    Last Post: 08-06-2007, 05:55 PM
  5. Replies: 4
    Last Post: 06-08-2007, 06:15 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
  •