Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Having problem with these program

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
lowercase baba
Posts: 12955
65
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so what exactly is your question?
 
Jorge Correa
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 71719
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
. . . if("00000".equals(zipCodeAsEntered)) . . . ?
 
Marshal
Posts: 26293
80
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or are you asking how to display a message?
reply
    Bookmark Topic Watch Topic
  • New Topic