Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2010
    Posts
    47
    Rep Power
    0

    Default 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.

  2. #2
    cc11rocks is offline Member
    Join Date
    Jan 2011
    Posts
    49
    Rep Power
    0

  3. #3
    Join Date
    Sep 2010
    Posts
    47
    Rep Power
    0

    Default

    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.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by AndroidAppNewbie View Post
    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

  1. Need help posting Image into JFrame in Shooter game
    By Noctis Lucis Caelum in forum Java Gaming
    Replies: 1
    Last Post: 01-24-2011, 11:18 PM
  2. placing the components
    By rajeevhegde in forum AWT / Swing
    Replies: 1
    Last Post: 05-17-2010, 03:12 PM
  3. placing jar file
    By ras_pari in forum New To Java
    Replies: 1
    Last Post: 12-01-2009, 09:32 AM
  4. Help placing images in JFrame
    By gammaman in forum New To Java
    Replies: 8
    Last Post: 07-24-2009, 02:19 AM
  5. Trying to create a map for a Zuul game using JFrame
    By alpdog14 in forum New To Java
    Replies: 1
    Last Post: 04-18-2009, 12:24 AM

Tags for this Thread

Posting Permissions

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