Results 1 to 8 of 8
  1. #1
    Shmian is offline Member
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Default Help with this Java test GUI?

    I am making a test for a geocache where if the user gets all the answers correct it outputs coordinates. I am trying to figure out how to make a little window where the question is displayed and there is a place to write your answer, nothing fancy. Here is the test:


    Java Code:
    import java.awt.*;
    import javax.swing.*;
    import java.util.Scanner;
    
    public class test extends JFrame{
    public static void main(String[] args){
    Scanner ian = new Scanner(System.in);
    
    String aone;
    String atwo;
    String athree;
    String afour;
    String afive;
    String asix;
    String aseven;
    int bacon;
    int cheese;
    int lettuce;
    int blargh;
    int mayo;
    int george;
    int idk;
    int answer;
    System.out.println("The Computer Test");
    System.out.println("Type the answer in the space provided.");
    System.out.println("Question 1- What does RAM stand for?");
    aone = ian.nextLine();
    if (aone.equalsIgnoreCase("random access memory"))
    bacon = 1;
    else
    bacon = 0;
    System.out.println("Question 2- What type of keyboard layout is used in Albania?");
    atwo = ian.nextLine();
    if(atwo.equalsIgnoreCase("Qwertz"))
    cheese = 1;
    else
    cheese = 0;
    System.out.println("Question 3- What was the first company to make a mouse?");
    athree = ian.nextLine();
    if(athree.equalsIgnoreCase("apple"))
    lettuce = 1;
    else
    lettuce = 0;
    System.out.println("Question 4- How do you write \"I want the cache coordinates!\"in binary?");
    afour = ian.nextLine();
    if(afour.equalsIgnoreCase("010010010
    blargh = 1;
    else 
    blargh = 0;
    System.out.println("Question 5- What is the name of what is known to be the first search engine?");
    afive = ian.nextLine();
    if(afive.equalsIgnoreCase("Archie"))
    mayo = 1;
    else
    mayo = 0;	
    System.out.println("Question 6- Which company invented Java?");
    asix = ian.nextLine();
    if(asix.equalsIgnoreCase("Sun Microsystems"))
    george = 1;
    else
    george = 0;	
    System.out.println("Question 8-(Hardest question--- What type of file does the extension \".EWL\" usually refer to?");
    aseven = ian.nextLine();
    if(aseven.equalsIgnoreCase("MS Encarta Document"))
    idk = 1;
    else
    idk = 0;	
    
    answer = bacon + cheese + lettuce + blargh + mayo + george + idk;
    
    if(answer < 7){
    System.out.println("I'm sorry, you did not get all the questions correct.");
    }
    if(answer == 7){
    System.out.println("Here are the coordinates.");
    }
    
    }
    }
    This works fine, but I need to make GUI so I can make it usable. Help?
    Last edited by Shmian; 03-14-2011 at 11:20 PM.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    Help with what? Your post is like if you walked up to a NASA engineer and said "I want to build a space shuttle, can you help?"

    Have you made a GUI before? If not google for a tutorial, follow it a build a basic GUI. Then see if you can adapt what you have learnt to making your own GUI. When you have tried doing that and have a specific question come back post your code and ask that specific question.

  3. #3
    Shmian is offline Member
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Default

    I have tried before, but every tutorial I find I either can't understand the terminology, or have trouble applying the tutorial to my specific example. I know how to make a basic frame, but I don't understand how to make it functional for this quiz. Can somebody please help me get started, or tell me where to start? Can I get a link to a useful tutorial that will help me? Thanks.

  4. #4
    aadem is offline Member
    Join Date
    Mar 2011
    Posts
    22
    Rep Power
    0

    Default Well

    I think your looking for a JOptionPane

    Do this. before you define your class (public class whatever {

    type this
    import javax.swing.*;


    Than, instead of getting input through scanner (which you should use an inputstreamreader for anyway in my opinion ONLY OPINION) type this REPLACE YOUR ian.nextLine() with

    String input1 = JOptionPane.showInputDialog("What is your name?");

    String input2 = JOptionPane.showInputDialog("What is your age?");

    replace those questions about name and age with whatever you want to ask

  5. #5
    Shmian is offline Member
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Default

    Thanks. This is what I need, I'll try it right now. I'll post again if I have any questions, but thanks again.:D

  6. #6
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    If you are looking to make a more full GUI and not just changing what you use for the input a card layout would probably work well. Google java card layout and you should get some good tutorials and examples.

  7. #7
    Shmian is offline Member
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Default

    I am finished with the questions part of the test, but I am confused about how to display the coordinates or the message saying that they got questions wrong.

    Java Code:
    if(answer < 7){
    			System.out.println("I'm sorry, you did not get all the questions correct.");
    		}
    		if(answer == 7){
    			System.out.println("Here are the coords.");
    			
    		}
    			      
    			   }
    			
    	}
    That's the part I need to edit. I can't do showInputDialog because then there will be a text bar underneath the text.

  8. #8
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    Did it not occur to you to look at the Java API to see what other methods the JOptionPane class has?

Similar Threads

  1. Java verb test
    By Ep3demic in forum New To Java
    Replies: 0
    Last Post: 03-10-2010, 01:01 PM
  2. Java Aptitude Test
    By j3sr in forum New To Java
    Replies: 3
    Last Post: 01-25-2010, 08:39 AM
  3. Java Aptitude Test
    By j3sr in forum Advanced Java
    Replies: 1
    Last Post: 01-23-2010, 03:22 PM
  4. java online test
    By satyadas in forum Java Certification
    Replies: 0
    Last Post: 06-06-2008, 08:23 AM
  5. Replies: 0
    Last Post: 04-05-2008, 12:38 AM

Posting Permissions

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