Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: please assist me to run this code in a java Graphical User Interface

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default please assist me to run this code in a java Graphical User Interface

    import java.util.Scanner;
    public class quiz {
    public static void main(String[] args) {
    final String TRUE= "True";
    final String FALSE= "False";
    int correctAns= 0;
    Scanner in= new Scanner(System.in);
    do{
    System.out.println("Q1: Which month has 28 days in it?");
    System.out.println("1:January");
    System.out.println("2:February");
    System.out.println("3:Every Month...");
    System.out.println("Enter the number you believe the answer"
    + "is assigned to.");
    int input= in.nextInt();
    if (input == 3)
    {
    System.out.println("Correct!");
    correctAns++;
    }
    else
    {
    System.out.println("Incorrect...");
    }
    break;
    }while(true);
    do {
    System.out.println("Q2: A farmer had 15 sheep, and all but"
    + " 8 died. How many sheep are left?");
    System.out.println("1:Seven");
    System.out.println("2:Eight");
    System.out.println("3:Three");
    System.out.println("Enter the number you believe the answer"
    + "is assigned to.");
    int input= in.nextInt();
    if (input == 2)
    {
    System.out.println("Correct!");
    correctAns++;
    }
    else
    {
    System.out.println("Incorrect...");
    }
    break;
    }while(true);
    do {
    System.out.println("Q3: In Britain, there is a 4th of July.");
    System.out.println("1:True");
    System.out.println("2:False");
    System.out.println("Enter the number you believe the answer"
    + "is assigned to.");
    int input= in.nextInt();
    if (input == 1)
    {
    System.out.println("Correct!");
    correctAns++;
    }
    else
    {
    System.out.println("Incorrect...");
    }
    break;
    }while(true);
    do {
    System.out.println("Q4: How many cheeks do you have?");
    System.out.println("1:Two");
    System.out.println("2:Three");
    System.out.println("3:Four");
    System.out.println("Enter the number you believe the answer"
    + "is assigned to.");
    int input= in.nextInt();
    if (input == 3)
    {
    System.out.println("Correct!");
    correctAns++;
    }
    else
    {
    System.out.println("Incorrect...");
    }
    break;
    }while(true);
    do {
    System.out.println("Q5: A 16 year old boy has had 16 birth days.");
    System.out.println("1:True");
    System.out.println("2:False");
    System.out.println("Enter the number you believe the answer"
    + "is assigned to.");
    int input= in.nextInt();
    if (input == 2)
    {
    System.out.println("Correct!");
    correctAns++;
    }
    else
    {
    System.out.println("Incorrect...");
    }
    break;
    }while(true);
    do {
    System.out.println("Q6: Panama hats are made in Panama.");
    System.out.println("1:True");
    System.out.println("2:False");
    System.out.println("Enter the number you believe the answer"
    + "is assigned to.");
    int input= in.nextInt();
    if (input == 2)
    {
    System.out.println("Correct!");
    correctAns++;
    }
    else
    {
    System.out.println("Incorrect...");
    }
    break;
    }while(true);
    }
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: please assist me to run this code in a java Graphical User Interface

    Please post your code in code tags.

    What's your question?

  3. #3
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: please assist me to run this code in a java Graphical User Interface

    Hello.
    Very simple. Your entire code should run in a JFrame or JApplet.
    And for input from keyboard use JOptionPane.

    Syed.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: please assist me to run this code in a java Graphical User Interface

    Take a look at the GUI tutorial: Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Hi all, i'm new to java programmin. can u guys assist me with my program?
    By jessica214 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 13th, 2013, 03:18 PM
  2. Java Abstract class and Interface issues in a code
    By John234 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 5th, 2013, 09:51 PM
  3. Replies: 1
    Last Post: November 2nd, 2012, 04:16 PM
  4. Please, help with OOP program with graphical interface
    By tavicz in forum Object Oriented Programming
    Replies: 1
    Last Post: April 29th, 2012, 02:56 PM
  5. User Interface Problems
    By pmg in forum What's Wrong With My Code?
    Replies: 6
    Last Post: April 4th, 2011, 07:32 AM