Results 1 to 8 of 8
Thread: Help with this Java test GUI?
- 03-14-2011, 11:17 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 4
- Rep Power
- 0
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:
This works fine, but I need to make GUI so I can make it usable. Help?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."); } } }Last edited by Shmian; 03-14-2011 at 11:20 PM.
- 03-14-2011, 11:31 PM #2
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.
- 03-14-2011, 11:59 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 4
- Rep Power
- 0
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.
- 03-15-2011, 12:23 AM #4
Member
- Join Date
- Mar 2011
- Posts
- 22
- Rep Power
- 0
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
- 03-15-2011, 01:15 AM #5
Member
- Join Date
- Mar 2011
- Posts
- 4
- Rep Power
- 0
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
- 03-15-2011, 01:19 AM #6
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
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.
- 03-15-2011, 02:00 AM #7
Member
- Join Date
- Mar 2011
- Posts
- 4
- Rep Power
- 0
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.
That's the part I need to edit. I can't do showInputDialog because then there will be a text bar underneath the text.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."); } } }
- 03-15-2011, 02:12 AM #8
Similar Threads
-
Java verb test
By Ep3demic in forum New To JavaReplies: 0Last Post: 03-10-2010, 01:01 PM -
Java Aptitude Test
By j3sr in forum New To JavaReplies: 3Last Post: 01-25-2010, 08:39 AM -
Java Aptitude Test
By j3sr in forum Advanced JavaReplies: 1Last Post: 01-23-2010, 03:22 PM -
java online test
By satyadas in forum Java CertificationReplies: 0Last Post: 06-06-2008, 08:23 AM -
Test Advisory Panel-Telecommute- Test your Java skills + share insights on Java tests
By michelle in forum Jobs OfferedReplies: 0Last Post: 04-05-2008, 12:38 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks