Results 1 to 2 of 2
- 03-09-2011, 10:53 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 7
- Rep Power
- 0
Converting Scanner input to JOptionPane
I would much rather print this out through JOptionPane than to have it displayed on the console. Where do I start with it?
Java Code:import javax.swing.JOptionPane; import java.util.Scanner; public class DriverExam { public static void main(String[] args) { // accept keyboard input Scanner keyboard = new Scanner(System.in); System.out.println("Enter your answers below.\n"); char[] answers = new char[20]; // request an answer for each question for(int i = 0; i < answers.length; i++) { // get input until input is valid char input; do { System.out.print(i + 1 + ". "); // get character and make it upper case input = Character.toUpperCase(keyboard.next().charAt(0)); } while(input < 'A' || input >'D'); // store answer answers[i] = input; } // print output here DriverExamClass driver = new DriverExamClass(answers) {}; System.out.println(); System.out.println("You "+(driver.passed()?"passed" : "did not pass") + ".\n"); System.out.println("Correct: " + driver.totalCorrect() + "\n"); System.out.println("Incorrect: " + driver.totalIncorrect() + "\n"); System.out.println("Questions missed: " + driver.questionsMissed()); } }
- 03-09-2011, 11:26 PM #2
Senior Member
- Join Date
- Jan 2011
- Location
- Belgrade, Serbia
- Posts
- 227
- Rep Power
- 3
Very simple, take a look...
How to Make Dialogs (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
Similar Threads
-
End Scanner int input with text value
By BillyB in forum New To JavaReplies: 3Last Post: 03-07-2011, 05:13 PM -
how to reverse some input from scanner
By moncur in forum New To JavaReplies: 24Last Post: 11-09-2010, 02:59 PM -
Input JOptionPane
By nic21 in forum AWT / SwingReplies: 1Last Post: 11-18-2009, 05:32 PM -
Scanner input problem
By slayer_azure in forum New To JavaReplies: 3Last Post: 05-26-2008, 10:49 PM -
JOptionPane - input dialog
By Java Tip in forum Java TipReplies: 0Last Post: 12-17-2007, 09:09 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks