Results 1 to 4 of 4
- 02-12-2011, 05:59 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 47
- Rep Power
- 0
Placing a game in a Jframe, gui or whatever
I've made a little simple guessing game, and i wonder how i can place it inside a Jframe, instead of running it as text based in the console(Using eclipse)
I'll post the code aswell:
Edit: Don't mind my name, this is java programming :>
PHP Code:import static java.lang.System.out; import static java.lang.System.in; import java.util.Scanner; import java.util.Random; public class GuessAgain { public static void main (String[] args) { Scanner myScanner = new Scanner(System.in); int numGuesses = 0; int randomNumber = new Random().nextInt(30) +1 ; { out.println(" ***************** "); out.println("Welcome to the Guessing Game"); out.println(" ***************** "); out.println(); out.print("Enter a number from 1 to 30: "); int inputNumber = myScanner.nextInt(); numGuesses++; if (inputNumber > randomNumber){ out.println("The number is smaller then " + inputNumber);} if (inputNumber < randomNumber){ out.println("The number is bigger then " + inputNumber); } while (inputNumber != randomNumber){ out.println(); out.print("Enter a number from 1 to 30: "); inputNumber = myScanner.nextInt(); numGuesses++; if (inputNumber > randomNumber){ out.println("The number is smaller then " + inputNumber);} if (inputNumber < randomNumber){ out.println("The number is bigger then " + inputNumber); } } if (inputNumber == randomNumber);{ out.println("You managed to find the correct number!"); } out.print("You answered with the number "); out.println(randomNumber + " ,which is correct!"); out.print("You have completed the game after "); out.println(numGuesses + " guesses."); } }}Last edited by AndroidAppNewbie; 02-12-2011 at 06:02 PM.
- 02-12-2011, 06:09 PM #2
Member
- Join Date
- Jan 2011
- Posts
- 49
- Rep Power
- 0
- 02-12-2011, 06:23 PM #3
Member
- Join Date
- Sep 2010
- Posts
- 47
- Rep Power
- 0
I know how to make a frame, but i don't know how to place my game in it, and make the game work in it.
-
You can't get that code "into" a JFrame since it's nothing more than a most basic console program inside of a main method. I suggest that you re-write the so that it's a true OOPs-compliant class and then use that with Swing coding techniques form the tutorials to create your GUI.
Similar Threads
-
Need help posting Image into JFrame in Shooter game
By Noctis Lucis Caelum in forum Java GamingReplies: 1Last Post: 01-24-2011, 11:18 PM -
placing the components
By rajeevhegde in forum AWT / SwingReplies: 1Last Post: 05-17-2010, 03:12 PM -
placing jar file
By ras_pari in forum New To JavaReplies: 1Last Post: 12-01-2009, 09:32 AM -
Help placing images in JFrame
By gammaman in forum New To JavaReplies: 8Last Post: 07-24-2009, 02:19 AM -
Trying to create a map for a Zuul game using JFrame
By alpdog14 in forum New To JavaReplies: 1Last Post: 04-18-2009, 12:24 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks