Okay so my instructor just told us we needed to use a GUI via JOptionPane with our program. So that we may turn out programs in as executable jar files. However, I have never used it and im kind of new at this stuff so I need some help. Here is my problem and code:
package waitingroomlinkedlist; import java.util.Scanner; import javax.swing.JOptionPane; public class WaitingRoomLinkedList { public static void main(String args[]) { boolean done = false; String inputFirst; String inputLast; String[] choices = {"First Name", "Last Name", "Quit"}; while (!done) { int choice = JOptionPane.showOptionDialog( null, "Personal Information:", "Register", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, choices, choices[0]); switch (choice){ case 0: inputFirst = JOptionPane.showInputDialog( "Enter First Name"); break; case 1: inputLast = JOptionPane.showInputDialog("Enter Last Name"); break; case 2: done = true; JOptionPane.showMessageDialog( null, "...quitting!", "", JOptionPane.ERROR_MESSAGE); break; } } Person p1 = new Person(inputFirst, inputLast); } }
Now for some reason I am getting an error when trying to create a new instance of the Person class and pass inputFirst and inputLast. Its telling me that I have not initialized inputFirst or Last. When I allow it to initialize it sets inputFirst = null; and so forth with inputLast. Any idea what's going on here? All I want to do is pass the two Strings to my constructor in my Person class.