/* Author : Michael Robinson Program : gui_1_dialogBoxes.java Purpose : To present GUI dialog boxes - Message Dialog Boxes - Input Dialog Boxes Notes : JOptionPane ALWAYS returns the input as STRING regardless of what was inputed Updated : July 5th, 2099 */ import javax.swing.JOptionPane; public class gui_1_dialogBoxes { //accepts input from user and returns it to caller public static String doInputBox( String question ) { return( JOptionPane.showInputDialog( question ) ); } //display message to users public static void doMessageBox( String message ) { JOptionPane.showMessageDialog( null, message ); } //accepts multiple variables of Object type, sort them //in descending order and return them as String data types public static String swap( Object ... numbers ) { String array[] = new String[ 100 ]; int counter = 0; String temp = ""; //processing all the Objects passed received //using the enhanced for loop for( Object x : numbers ) { array[ counter ] = x.toString(); counter++; } //swap/sort array into descending order if( array[ 0 ].compareTo(array[ 1 ]) > 0 ) { temp = array[ 0 ]; array[ 0 ] = array[ 1 ]; array[ 1 ] = temp; } if( array[ 1 ].compareTo(array[ 2 ]) > 0 ) { temp = array[ 1 ]; array[ 1 ] = array[ 2 ]; array[ 2 ] = temp; } if( array[ 0 ].compareTo(array[ 1 ]) > 0 ) { temp = array[ 0 ]; array[ 0 ] = array[ 1 ]; array[ 1 ] = temp; } //JOptionPane ALWAYS returns the input as STRING regardless //of what was inputed return ( "Sorted : " + array[ 0 ] + " " + array[ 1 ] + " " + array[ 2 ] ); }//end public static String swap( int ... numbers ) public static void main( String arg[] ) { doMessageBox( "Welcome, this is a Message Dialog Box..." ); //assign the input from the method doInputBox //to the String fName String fName = doInputBox( "Enter your First Name" ); //assign the input from the method doInputBox //to the String mName String mName = doInputBox( "Enter your Middle Name" ); //assign the input from the method doInputBox //to the String lName String lName = doInputBox( "Enter your Last Name" ); //call doMessageBox passing fName, mName and lName doMessageBox( "Nice to meet you\n" + fName + " " + mName + " " + lName + "\nNow let's do some Sorting" ); //assign the input from the method doInputBox //to the String fNum String fNum = ( doInputBox( "Enter First Object" ) ); //assign the input from the method doInputBox //to the String sNum String sNum = ( doInputBox( "Enter Second Object" ) ); //assign the input from the method doInputBox //to the String tNum String tNum = ( doInputBox( "Enter Third Object" ) ); //call doMessageBox passing fName, fNum sNum tNum and //the result of calling swap method after also passing //the same fName, fNum sNum tNum and variables doMessageBox( "Objects Swap " + fName + "\n" + "Before : " + fNum + " " + sNum + " " + tNum + "\n" + swap( fNum, sNum, tNum ) ); System.exit(0); //must use when using JOptionPane b/c it //causes an additional task to run in the VM }//end public static void main( String arg[] ) }//end public static void main( String arg[] )