Results 1 to 17 of 17
  1. #1
    Join Date
    May 2012
    Posts
    7
    Rep Power
    0

    Exclamation Creating An Applet

    I wrote this program, and wanted to make it go into an applet or an executable file, but I don't know how. Please help!
    Java Code:
    import java.io.*;
    import java.util.*;
    public class Program1
    {
        public static void main(String args[])
        {
            while (true){
            Scanner kbReader = new Scanner(System.in);
            System.out.println("Hello Friends, I am here to put together a short story");
            System.out.println("about you and your life");
            System.out.println("   ");
            System.out.println("What is your name? (Hint: Just your first name)");
            String a = kbReader.next();
            System.out.println("  ");
            System.out.println("How old are you?");
            String b = kbReader.next();
            System.out.println("  ");
            System.out.println("Are you male or female?");
            String e = kbReader.next();
            System.out.println("  ");
            System.out.println("Do you have any pets? Y or N?");
            String c = kbReader.next();
            System.out.println("  ");
            String thisbetterwork = "thisbetterwork";
            String kool = "kool";
            String kooler = "kooler";
            if (c.equals("Y"))
            {
                System.out.println("How many?");
                String d = kbReader.next();
                String yesorno;
                yesorno = "does";
                thisbetterwork = "do";
                String tolol;
                String tololol;
                String tolololol;
                String tololololol;
                if (d.equals("1"))
                {
                    System.out.println("Just one? Ok, now we will move on.");
                    tolol = "1";
                }
                else if (d.equals("2"))
                {
                    System.out.println("Impressive, I know many cool people who have 2!");
                    tolol = "2";
                }
                else if (d.equals("3"))
                {
                    System.out.println("Wow! That is even more than I have! :D");
                    tolol = "3";
                }
                else if (d.equals("4"))
                {
                    System.out.println("You do realize that you are maxed out on pets in Denver, right?");
                    tolol = "4";
                }
                else if (d.equals("end"))
                {
                    System.exit(0);
                }
                else
                {
                    System.out.println("You do realize that if you are in Denver you are breaking the law, right?");
                    tolol = "more than 4";
                }
            }    
            else if(c.equals("N"))
            {
                System.out.println("Oh, well then, we will skip the pet part then. :(");
                String yesorno;
                String maybeso;
                yesorno = "doesn't";
                thisbetterwork = "don't";
            }
            else if (c.equals("end"))
                {
                    System.exit(0);
                }
            else
            {
                System.out.println("Sorry, try again");
            }
            if (e.equals("male"))
            {
                e = "he";
                String t;
                c = "his";
                t = "his";
                kool = "He";
            }
            else if (e.equals("female"))
            {
                e = "she";
                c = "her";
                kool = "She";
            }
            else if (e.equals("end"))
                {
                    System.exit(0);
                }
            else
            {
                System.out.println("Not recongnized, please try again");
            }
            System.out.println("  ");
            System.out.println("Do you like this class? Y or N");
            String dkd = kbReader.next();
            String tololol;
            if (dkd.equals("Y"))
            {
                System.out.println("So do I!");
                tololol = "like";
                kooler = "likes";
            }
            else if (dkd.equals("N"))
            {
                System.out.println("Why not? I think that it is lots of fun!");
                tololol = "do not like";
                kooler = "doesn't like";
            }
            else if (dkd.equals("end"))
                {
                    System.exit(0);
                }
            else
            {
                System.out.println("Please Try Again");
            }
            System.out.println("  ");
            String yesorno;
            System.out.println("Please wait as I compute and process a personalized story about you...");
            System.out.println("  ");
            System.out.println("Done. Printing your personalized story now to your screen.");
            System.out.println("   ");
            System.out.println("Hi! I know a person, "+c+" name is "+a+". "+e+" is "+b+" years old. "+c+" "+thisbetterwork+" have pets."+kool+" "+kooler+" this class.");
            System.out.println("   ");
           }
        }
    }
    Last edited by Norm; 05-11-2012 at 09:02 PM. Reason: added code tags

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Creating An Applet

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Creating An Applet

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

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

    Default Re: Creating An Applet

    You can not use the Scanner class to read user input in an applet.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Join Date
    May 2012
    Posts
    7
    Rep Power
    0

    Default Re: Creating An Applet

    What can you use than?

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

    Default Re: Creating An Applet

    Applets are part of the html page displayed by a browser. Add a GUI component to that display to receive user input.

    BTW your posted code is not an applet.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    Join Date
    May 2012
    Posts
    7
    Rep Power
    0

    Default Re: Creating An Applet

    I know it isn't! I want to make it into an applet!

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

    Default Re: Creating An Applet

    First you need to change the program's logic to use GUI instead of the console. When that is done, Make a class that extends JPanel and add the GUI and logic to that, Then you will be able to add that new class to a class that extends JApplet or one that extends JFrame for testing or using.
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    Join Date
    May 2012
    Posts
    7
    Rep Power
    0

    Default Re: Creating An Applet

    How do you do that? Can you give me an example?

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

    Default Re: Creating An Applet

    What part part you looking for?
    Converting the code is not trivial.

    You create your own class:
    Java Code:
    class YourClass extends JPanel {
      .... converted code here
    } // end class
    Java Code:
    public class GUIClass extends JFrame {
    
       YourClass urCls = new YourClass();   // create an instance of your class
       add(urCls);            //  add instance of class to current GUI container
    Last edited by Norm; 05-14-2012 at 06:06 PM.
    If you don't understand my response, don't ignore it, ask a question.

  11. #11
    Join Date
    May 2012
    Posts
    7
    Rep Power
    0

    Default Re: Creating An Applet

    I still don't understand how I would convert my code.

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

    Default Re: Creating An Applet

    Do you know how to write GUI code?
    If so, then you need to consider how the console program interacts with a user to get input from the user and convert that scheme for getting input to one that uses GUI components like text fields or comboboxes and buttons.
    If you don't understand my response, don't ignore it, ask a question.

  13. #13
    Join Date
    May 2012
    Posts
    7
    Rep Power
    0

    Default Re: Creating An Applet

    I do not know how to write GUI code. That is why I am asking how I would convert my code.

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

    Default Re: Creating An Applet

    Time to start doing some reading:
    Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)

    If you don't know how to write GUI, it will take you several weeks to learn enough to get started.
    If you don't understand my response, don't ignore it, ask a question.

  15. #15
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Creating An Applet

    Quote Originally Posted by Nickthegoatboy View Post
    I do not know how to write GUI code. That is why I am asking how I would convert my code.
    Also, you evidently don't bother to go through links posted to help you. Which is why Norm had to repeat the link I posted at #3.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  16. #16
    Join Date
    May 2012
    Posts
    7
    Rep Power
    0

    Default Re: Creating An Applet

    Yes, you posted the link, but with no explanation unlike Norm.

  17. #17
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Creating An Applet

    All the explanation you need is in the linked pages.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Problem with creating a jar to make a signed applet
    By Reskaillev in forum New To Java
    Replies: 0
    Last Post: 10-04-2011, 10:36 PM
  2. Help Creating a GUI applet window that compiles my program
    By ReclaimerGold in forum New To Java
    Replies: 3
    Last Post: 04-29-2011, 12:27 AM
  3. Creating Java applet
    By mneskovic in forum Java Applets
    Replies: 11
    Last Post: 05-11-2010, 12:51 AM
  4. Help with creating an applet
    By josephdcoleman in forum New To Java
    Replies: 2
    Last Post: 02-23-2009, 11:50 PM
  5. Creating Calendar in Applet
    By wco5002 in forum New To Java
    Replies: 2
    Last Post: 04-09-2008, 04:21 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
  •