Need help with If the user hits Cancel on either first or last name, show the error
i know its a if and loop but not sure what so far i have this
//CIS 226 Assignment 2
//The GUI - Assign2
// - 02/02/2011
import javax.swing.JOptionPane;
public class Assign2 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String name = JOptionPane.showInputDialog("Please enter your first name:");
String lastname = JOptionPane.showInputDialog("Please enter your last name");
JOptionPane.showMessageDialog(null, "Hello, " + name +(" ") +lastname+ ", \n Welcome to CIS 226." );
//For extra credit
JOptionPane.showMessageDialog(null, "Sorry, you have to enter your name to enroll into CIS 226.", "Error ", JOptionPane.ERROR_MESSAGE);
}
}
Re: Need help with If the user hits Cancel on either first or last name, show the err
Quote:
public static void main(String[] args) {
// TODO Auto-generated method stub
String name = JOptionPane.showInputDialog("Please enter your first name:");
String lastname = JOptionPane.showInputDialog("Please enter your last name");
JOptionPane.showMessageDialog(null, "Hello, " + name +(" ") +lastname+ ", \n Welcome to CIS 226." );
//For extra credit
JOptionPane.showMessageDialog(null, "Sorry, you have to enter your name to enroll into CIS 226.", "Error ", JOptionPane.ERROR_MESSAGE);
}
when user will click on cancel button null is assigned into the variable.name or lastname
if(name.equals(null) || lastname.equals(null))
JOptionPane.showMessageDialog(null, "Sorry, you have to enter your name to enroll into CIS 226.", "Error ", JOptionPane.ERROR_MESSAGE);
public static void main(String[] args) {
// TODO Auto-generated method stub
String name = JOptionPane.showInputDialog("Please enter your first name:");
String lastname = JOptionPane.showInputDialog("Please enter your last name");
if(name.equals(null) || lastname.equals(null))
JOptionPane.showMessageDialog(null, "Sorry, you have to enter your name to enroll into CIS 226.", "Error ", JOptionPane.ERROR_MESSAGE);
else
JOptionPane.showMessageDialog(null, "Hello, " + name +(" ") +lastname+ ", \n Welcome to CIS 226." );
//For extra credit
}
Re: Need help with If the user hits Cancel on either first or last name, show the err
thanks i saw the name = null in my book but i think i was missing the null in my script. but thanks again
Re: Need help with If the user hits Cancel on either first or last name, show the err
i have it like this but when i hit cancel on both name and last name i still get the null message " hello welcome, null null, to cis226. whats wrong?
//CIS 226 Assignment 2
//The GUI - Assign2
// - 02/02/2011
import javax.swing.JOptionPane;
public class Assign2 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String name = JOptionPane.showInputDialog("Please enter your first name:");
String lastname = JOptionPane.showInputDialog("Please enter your last name");
JOptionPane.showMessageDialog(null, "Hello, " + name +(" ") +lastname+ ", \n Welcome to CIS 226." );
//For extra credit
if(name.equals(null) || lastname.equals(null))
JOptionPane.showMessageDialog(null, "Sorry, you have to enter your name to enroll into CIS 226.", "Error ", JOptionPane.ERROR_MESSAGE);
else
JOptionPane.showMessageDialog(null, "Sorry, you have to enter your name to enroll into CIS 226.", "Error ", JOptionPane.ERROR_MESSAGE);
}
}
Re: Need help with If the user hits Cancel on either first or last name, show the err
Quote:
//For extra credit
if(name.equals(null) || lastname.equals(null))
JOptionPane.showMessageDialog(null, "Sorry, you have to enter your name to enroll into CIS 226.", "Error ", JOptionPane.ERROR_MESSAGE);
else
JOptionPane.showMessageDialog(null, "Sorry, you have to enter your name to enroll into CIS 226.", "Error ", JOptionPane.ERROR_MESSAGE);
}
you haven't seen the code i had given earlier carefully, welcome message should be in else part.
Quote:
if(name.equals(null) || lastname.equals(null))
JOptionPane.showMessageDialog(null, "Sorry, you have to enter your name to enroll into CIS 226.", "Error ", JOptionPane.ERROR_MESSAGE);
else
JOptionPane.showMessageDialog(null, "Hello, " + name +(" ") +lastname+ ", \n Welcome to CIS 226." );
And please mark this thread solved , if your problem is solved