Home > Showinputdialog Cancel > Joptionpane.showinputdialog Cancel Error

Joptionpane.showinputdialog Cancel Error

here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings

Showinputdialog Remove Cancel Button

and policies of this site About Us Learn more about Stack Overflow joptionpane cancel button listener the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation

Showinputdialog Cancel Return

Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; showinputdialog cancel example it only takes a minute: Sign up Clicking the cancel button showInputDialogue up vote 4 down vote favorite 1 I have a question in regards to pressing the cancel button of my inputDialoguebox. I have asked a similar question before so I apologize if I seem to repeat myself. The main problem I have is that my code executes regardless joptionpane exit on close of me pressing cancel and a socket connection does get made even if I don't add any input. Why does this happen and how can I avoid this? String input = ""; try { InetAddress host = InetAddress.getLocalHost(); String hostAddress = host.getHostAddress(); //setting label to host number so as to know what number to use labHostName.setText("(" + hostAddress + ")"); input = JOptionPane.showInputDialog(null,"Please enter host name to access server(dotted number only)...see number on frame", "name", JOptionPane.INFORMATION_MESSAGE); if(input != null && "".equals(input))//input != null && input.equals("")) { throw new EmptyFieldsException(); } else if(input != null && !input.equals(hostAddress)) { throw new HostAddressException(); } else { clientSocket = new Socket(input, 7777); So with the code being the way it is at the moment the clientsocket connection is made even if I do press cancel. Is the reason for this perhaps because I have the Server and Client as two seperate programs on the same machine? How can I avoid this from happening? java sockets joptionpane share|improve this question edited Sep 14 '12 at 20:59 Jacob Schoen 8,327105687 asked Mar 16 '1

here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the

Joptionpane.showinputdialog Close Button

workings and policies of this site About Us Learn more about Stack close joptionpane on cancel Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs

Joptionpane Null Pointer Exception

Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join http://stackoverflow.com/questions/9733702/clicking-the-cancel-button-showinputdialogue them; it only takes a minute: Sign up How to handle cancel button in JOptionPane up vote 6 down vote favorite 2 I had created a JOptionPane of type showInputDialog. When it opens it, it shows me two buttons: OK and Cancel. I would like to handle the action when I push on Cancel button, but I don't know http://stackoverflow.com/questions/11494222/how-to-handle-cancel-button-in-joptionpane how to reach it. How can I get it? java swing jbutton joptionpane share|improve this question edited Jul 15 '12 at 23:59 trashgod 170k14110411 asked Jul 15 '12 at 17:50 Mazzy 3,008154793 stackoverflow.com/a/10966330/829571 –assylias Jul 15 '12 at 17:55 add a comment| 4 Answers 4 active oldest votes up vote 17 down vote accepted For example: int n = JOptionPane.showConfirmDialog( frame, "Would you like green eggs and ham?", "An Inane Question", JOptionPane.YES_NO_OPTION); if (n == JOptionPane.YES_OPTION) { } else if (n == JOptionPane.NO_OPTION) { } else { } Alternatively with showOptionDialog: Object[] options = {"Yes, please", "No way!"}; int n = JOptionPane.showOptionDialog(frame, "Would you like green eggs and ham?", "A Silly Question", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (n == JOptionPane.YES_OPTION) { } else if (n == JOptionPane.NO_OPTION) { } else { } See How to Make Dialogs for more details. EDIT: showInputDialog String response = JOptionPane.showInputDialog(owner, "Input:", ""); if ((response != null) && (response.length() > 0)) { } share|improve this answer edited Jul 15 '12 at 18:05 answered Jul 15 '12 at 1

here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta http://stackoverflow.com/questions/16895775/joptionpane-cancel-button Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, showinputdialog cancel helping each other. Join them; it only takes a minute: Sign up JOptionPane cancel button up vote 0 down vote favorite Guys Im trying to use the JOptionPane but the cancel button is responding as if I entered a wrong input value and does not exit the programm. Any ideas whould be very useful! int n = 0, joptionpane.showinputdialog cancel error k = 0; Students stu = new Students(); while (n <= 0) { try { n = Integer.parseInt(JOptionPane.showInputDialog(stu, "Enter the number of people","Input", JOptionPane.INFORMATION_MESSAGE)); if (n <= 0) { OptionPane.showMessageDialog(stu, "You have given a wrong input!", "Warning", JOptionPane.WARNING_MESSAGE); } } catch (Exception e) { JOptionPane.showMessageDialog(stu, "You have given a wrong input!", "Warning", JOptionPane.WARNING_MESSAGE); n = 0; } } java swing joptionpane cancel-button share|improve this question edited Jun 3 '13 at 11:38 mKorbel 99.8k1384201 asked Jun 3 '13 at 11:33 user2441143 3116 consider posting full working code.... –pinkpanther Jun 3 '13 at 11:38 JOptionPane returns that as constant implemented in API –mKorbel Jun 3 '13 at 11:38 what's the condition for the program to exit? –A-SM Jun 3 '13 at 11:39 Im trying to tell the program when the user presses the cancel button to exit –user2441143 Jun 3 '13 at 11:46 Look at the answer below, by A-SM. The input dialog will return null if the user presses the cance

 
No related pages.