Results 1 to 17 of 17
Thread: Creating An Applet
- 05-11-2012, 06:26 PM #1
Member
- Join Date
- May 2012
- Posts
- 7
- Rep Power
- 0
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
- 05-11-2012, 07:26 PM #2
Re: Creating An Applet
Why do they call it rush hour when nothing moves? - Robin Williams
- 05-11-2012, 07:27 PM #3
Re: Creating An Applet
Why do they call it rush hour when nothing moves? - Robin Williams
- 05-11-2012, 07:47 PM #4
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.
- 05-11-2012, 08:46 PM #5
Member
- Join Date
- May 2012
- Posts
- 7
- Rep Power
- 0
Re: Creating An Applet
What can you use than?
- 05-11-2012, 08:52 PM #6
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.
- 05-11-2012, 09:23 PM #7
Member
- Join Date
- May 2012
- Posts
- 7
- Rep Power
- 0
Re: Creating An Applet
I know it isn't! I want to make it into an applet!
- 05-11-2012, 09:28 PM #8
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.
- 05-14-2012, 05:59 PM #9
Member
- Join Date
- May 2012
- Posts
- 7
- Rep Power
- 0
Re: Creating An Applet
How do you do that? Can you give me an example?
- 05-14-2012, 06:04 PM #10
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 classJava 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 containerLast edited by Norm; 05-14-2012 at 06:06 PM.
If you don't understand my response, don't ignore it, ask a question.
- 05-14-2012, 06:12 PM #11
Member
- Join Date
- May 2012
- Posts
- 7
- Rep Power
- 0
Re: Creating An Applet
I still don't understand how I would convert my code.
- 05-14-2012, 06:16 PM #12
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.
- 05-14-2012, 06:17 PM #13
Member
- Join Date
- May 2012
- Posts
- 7
- Rep Power
- 0
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.
- 05-14-2012, 06:23 PM #14
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.
- 05-14-2012, 07:32 PM #15
- 05-15-2012, 05:33 PM #16
Member
- Join Date
- May 2012
- Posts
- 7
- Rep Power
- 0
Re: Creating An Applet
Yes, you posted the link, but with no explanation unlike Norm.
- 05-15-2012, 06:08 PM #17
Similar Threads
-
Problem with creating a jar to make a signed applet
By Reskaillev in forum New To JavaReplies: 0Last Post: 10-04-2011, 10:36 PM -
Help Creating a GUI applet window that compiles my program
By ReclaimerGold in forum New To JavaReplies: 3Last Post: 04-29-2011, 12:27 AM -
Creating Java applet
By mneskovic in forum Java AppletsReplies: 11Last Post: 05-11-2010, 12:51 AM -
Help with creating an applet
By josephdcoleman in forum New To JavaReplies: 2Last Post: 02-23-2009, 11:50 PM -
Creating Calendar in Applet
By wco5002 in forum New To JavaReplies: 2Last Post: 04-09-2008, 04:21 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks