• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to handle cancel option in JOptionPane

 
Lisa Foster
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I click cancel on this below option it throws alot of errors how to handle this???
Thanks Lisa

//prompt for server and port number.
serverPort = (String)JOptionPane.showInputDialog(flightTable, "Enter the server and port number of the network database. \n I.E. Server:Port");
serverPort = serverPort.trim();
if (serverPort.equals("") | | serverPort.equals(null)) // user has not entered a server
JOptionPane.showMessageDialog(flightTable,"You have not enter a server and/or port.","Server Error", JOptionPane.ERROR_MESSAGE);
else{ //user entered a server
.
.
.
.
.
 
Dilip kumar
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
seats = JOptionPane.showInputDialog(frame, "Please enter number of tickets :");
// Do nothing if user clicks on Cancel button.
if ( seats == null ) return;
// Handle if user enters 0 or space and clicks OK
if(seats.equals("") | | seats.trim().length()==0 | | Integer.valueOf(seats).intValue()==0) {
JOptionPane.showMessageDialog(null, "Please enter valid number.", "Invaid Entry", JOptionPane.INFORMATION_MESSAGE );
return;
}
Hope this helps.
 
Lisa Foster
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks it works fine
Lisa
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic