Return to Main Code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Synapse
    New Member
    • Dec 2006
    • 26

    Return to Main Code

    Hello people...i need help in my code. I have a confirm dialog below and it will ask you to repeat the program again. now my problem is that if i choose yes, it will exit the application. here's my code below.


    import javax.swing.JOp tionPane;


    public class palin {

    public static void main (String args[]) {


    String num, right, error, numint;
    int number, num1, num2, num3, num4, num5;

    numint = JOptionPane.sho wInputDialog( "Enter 5 digits:" );

    number = Integer.parseIn t(numint);
    num = number + "";
    num1 = num.charAt(0);
    num2 = num.charAt(1);
    num3 = num.charAt(2);
    num4 = num.charAt(3);
    num5 = num.charAt(4);

    right = "It is a PALINDROME!";
    error = "It is NOT A PALINDROME!";

    if (num1==num5 && num2==num4)
    JOptionPane.sho wMessageDialog(
    null, right, "Access Granted",
    JOptionPane.INF ORMATION_MESSAG E);
    else
    JOptionPane.sho wMessageDialog(
    null, error, "Access Denied",
    JOptionPane.INF ORMATION_MESSAG E);

    int choice = JOptionPane.sho wConfirmDialog (null, "Do you want to try it again?");
    if (choice == JOptionPane.YES _OPTION)
    System.exit(-1);
    else if(choice == JOptionPane.NO_ OPTION)
    System.exit(0);

    }
    }

    hope you can help me guys. thank you!
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by Synapse
    Hello people...i need help in my code. I have a confirm dialog below and it will ask you to repeat the program again. now my problem is that if i choose yes, it will exit the application. here's my code below.


    import javax.swing.JOp tionPane;


    public class palin {

    public static void main (String args[]) {


    String num, right, error, numint;
    int number, num1, num2, num3, num4, num5;

    numint = JOptionPane.sho wInputDialog( "Enter 5 digits:" );

    number = Integer.parseIn t(numint);
    num = number + "";
    num1 = num.charAt(0);
    num2 = num.charAt(1);
    num3 = num.charAt(2);
    num4 = num.charAt(3);
    num5 = num.charAt(4);

    right = "It is a PALINDROME!";
    error = "It is NOT A PALINDROME!";

    if (num1==num5 && num2==num4)
    JOptionPane.sho wMessageDialog(
    null, right, "Access Granted",
    JOptionPane.INF ORMATION_MESSAG E);
    else
    JOptionPane.sho wMessageDialog(
    null, error, "Access Denied",
    JOptionPane.INF ORMATION_MESSAG E);

    int choice = JOptionPane.sho wConfirmDialog (null, "Do you want to try it again?");
    if (choice == JOptionPane.YES _OPTION)
    System.exit(-1);
    else if(choice == JOptionPane.NO_ OPTION)
    System.exit(0);

    }
    }

    hope you can help me guys. thank you!
    Use code tags when posting code
    What do you think these lines tell the program to do?

    [CODE=java] if (choice == JOptionPane.YES _OPTION)
    System.exit(-1);[/CODE]

    Comment

    • Synapse
      New Member
      • Dec 2006
      • 26

      #3
      I got that line from this forum too but it didn't work.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by Synapse
        I got that line from this forum too but it didn't work.
        Well the important thing is not getting some lines of code, it's about understanding the code, so you can write your own anytime. Follow the logic of your code and try to understand what the statements in your code mean.

        Comment

        Working...