• Post Reply Bookmark Topic Watch Topic
  • New Topic

Having problem with these program  RSS feed

 
Jorge Correa
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to create a program that enter some information including a zip code, but the user is not allowed to type ( 00000 ) . If the user does input those five digits a invalid input should be displayed.
This is what i have for that part:

private JTextField getzipCodeEntry() {
zipCodeEntry = new JTextField();
zipCodeEntry.setPreferredSize(new Dimension(200, 20));
zipCodeEntry.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
zipCodeAsEntered = zipCodeEntry.getText().trim();
// This deletes leading and trailing blanks in entry field, too
zipCodeEntry.setText(zipCodeAsEntered);
System.out.println(zipCodeAsEntered);
if (!zipCodeAsEntered.matches("\\d{5}"))
System.out.println("ZIP must be five digits");

if (zipCodeAsEntered.length() == 0)
System.out.println("Zip Code is required");


}

}); // end private JLabel getzipCodeLabel()
return zipCodeEntry;
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

Ok, so you know what the problem to solve is and you have some code. Now, what is your question?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so what exactly is your question?
 
Jorge Correa
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry if i did not myself clear. I want some help in how to display a invalid input message if the user enters 00000 in the zip code field.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . if("00000".equals(zipCodeAsEntered)) . . . ?
 
Paul Clapham
Sheriff
Posts: 22834
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or are you asking how to display a message?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!