// DiffSquaresSwing.java: show the difference of two squares import javax.swing.JOptionPane; class DiffSquaresSwing { static int inputNumber(String message) { int result; String input; // Get a string from the user input = JOptionPane.showInputDialog(null, message); // Convert it to an integer result = Integer.parseInt(input); // Return the result return result; } static int diffSquares(int a, int b) { int sum; int diff; sum = a + b; diff = a - b; return sum * diff; } public static void main(String[] args) { int x; int y; x = inputNumber("First number:"); y = inputNumber("Second number:"); JOptionPane.showMessageDialog( null, "The difference of squares is: " + diffSquares(x,y), "Result of difference of squares", JOptionPane.PLAIN_MESSAGE); System.exit(0); } }