Hello. I have a program that takes a letter of the alphabet and translates it to a number on a telephone key pad. Everything is correct and prints out great in the console, but I need to do a GUI version of it, and I'm having massive trouble trying to figure out what the code is for the char user input.
I've tried to put in things like
userLetter = Parse.charParse ( JOptionPane.showInputDialog("Please enter letter...");
but it's not working, and I have no other clue what it could be. The console version is below, I just need help with what I need to change the
"char userLetter =(QWERTY.next()).charAt(0);" to in order to get a GUI input box version. I know how to change the rest. Thanks in advance!
import java.util.Scanner; import javax.swing.JOptionPane; public class Letter { /** * @param args */ public static void main(String[] args) { Scanner QWERTY = new Scanner(System.in); System.out.println("Enter a letter of the alphabet to see what number it corresponds to."); char userLetter =(QWERTY.next()).charAt(0); char letter = 0; letter = (char) Character.toUpperCase(userLetter); int Digit = 0; if (letter == 'A' || letter == 'B' || letter == 'C') { Digit = 2; } else if (letter == 'D' || letter == 'E' || letter == 'F') { Digit = 3; } else if (letter == 'G' || letter == 'H' || letter == 'I') { Digit = 4; } else if (letter == 'J' || letter == 'K' || letter == 'L') { Digit = 5; } else if (letter == 'M' || letter == 'N' || letter == 'O') { Digit = 6; } else if (letter == 'P' || letter == 'Q' || letter == 'R' || letter == 'S') { Digit = 7; } else if (letter == 'T' || letter == 'U' || letter == 'V') { Digit = 8; } else if (letter == 'W' || letter == 'X' || letter == 'Y' || letter == 'Z') { Digit = 9; } if (Digit==1 || Digit==2 || Digit==3 || Digit==4 || Digit==5 || Digit==6 || + Digit==7 || Digit==8|| Digit==9) { System.out.println("The corresponding number is = " + Digit); } else { System.err.println("Error. Please try again."); } } }