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

    Question Placing a game in a window

    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.");
        	
        	}
        	
        
    }}

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

Similar Threads

  1. Placing a game in a Jframe, gui or whatever
    By AndroidAppNewbie in forum AWT / Swing
    Replies: 3
    Last Post: 02-12-2011, 07:21 PM
  2. Pausing game when user minimizes window
    By tecno40 in forum Java Applets
    Replies: 1
    Last Post: 12-29-2010, 05:37 PM
  3. placing the components
    By rajeevhegde in forum AWT / Swing
    Replies: 1
    Last Post: 05-17-2010, 03:12 PM
  4. placing jar file
    By ras_pari in forum New To Java
    Replies: 1
    Last Post: 12-01-2009, 09:32 AM
  5. Placing Files In Folder
    By ramesh.8189 in forum New To Java
    Replies: 0
    Last Post: 02-06-2009, 12:36 PM

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
  •